-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit
More file actions
executable file
·1470 lines (1329 loc) · 34.7 KB
/
Copy pathinit
File metadata and controls
executable file
·1470 lines (1329 loc) · 34.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# shellcheck source=initrd.defaults
. /etc/initrd.defaults
# shellcheck source=initrd.scripts
. /etc/initrd.scripts
# shellcheck source=/dev/null
[ -e /etc/initrd.splash ] && . /etc/initrd.splash
# Basic /dev content, we need it as fast as possible.
[ ! -e /dev/console ] && mknod /dev/console c 5 1
[ ! -e /dev/null ] && mknod /dev/null c 1 3
[ ! -e /dev/random ] && mknod /dev/random c 1 8
[ ! -e /dev/tty ] && mknod /dev/tty c 5 0
[ ! -e /dev/tty0 ] && mknod /dev/tty0 c 4 0
[ ! -e /dev/tty1 ] && mknod /dev/tty1 c 4 1
[ ! -e /dev/ttyS0 ] && mknod /dev/ttyS0 c 4 64
[ ! -e /dev/ttyS1 ] && mknod /dev/ttyS1 c 4 65
[ ! -e /dev/urandom ] && mknod /dev/urandom c 1 9
[ ! -e /dev/zero ] && mknod /dev/zero c 1 5
# Take control
CONSOLE="/dev/$(get_active_console)"
exec 0<>${CONSOLE} 1<>${CONSOLE} 2<>${CONSOLE}
if [ "$$" != '1' ]
then
echo '/linuxrc has to be run as the init process as the one'
echo 'with a PID of 1. Try adding init="/linuxrc" to the'
echo 'kernel command line or running "exec /linuxrc".'
exit 1
fi
mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1
mount -o remount,rw / >/dev/null 2>&1
mount -t tmpfs -o rw,nosuid,nodev,relatime,mode=755 none /run 2>&1
if [ ! -d /run/initramfs ]
then
mkdir -p /run/initramfs
chmod 0750 /run/initramfs
fi
if [ ! -s /etc/ld.so.cache ]
then
# Looks like we were unable to run ldconfig during initramfs generation
hash ldconfig >/dev/null 2>&1 && run ldconfig
fi
# Set up symlinks
run busybox --install -s
# Handle kernel command-line parameters
CMDLINE=$(cat /proc/cmdline 2>/dev/null)
for x in ${CMDLINE}
do
case "${x}" in
real_root=*)
REAL_ROOT=${x#*=}
;;
root=*)
FAKE_ROOT=${x#*=}
;;
subdir=*)
SUBDIR=${x#*=}
;;
real_init=*)
REAL_INIT=${x#*=}
;;
init=*)
FAKE_INIT=${x#*=}
;;
# Livecd options
cdroot)
CDROOT=1
;;
cdroot=*)
CDROOT=1
CDROOT_DEV=${x#*=}
;;
cdroot_type=*)
CDROOT_TYPE=${x#*=}
;;
cdroot_marker=*)
CDROOT_MARKER=${x#*=}
;;
# Start livecd loop, looptype options
loop=*)
LOOP=${x#*=}
;;
looptype=*)
LOOPTYPE=${x#*=}
;;
isoboot=*)
ISOBOOT=${x#*=}
;;
# Start Volume manager options
dolvm)
USE_LVM_NORMAL=1
;;
domdadm)
USE_MDADM=1
;;
dodmraid)
USE_DMRAID_NORMAL=1
;;
dodmraid=*)
DMRAID_OPTS=${x#*=}
USE_DMRAID_NORMAL=1
;;
domultipath)
USE_MULTIPATH_NORMAL=1
;;
dozfs*)
USE_ZFS=1
case "${x#*=}" in
*force*)
ZPOOL_FORCE=-f
;;
esac
case "${x#*=}" in
*cache*)
if [ -s "/etc/zfs/zpool.cache" ]
then
ZPOOL_CACHE="-c /etc/zfs/zpool.cache"
else
bad_msg "zpool.cache not found or empty, zpool import will be slow"
fi
;;
esac
;;
quiet|quiet_genkernel)
QUIET=1
;;
# Debug Options
debug)
run touch "${GK_DEBUGMODE_STATEFILE}"
;;
# Scan delay options
scandelay=*)
SDELAY=${x#*=}
;;
scandelay)
SDELAY=3
;;
rootdelay=*|rootwait=*)
ROOTDELAY=${x#*=}
;;
rootdelay|rootwait)
ROOTDELAY=5
;;
firstmods=*)
FIRSTMODS=$(echo ${FIRSTMODS} ${x#*=} | sed -e 's/^\ *//;s/,/ /g')
;;
# Module no-loads
doload=*)
MDOLIST=$(echo ${MDOLIST} ${x#*=} | sed -e 's/^\ *//;s/,/ /g')
;;
noload=*)
MLIST=$(echo ${MLIST} ${x#*=} | sed -e 's/^\ *//;s/,/ /g')
export MLIST
;;
splash)
if [ -x /usr/bin/plymouth -a -x /usr/sbin/plymouthd ]
then
PLYMOUTH=1
fi
;;
splash=*)
if [ -e /etc/initrd.splash ]
then
FBSPLASH=1
fi
;;
# /dev/md
lvmraid=*)
warn_msg "'${x}' kernel command-line argument is deprecated; Use 'dolvm' instead!"
USE_LVM_NORMAL=1
;;
part=*)
MDPART=${x#*=}
;;
part|partitionable)
MDPART=1
;;
# For network options see start_network() in initrd.scripts
# NFS
nfsroot=*)
NFSROOT=${x#*=}
;;
# iSCSI
iscsi_initiatorname=*)
ISCSI_INITIATORNAME=${x#*=}
;;
iscsi_target=*)
ISCSI_TARGET=${x#*=}
;;
iscsi_tgpt=*)
ISCSI_TGPT=${x#*=}
;;
iscsi_address=*)
ISCSI_ADDRESS=${x#*=}
;;
iscsi_port=*)
ISCSI_PORT=${x#*=}
;;
iscsi_username=*)
ISCSI_USERNAME=${x#*=}
;;
iscsi_password=*)
ISCSI_PASSWORD=${x#*=}
;;
iscsi_username_in=*)
ISCSI_USERNAME_IN=${x#*=}
;;
iscsi_password_in=*)
ISCSI_PASSWORD_IN=${x#*=}
;;
iscsi_debug=*)
ISCSI_DEBUG=${x#*=}
;;
iscsi_noibft)
ISCSI_NOIBFT=1
;;
# Crypto
crypt_root=*)
CRYPT_ROOT=${x#*=}
USE_CRYPTSETUP=1
;;
crypt_root_options=*)
CRYPT_ROOT_OPTIONS=$(echo ${CRYPT_ROOT_OPTIONS} ${x#*=} | sed -e 's/,/ /g')
;;
crypt_swap=*)
CRYPT_SWAP=${x#*=}
USE_CRYPTSETUP=1
;;
crypt_swap_options=*)
CRYPT_SWAP_OPTIONS=$(echo ${CRYPT_SWAP_OPTIONS} ${x#*=} | sed -e 's/,/ /g')
;;
root_header=*)
CRYPT_ROOT_HEADER=${x#*=}
;;
root_headerdev=*)
CRYPT_ROOT_HEADERDEV=${x#*=}
;;
root_headerdev_fstype=*)
CRYPT_ROOT_HEADERDEV_FSTYPE=${x#*=}
;;
root_key=*)
CRYPT_ROOT_KEY=${x#*=}
;;
root_keydev=*)
CRYPT_ROOT_KEYDEV=${x#*=}
;;
root_keydev_fstype=*)
CRYPT_ROOT_KEYDEV_FSTYPE=${x#*=}
;;
root_trim=*)
tmp_enabled=${x#*=}
if is_true "${tmp_enabled}"
then
CRYPT_ROOT_OPTIONS="${CRYPT_ROOT_OPTIONS} --allow-discards"
fi
unset tmp_enabled
;;
swap_header=*)
CRYPT_SWAP_HEADER=${x#*=}
;;
swap_headerdev=*)
CRYPT_SWAP_HEADERDEV=${x#*=}
;;
swap_headerdev_fstype=*)
CRYPT_SWAP_HEADERDEV_FSTYPE=${x#*=}
;;
swap_key=*)
CRYPT_SWAP_KEY=${x#*=}
;;
swap_keydev=*)
CRYPT_SWAP_KEYDEV=${x#*=}
;;
swap_keydev_fstype=*)
CRYPT_SWAP_KEYDEV_FSTYPE=${x#*=}
;;
keyctl_keydesc=*)
KEYCTL_KEYDESC=${x#*=}
;;
keyctl_keytimeout=*)
KEYCTL_KEYTIMEOUT=${x#*=}
;;
keyctl_keykeep)
KEYCTL_KEYKEEP=1
;;
real_resume=*|resume=*)
REAL_RESUME=${x#*=}
;;
noresume)
NORESUME=1
;;
crypt_silent)
CRYPT_SILENT=1
;;
dosshd)
USE_SSH=1
;;
gk.bootfont.disabled=*)
tmp_disabled=${x#*=}
if is_true "${tmp_disabled}"
then
GK_BOOTFONT_DISABLED=1
fi
unset tmp_disabled
;;
gk.emergency=*)
tmp_action=${x#*=}
case "${tmp_action}" in
reboot)
GK_EMERGENCY_ACTION="reboot -f"
;;
poweroff)
GK_EMERGENCY_ACTION="poweroff -f"
;;
halt)
GK_EMERGENCY_ACTION="halt -f"
;;
*)
warn_msg "'${x}' is an unsupported emergency action -- ignored!"
;;
esac
unset tmp_action
;;
gk.hw.load-all=*)
tmp_disabled=${x#*=}
if is_true "${tmp_disabled}"
then
GK_HW_LOAD_ALL_MODULES=1
fi
unset tmp_disabled
;;
gk.hw.use-modules_load=*)
tmp_disabled=${x#*=}
if is_true "${tmp_disabled}"
then
GK_HW_USE_MODULES_LOAD=1
fi
unset tmp_disabled
;;
gk.log.disabled=*)
tmp_disabled=${x#*=}
if is_true "${tmp_disabled}"
then
[ -f "${GK_INIT_LOG}" ] && rm "${GK_INIT_LOG}"
GK_INIT_LOG=
touch "${GK_INIT_LOG_DISABLED}"
fi
unset tmp_disabled
;;
gk.sshd.port=*)
tmp_port=${x#*=}
if is_int "${tmp_port}"
then
GK_SSHD_PORT=${tmp_port}
else
warn_msg "'${x}' does not look like a valid port -- ignored!"
fi
unset tmp_port
;;
gk.sshd.wait=*)
tmp_wait=${x#*=}
if is_int "${tmp_wait}"
then
GK_SSHD_WAIT=${tmp_wait}
else
warn_msg "'${x}' does not look like a valid time (second) value -- ignored!"
fi
unset tmp_wait
;;
gk.udev.debug=*)
tmp_enabled=${x#*=}
if is_true "${tmp_enabled}"
then
GK_UDEV_DEBUG=1
fi
unset tmp_enabled
;;
gk.udev.timeout=*)
tmp_timeout=${x#*=}
if is_int "${tmp_timeout}"
then
GK_UDEV_TIMEOUT=${tmp_timeout}
else
warn_msg "'${x}' does not look like a valid time (second) value -- ignored!"
fi
unset tmp_timeout
;;
gk.userinteraction.disabled=*)
tmp_disabled=${x#*=}
if is_true "${tmp_disabled}"
then
touch "${GK_USERINTERACTION_DISABLED_STATEFILE}"
fi
unset tmp_disabled
;;
gk.preserverun.disabled=*)
tmp_disabled=${x#*=}
if is_true "${tmp_disabled}"
then
warn_msg "gk.preserverun.disabled is set; /run will not be moved to newroot!"
GK_PRESERVE_RUN=0
fi
unset tmp_disabled
;;
gk.prompt.timeout=*)
tmp_timeout=${x#*=}
if is_int "${tmp_timeout}"
then
GK_PROMPT_TIMEOUT=${tmp_timeout}
else
warn_msg "'${x}' does not look like a valid time (second) value -- ignored!"
fi
unset tmp_timeout
;;
real_rootflags=*)
REAL_ROOTFLAGS=${x#*=}
;;
rootflags=*)
FAKE_ROOTFLAGS=${x#*=}
;;
rootfstype=*)
ROOTFSTYPE=${x#*=}
;;
keymap=*)
keymap=${x#*=}
;;
locale=*)
locale=${x#*=}
;;
aufs)
aufs=1
;;
aufs\=*)
aufs=1
if echo "${x#*=}" | grep , &>/dev/null
then
aufs_dev_uid=${x#*,}
aufs_dev=${x%,*}
else
aufs_dev=${x#*=}
fi
;;
# Allow user to specify the modules location
aufs.modules\=*)
aufs_modules_dir=${x#*=}
aufs_modules=1
;;
overlayfs)
overlayfs=1
;;
overlayfs\=*)
overlayfs=1
if echo "${x#*=}" | grep , &>/dev/null
then
overlayfs_dev_uid=${x#*,}
overlayfs_dev=${x%,*}
else
overlayfs_dev=${x#*=}
fi
;;
# Allow user to specify the modules location
overlayfs.modules\=*)
overlayfs_modules_dir=${x#*=}
overlayfs_modules=1
;;
unionfs)
if [ ! -x /sbin/unionfs ]
then
USE_UNIONFS_NORMAL=0
bad_msg 'unionfs binary not found: aborting use of unionfs!'
else
USE_UNIONFS_NORMAL=1
fi
;;
nounionfs)
USE_UNIONFS_NORMAL=0
;;
verify)
VERIFY=1
;;
esac
done
if ! is_quiet
then
# Prevent superfluous printks from being printed to the console
echo ${GK_CONSOLE_LOGLEVEL} > /proc/sys/kernel/printk
fi
good_msg "${GK_META_VERSION} (${GK_META_BUILD_DATE}). Linux kernel ${KV}"
if [ "${GK_BOOTFONT_DISABLED}" = '0' -a -e /lib/console/font ]
then
if echo "$(get_active_console)" | grep -qF ttyS
then
warn_msg "Active console is ${console}; Not loading embedded boot font ..."
elif hash setfont >/dev/null 2>&1
then
run setfont /lib/console/font -C ${CONSOLE} 2>&1
fi
fi
if [ "${CDROOT}" = '0' ]
then
if [ -z "${REAL_ROOT}" -a "${FAKE_ROOT}" != "/dev/ram0" ]
then
REAL_ROOT="${FAKE_ROOT}"
fi
if [ -z "${REAL_INIT}" -a "${FAKE_INIT}" != "/linuxrc" ]
then
REAL_INIT="${FAKE_INIT}"
fi
if [ -z "${REAL_ROOTFLAGS}" ]
then
REAL_ROOTFLAGS="${FAKE_ROOTFLAGS}"
fi
fi
# Set variables based on the value of REAL_ROOT
case "${REAL_ROOT}" in
ZFS=*)
ZFS_POOL=${REAL_ROOT#*=}
ZFS_POOL=${ZFS_POOL%%/*}
USE_ZFS=1
;;
ZFS)
USE_ZFS=1
;;
esac
# Verify that it is safe to use ZFS
if [ "${USE_ZFS}" = '1' ]
then
for i in zfs zpool
do
if ! hash ${i} >/dev/null 2>&1
then
USE_ZFS=0
bad_msg "Aborting use of ZFS because '${i}' not found!"
break
fi
done
unset i
[ "${USE_ZFS}" = '1' ] && MY_HWOPTS="${MY_HWOPTS} zfs"
fi
if [ "${ROOTFSTYPE}" = "f2fs" ]
then
# Hack for f2fs, which uses crc32 but does not depend on it (in many kernels at least):
FIRSTMODS="${FIRSTMODS} crc32_generic"
fi
if [ "${ROOTFSTYPE}" = "btrfs" -o -x /sbin/btrfs ]
then
# We have no mechanism to trigger btrfs module loading before UDEV's btrfs builtin
# will run; In addition, loading btrfs via UDEV could cause problems for slow
# machines, see https://github.com/dracutdevs/dracut/issues/658
FIRSTMODS="${FIRSTMODS} btrfs"
fi
cmdline_hwopts
# Mount devfs
mount_devfs
# Mount sysfs
mount_sysfs
if [ -e /proc/sys/kernel/hotplug ]
then
log_msg "COMMAND: 'echo "" > /proc/sys/kernel/hotplug'"
echo "" > /proc/sys/kernel/hotplug
fi
# Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
if [ -z "${DO_modules}" ]
then
good_msg 'Skipping module load; disabled via command-line'
elif [ -d "/lib/modules/${KV}" ]
then
if [ -n "${FIRSTMODS}" ]
then
good_msg 'Loading first modules ...'
# try these modules first -- detected modules for root device:
modules_load firstmods ${FIRSTMODS}
fi
# Load appropriate kernel modules
if [ "${GK_HW_USE_MODULES_LOAD}" = '1' ]
then
good_msg 'Loading modules ...'
for modules in ${MY_HWOPTS}
do
modules_scan ${modules}
done
fi
if [ -n "${MDOLIST}" ]
then
good_msg 'Loading modules from command-line ...'
modules_load extra_load ${MDOLIST}
fi
else
good_msg 'Skipping module load; no modules in the ramdisk!'
fi
# Run debug shell if requested
run_debug_shell "before starting udevd"
# Initialize udev
if [ ! -f "/etc/udev/hwdb.bin" ]
then
good_msg 'Generating /etc/udev/hwdb.bin ...'
run udevadm hwdb --update \
|| bad_msg 'Failed to generate /etc/udev/hwdb.bin!'
fi
good_msg 'Activating udev ...'
udevd_cmd="run udevd --resolve-names=never"
if [ "${GK_UDEV_DEBUG}" = '1' ]
then
udevd_cmd="${udevd_cmd} --debug > ${GK_UDEV_LOG} 2>&1 &"
else
udevd_cmd="${udevd_cmd} --daemon"
fi
eval "${udevd_cmd}"
if [ $? -eq 0 ]
then
run udevadm trigger --action=add
udevsettle
else
bad_msg "udevd failed to run"
fi
cd /
# start splash; plymouth must start after udev
splash 'init'
# Start iSCSI
if hash iscsistart >/dev/null 2>&1
then
start_iscsi
fi
# Loop file already exists on fs, assume no mount needed,
# This allows for squashfs in initrd, which can be used for (i)PXE booting
if [ -e "${LOOP}" ]
then
got_good_root=1
got_loop_wo_mount=1
CDROOT_PATH=$(dirname "${LOOP}")
fi
# Apply scan delay if specified
sdelay
# Scan volumes
start_volumes
setup_keymap
if [ "${USE_SSH}" = '1' ]
then
start_network
start_sshd
fi
keyctl_keyadd
# Initialize LUKS root device except for livecd's
if [ "${CDROOT}" != '1' ]
then
if ( [ -n "${CRYPT_SWAP_KEY}" ] && [ -z "${CRYPT_SWAP_KEYDEV}" ] ) || \
( [ -n "${CRYPT_SWAP_HEADER}" ] && [ -z "${CRYPT_SWAP_HEADERDEV}" ] ) || \
( [ "${REAL_ROOT}" = "${REAL_RESUME}" ] || [ "${USE_LVM_NORMAL}" = '1' ] )
then
# the swap key or header might be on the root fs so start it first in this case
start_LUKS_root
luks_root_started=1
start_LUKS_swap
else
# we don't need to start the root at all if we are resuming from suspend
start_LUKS_swap
fi
if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
then
case "${REAL_RESUME}" in
LABEL=*|UUID=*|PARTLABEL=*|PARTUUID=*)
RESUME_DEV=""
retval=1
good_msg "Determining resume device (trying ${REAL_RESUME}) ..."
if [ ${retval} -ne 0 ]
then
RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -ne 0 ]
then
RESUME_DEV=$(blkid -o device -l -t "${REAL_RESUME}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]
then
good_msg "Resume device detected as ${RESUME_DEV}!"
REAL_RESUME="${RESUME_DEV}"
fi
;;
esac
do_resume
fi
if [ -z "${luks_root_started}" ]
then
start_LUKS_root
fi
fi
run mkdir -p "${NEW_ROOT}"
CHROOT="${NEW_ROOT}"
# Run debug shell if requested
run_debug_shell "before setting up the root filesystem"
if [ "${CDROOT}" = '1' ]
then
# Setup the root filesystem
bootstrapFS
if [ "${aufs}" = '1' ]
then
setup_aufs
CHROOT=${aufs_union}
elif [ "${overlayfs}" = '1' ] && [ "${got_good_root}" != '1' ]
then
bootstrapCD
CHROOT=${NEW_ROOT}
fi
if [ "${got_good_root}" != '1' ] && [ /dev/nfs != "${REAL_ROOT}" ] && [ sgimips != "${LOOPTYPE}" ] && [ 1 != "${aufs}" ] && [ 1 != "${overlayfs}" ]
then
bootstrapCD
fi
if [ "${REAL_ROOT}" = '' ] && [ "${got_good_root}" != '1' ]
then
warn_msg "No bootable medium found. Waiting for new devices ..."
COUNTER=0
while [ ${COUNTER} -lt 3 ]
do
sleep 3
let COUNTER=${COUNTER}+1
done
sleep 1
bootstrapCD
fi
if [ "${REAL_ROOT}" = '' ] && [ "${got_good_root}" != '1' ]
then
# Undo stuff
run umount "${NEW_ROOT}/dev" 2>/dev/null
run umount "${NEW_ROOT}/sys" 2>/dev/null
run umount /sys 2>/dev/null
run umount "${NEW_ROOT}"
run rm -rf "${NEW_ROOT}/*"
bad_msg 'Could not find CD to boot, something else needed!'
CDROOT=0
fi
fi
# Determine root device
let ROOTDELAY_TIMEOUT=$(date +%s)+1
ROOTDELAY_TIME_WAITED=0
[ -n "${ROOTDELAY}" -a ${ROOTDELAY} -gt 0 ] && let ROOTDELAY_TIMEOUT=${ROOTDELAY_TIMEOUT}+${ROOTDELAY}-1
while true
do
good_msg_n "Determining root device (trying ${REAL_ROOT}) ..."
while [ "${got_good_root}" != '1' ]
do
# Start of sleep loop waiting on root
while [ "${got_good_root}" != '1' -a $(date +%s) -le ${ROOTDELAY_TIMEOUT} ]
do
case "${REAL_ROOT}" in
LABEL=*|UUID=*|PARTLABEL=*|PARTUUID=*)
ROOT_DEV=""
retval=1
if [ ${retval} -ne 0 ]
then
ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -ne 0 ]
then
ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]
then
got_good_root=1
REAL_ROOT="${ROOT_DEV}"
echo
good_msg "Root device detected as ${REAL_ROOT}!"
break
fi
;;
ZFS*)
if [ "${USE_ZFS}" = '0' ]
then
bad_msg "Cannot use ZFS when started without 'dozfs' kernel command-line parameter!"
break
fi
ROOT_DEV="${REAL_ROOT#*=}"
if [ "${ROOT_DEV}" != 'ZFS' ]
then
if [ "$(get_zfs_property "${ROOT_DEV}" type)" = 'filesystem' ]
then
got_good_root=1
REAL_ROOT=${ROOT_DEV}
ROOTFSTYPE=zfs
echo
good_msg "Root device detected as ${REAL_ROOT}!"
break
else
bad_msg "${ROOT_DEV} is not a filesystem"
continue
fi
else
BOOTFS=$(zpool list -H -o bootfs 2>/dev/null)
if [ "${BOOTFS}" != '-' ]
then
for i in ${BOOTFS}
do
zfs get type ${i} > /dev/null 2>&1
if [ $? -eq 0 ]
then
got_good_root=1
REAL_ROOT=${i}
ROOTFSTYPE=zfs
echo
good_msg "Root device detected as ${REAL_ROOT}!"
break
fi
done
fi
fi
;;
*)
ROOT_DEV=$(readlink -f "${REAL_ROOT}")
if [ -b "${ROOT_DEV}" ]
then
got_good_root=1
REAL_ROOT=${ROOT_DEV}
echo
good_msg "Root device detected as ${REAL_ROOT}!"
break
fi
;;
esac
unset ROOT_DEV
if [ "${got_good_root}" != '1' ]
then
let ROOTDELAY_TIME_WAITED=${ROOTDELAY_TIME_WAITED}+1
sleep 0.1s
let ROOTDELAY_100MSEC_MODULO=${ROOTDELAY_TIME_WAITED}%10
if [ ${ROOTDELAY_100MSEC_MODULO} = 0 ]
then
printf "."
fi
fi
done # End of sleep loop waiting on root
if [ $(date +%s) -gt ${ROOTDELAY_TIMEOUT} ]
then
echo
fi
if [ "${USE_ZFS}" = '1' ]
then
write_env_file \
"${ZFS_ENC_ENV_FILE}" \
REAL_ROOT \
ROOTFSTYPE
fi
# Check for a block device or /dev/nfs or zfs encryption
if [ -n "${REAL_ROOT}" ] && [ "${REAL_ROOT}" = "/dev/nfs" ] || [ "${ROOTFSTYPE}" = "zfs" ] || [ -b "${REAL_ROOT}" ]
then
if [ "${ROOTFSTYPE}" = "zfs" ]
then
# at this point we determined dataset and are ready to mount
# let's check if this dataset is encrypted and ask for passphrase
if [ "$(zpool list -H -o feature@encryption "${REAL_ROOT%%/*}" 2>/dev/null)" = 'active' ]
then
ZFS_KEYSTATUS="$(get_zfs_property "${REAL_ROOT}" keystatus)"
ZFS_ENCRYPTIONROOT="$(get_zfs_property "${REAL_ROOT}" encryptionroot)"
if [ "${ZFS_ENCRYPTIONROOT}" != '-' ] && [ "${ZFS_KEYSTATUS}" = 'unavailable' ]
then
good_msg "Detected ZFS encryption, asking for key"
run zfs load-key "${ZFS_ENCRYPTIONROOT}"
# Get new key status to check if load-key was successful
# or dataset has been opened by someone else in the meantime (through SSH for instance)
ZFS_KEYSTATUS="$(get_zfs_property "${REAL_ROOT}" keystatus)"
if [ "${ZFS_KEYSTATUS}" != 'available' ]
then
bad_msg "${REAL_ROOT} is encrypted and not mountable without key"
got_good_root=0
break
fi
if [ -f "${ZFS_ENC_OPENED_LOCKFILE}" ]
then
good_msg "${REAL_ROOT} device meanwhile was opened by someone else."
else
run touch "${ZFS_ENC_OPENED_LOCKFILE}"
fi
fi
fi
else
got_good_root=1
fi
fi
break
done
if [ "${got_good_root}" = '1' -a "${CDROOT}" = 1 -a "${REAL_ROOT}" != "/dev/nfs" ]
then
# CD already mounted; no further checks necessary
break
elif [ "${got_good_root}" = '1' -a "${LOOPTYPE}" = 'sgimips' ]
then
# sgimips mounts the livecd root partition directly
# there is no isofs filesystem to worry about
break
elif [ "${got_good_root}" = '1' ]
then
good_msg "Mounting ${REAL_ROOT} as root ..."
if [ "${ROOTFSTYPE}" = 'zfs' ]
then
if [ "$(get_zfs_property "${REAL_ROOT}" mountpoint)" = 'legacy' ]
then
MOUNT_STATE=rw
else
MOUNT_STATE=rw,zfsutil
fi
else
MOUNT_STATE=ro
fi
# Try to mount the device as ${NEW_ROOT}
if [ "${REAL_ROOT}" = '/dev/nfs' ]
then
findnfsmount
mountret=$?
else
# If $REAL_ROOT is a symlink
# Resolve it like util-linux mount does
[ -L ${REAL_ROOT} ] && REAL_ROOT=$(readlink -f ${REAL_ROOT})
# determine fs -- 'auto' will not trigger module loading!
ROOTFSTYPE=$(determine_fs "${REAL_ROOT}" "${ROOTFSTYPE}")
# mount ro so fsck doesn't barf later
if [ "${REAL_ROOTFLAGS}" = '' ]
then
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}"
run mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
mountret=$?
else
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}"