]> TLD Linux GIT Repositories - rc-scripts.git/blob - rc.d/rc.sysinit
- version 0.5.4
[rc-scripts.git] / rc.d / rc.sysinit
1 #!/bin/sh
2 #
3 # /etc/rc.d/rc.sysinit - run once at boot time
4 #
5 # Taken in part from Miquel van Smoorenburg's bcheckrc.
6 #
7
8 # reasonable start values for bootsplash progress.
9 export progress=0
10 export sscripts=45
11 export kscripts=45
12
13 # NLS
14 if [ -r /etc/sysconfig/i18n ]; then
15         . /etc/sysconfig/i18n
16         [ -n "$LANG" ] && export LANG || unset LANG
17         [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
18         [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
19         [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
20         [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
21         [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
22         [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
23         [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
24         [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
25         [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
26 fi
27
28 # Read network config data
29 if [ -r /etc/sysconfig/network ]; then
30         . /etc/sysconfig/network
31 else
32         NETWORKING=no
33         HOSTNAME=localhost
34 fi
35
36 CONSOLE_LOGLEVEL=1
37
38 # Read functions
39 . /lib/rc-scripts/functions
40
41 modprobe_c_cache=""
42 modprobe_c() {
43         if [ "$modprobe_c_cache" ]; then
44                 echo "$modprobe_c_cache"
45                 return
46         fi
47
48         # filter only what is wanted by this script: aliases and options
49         modprobe_c_cache=$(modprobe -c | grep -E '^(alias|options)')
50         echo "$modprobe_c_cache"
51 }
52
53 # parse kernel cmdline
54 # needs /proc mounted
55 parse_cmdline() {
56         local arg cmdline
57         read cmdline < /proc/cmdline
58
59         for arg in $cmdline; do
60                 case "$arg" in
61                 noudev)
62                         # default is set in /etc/sysconfig/system
63                         START_UDEV=no
64                 ;;
65                 nomdadm)
66                         # default is set in /etc/sysconfig/system
67                         MDADM=no
68                 ;;
69                 nomultipath)
70                         # default is set in /etc/sysconfig/system
71                         DM_MULTIPATH=no
72                 ;;
73                 noselinux)
74                         # default is set in /etc/sysconfig/system
75                         SELINUX=no
76                 ;;
77                 nousb)
78                         nousb=1
79                 ;;
80                 nohdparm)
81                         nohdparm=1
82                 ;;
83                 fastboot)
84                         fastboot=1
85                 ;;
86                 nopnp)
87                         nopnp=1
88                 ;;
89                 nomodules)
90                         nomodules=1
91                 ;;
92                 nofirewire)
93                         nofirewire=1
94                 ;;
95                 nofsck)
96                         nofsck=1
97                 ;;
98                 esac
99         done
100 }
101
102 # resolve a device node to its major:minor numbers in decimal or hex
103 get_numeric_dev() {
104         local dev=$1 enc=${2:-hex} res
105
106         res=$(stat -Lc "%t:%T" "$dev")
107         if [ "$enc" = dec ]; then
108                 local oifs=$IFS
109                 IFS=":"
110                 set -- $res
111                 IFS=$oifs
112                 res=$((0x$1)):$((0x$2))
113         fi
114         echo -n $res
115 }
116
117 # setup SELINUX variable
118 init_selinux() {
119         # user knows!
120         if is_no "$SELINUX"; then
121                 return
122         fi
123
124         if ! grep -Fq selinuxfs /proc/filesystems; then
125                 # no support in kernel, no chance
126                 SELINUX=no
127         elif ! is_fsmounted selinuxfs $selinuxfsdir; then
128                 mount -n -t selinuxfs selinuxfs $selinuxfsdir
129         fi
130
131         # Check SELinux status
132         local selinuxfs=$(awk '/ selinuxfs / { print $2 }' /proc/mounts 2> /dev/null)
133         SELINUX=
134         if [ -n "$selinuxfs" ] && [ "$(cat /proc/self/attr/current)" != "kernel" ]; then
135                 if [ -r $selinuxfs/enforce ] ; then
136                         SELINUX=$(cat $selinuxfs/enforce)
137                 else
138                         # assume enforcing if you can't read it
139                         SELINUX=1
140                 fi
141         fi
142 }
143
144 disable_selinux() {
145         local _d selinuxfs _t _r
146
147         while read _d selinuxfs _t _r; do
148                 [ "$_t" = "selinuxfs" ] && break
149         done </proc/mounts
150         echo "*** Warning -- SELinux is active"
151         echo "*** Disabling security enforcement for system recovery."
152         echo "*** Run 'setenforce 1' to reenable."
153         echo "0" > $selinuxfs/enforce
154 }
155
156 relabel_selinux() {
157         local _d selinuxfs _t _r
158
159         while read _d selinuxfs _t _r; do
160                 [ "$_t" = "selinuxfs" ] && break
161         done </proc/mounts
162         echo "
163          *** Warning -- SELinux relabel is required. ***
164          *** Disabling security enforcement.         ***
165          *** Relabeling could take a very long time, ***
166          *** depending on file system size.          ***
167          "
168         echo "0" > $selinuxfs/enforce
169         /sbin/fixfiles -F relabel > /dev/null 2>&1
170         rm -f /.autorelabel
171         echo "*** Enabling security enforcement.         ***"
172         echo $SELINUX > $selinuxfs/enforce
173 }
174
175 # Enable automatic swapon of all partitions with the proper swap magic.
176 # This allows setting up swap without editing /etc/fstab.
177 enable_autoswap() {
178         local swappartitions=$(blkid -t TYPE=swap -o device)
179         if [ -z "$swappartitions" ]; then
180                 return
181         fi
182
183         local curswap=$(awk '/^\/dev/ { print $1 }' /proc/swaps | while read x; do echo -n " "; get_numeric_dev $x; echo -n " "; done)
184
185         local partition
186         for partition in $swappartitions; do
187                 [ ! -e $partition ] && continue
188                 majmin=$(get_numeric_dev $partition)
189                 if ! strstr "$curswap" " $majmin "; then
190                         run_cmd "$(nls 'Enabling local swap partitions: %s' $partition)" swapon $partition
191                 fi
192         done
193 }
194
195
196 enable_swap() {
197         run_cmd "Activating swap" swapon -a "$@"
198         is_yes "$AUTOSWAP" && enable_autoswap
199 }
200
201 # Loads modules from /etc/modules, /etc/modules.X.Y and /etc/modules.X.Y.Z
202 load_kernel_modules() {
203         local modules_file=$1
204         local _x _y _z v v1 old_IFS kernel kerneleq
205         {
206                 read _x _y v _z
207                 old_IFS=$IFS
208                 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
209                 IFS='_-'
210                 set -- $v
211                 v1=${1}
212                 IFS='.'
213                 set -- $v1
214                 IFS=$old_IFS
215
216                 kernel="$1.$2"
217                 kerneleq="$1.$2.$3"
218         } < /proc/version
219
220         local module args
221         # Loop over every line in modules file
222         ( \
223                 grep -hvE '^(#|[[:blank:]]*$)' /etc/$modules_file /etc/$modules_file.$kernel /etc/$modules_file.$kerneleq 2>/dev/null
224                 echo '' # make sure there is a LF at the end
225         ) | while read module args; do
226                 [ -z "$module" ] && continue
227                 # strip comments
228                 args=${args%%#*}
229                 show "Loading %s kernel module(s)" "$module"
230                 busy
231                 modprobe -s $module -- $args && ok || fail
232         done
233 }
234
235 # launch repair shell
236 # which after exiting will reboot
237 repair_shell() {
238         local reason="$2"
239
240         # don't use '\n' in nls macro !
241         echo
242         echo
243         echo "$reason"
244         nls "*** Dropping you to a shell; the system will reboot"
245         nls "*** when you leave the shell."
246         echo
247
248         [ "$SELINUX" = "1" ] && disable_selinux
249         if ! is_no "$RUN_SULOGIN_ON_ERR"; then
250                 /sbin/sulogin
251         else
252                 /bin/sh
253         fi
254
255         run_cmd "Unmounting file systems" umount -a
256         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
257         run_cmd "Automatic reboot in progress" reboot
258 }
259
260 check_root_fs() {
261         show "Checking root filesystem"; started
262         initlog -c "fsck -C -T -a $fsckoptions /"
263         rc=$?
264
265         # A return of 4 or higher means there were serious problems.
266         if [ $rc -gt 3 ]; then
267                 [ -e /proc/splash ] && echo "verbose" > /proc/splash
268
269                 PS1="$(nls '(Repair filesystem)# ')"; export PS1
270                 repair_shell "$(nls '*** An error occurred during the file system check.')"
271
272         # A return of 2 or 3 means that filesystem was repaired but we need
273         # to reboot.
274         elif [ "$rc" = "2" -o "$rc" = "3" ]; then
275                 [ -e /proc/splash ] && echo "verbose" > /proc/splash
276                 echo
277                 nls "*** Filesystem was repaired but system needs to be"
278                 nls "*** rebooted before mounting it."
279                 nls "*** REBOOTING ***"
280                 echo
281
282                 run_cmd "Unmounting file systems" umount -a
283                 mount -n -o remount,ro /
284                 run_cmd "Automatic reboot in progress" reboot
285         elif [ "$rc" = "1" ]; then
286                 _RUN_QUOTACHECK=1
287         fi
288 }
289
290 # Init software RAID arrays
291 init_mdadm() {
292         local output
293
294         if [ ! -x /sbin/mdadm ]; then
295                 return
296         fi
297
298         modprobe -s md
299         if [ ! -f /proc/mdstat ]; then
300                 return
301         fi
302
303         show "Starting up RAID devices"; busy
304         output=$(/sbin/mdadm --assemble --scan 2>&1)
305         ok
306
307         if [ -n "$output" ]; then
308                 echo "$output"
309         fi
310 }
311
312 # Init LVM
313 init_lvm() {
314         if [ ! -x /sbin/vgscan -o ! -x /sbin/vgchange ] && ! is_yes "$EVMS_LVM"; then
315                 return
316         fi
317
318         if is_no "$LVM2"; then
319                 lvmversion=$(LC_ALL=C /sbin/vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
320         else
321                 lvmversion=2
322         fi
323
324         if [ "$lvmversion" = "1" ] ; then
325                 modprobe -s lvm-mod
326                 lvmignorelocking=""
327                 lvmsysinit=""
328         elif [ "$lvmversion" = "2" ] ; then
329                 modprobe -s dm-mod
330                 lvmignorelocking="--ignorelockingfailure"
331                 lvmsysinit="--sysinit"
332         else
333                 modprobe -s lvm-mod
334                 # device mapper (2.5+ and patched 2.4)
335                 modprobe -s dm-mod
336                 lvmignorelocking=""
337                 lvmsysinit=""
338         fi
339
340         run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelocking
341         run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmsysinit
342
343         if [ "$lvmversion" = "2" ]; then
344                 # silently refresh LV /dev nodes (just in case)
345                 /sbin/vgmknodes $lvmignorelocking 1>/dev/null 2>&1
346                 # display VG statistics
347                 /sbin/vgdisplay -s $lvmignorelocking
348         fi
349 }
350
351 # boot logging to /var/log/boot.log. install showconsole package to get it.
352 if ! is_no "$RC_BOOTLOG" && [ -x /sbin/blogd ]; then
353         RC_BOOTLOG=1
354 else
355         RC_BOOTLOG=
356 fi
357
358 if [[ "$container" != lxc* ]]; then
359         # we need /proc mounted before everything
360         is_fsmounted proc /proc || mount -n /proc || mount -n -o gid=17,hidepid=2 -t proc /proc /proc
361
362         parse_cmdline
363
364         if [ -d /run ]; then
365                 is_fsmounted tmpfs /run || mount -n -t tmpfs run /run -o mode=0755,noexec,nosuid,nodev
366         fi
367
368         # Early sysctls
369         apply_sysctl
370
371         # sysfs is also needed before any other things (under kernel > 2.5)
372         if ! is_fsmounted sysfs /sys; then
373                 grep -Fq sysfs /proc/filesystems && mount -n -t sysfs sysfs /sys
374         fi
375         if grep -Fq securityfs /proc/filesystems; then
376                 mount -n -t securityfs securityfs /sys/kernel/security
377         fi
378         if [ -d /sys/firmware/efi ] && ! is_fsmounted efivarfs /sys/firmware/efi/efivars; then
379                 mount -n -o rw -t efivarfs efivarfs /sys/firmware/efi/efivars
380         fi
381
382         if [ -d /sys/fs/selinux ]; then
383                 # Linux 3.0+
384                 selinuxfsdir=/sys/fs/selinux
385         else
386                 selinuxfsdir=/selinux
387         fi
388         init_selinux
389
390         # Choose Hardware profile
391         if ! is_no "$HWPROFILES" && [ -f /etc/sysconfig/hwprof ]; then
392                 . /etc/sysconfig/hwprof
393                 if is_yes "${HWPROFILES}" && [ -x /sbin/hwprofile -a -d /etc/sysconfig/hwprofiles/data ]; then
394                         mount -n / -o rw,remount
395                         /sbin/hwprofile -qf
396                         mount -n / -o ro,remount
397                 fi
398         fi
399
400         # Disable splash when requested
401         is_no "$BOOT_SPLASH" && [ -e /proc/splash ] && echo "0" > /proc/splash
402
403         if [ -x /sbin/restorecon ] && is_fsmounted tmpfs /dev; then
404                 /sbin/restorecon -R /dev 2>/dev/null
405         fi
406
407         [ -z "${CONSOLETYPE}" ] && CONSOLETYPE="$(/sbin/consoletype)"
408
409         if [ "$CONSOLETYPE" = "vt" -a -x /sbin/setsysfont ]; then
410                 /sbin/setsysfont
411         fi
412 fi
413
414
415 # Print welcome message
416 nls "\t\t\t%sPowered by %sTLD Linux%s" "$(termput setaf $CPOWEREDBY)" "$(termput setaf $CTLD)" "$(termput op)"
417 if ! is_no "$RC_PROMPT"; then
418         nls -n "\t\t  Press %sI%s to enter interactive startup" "$(termput setaf $CI)" "$(termput op)"
419         echo
420 fi
421
422 # Set the hostname
423 if [ -z "${HOSTNAME}" ]; then
424         show "$(nls 'Host:') $(hostname)"; ok
425 else
426         run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
427 fi
428
429 # Set the NIS domain name
430 if [ -n "$NISDOMAIN" ]; then
431         run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
432 else
433         domainname ""
434 fi
435
436 if [[ "$container" != lxc* ]]; then
437         # Set console loglevel
438         if [ -n "$CONSOLE_LOGLEVEL" ]; then
439                 dmesg -n $CONSOLE_LOGLEVEL
440         fi
441
442         if ! is_no "$START_UDEV" && [ -x /sbin/start_udev ] && [[ "$container" != lxc* ]]; then
443                 is_fsmounted devtmpfs /dev || mount -n -t devtmpfs devtmpfs /dev
444                 load_kernel_modules modules.preudev
445                 /sbin/start_udev
446         elif [ -x /lib/firmware/firmware-loader.sh ]; then
447                 /sbin/sysctl -q -e -w kernel.hotplug=/lib/firmware/firmware-loader.sh
448         fi
449
450         # Unmount the initrd, if necessary
451         if grep -q /initrd /proc/mounts 2>/dev/null && ! grep -q /initrd/loopfs /proc/mounts 2>/dev/null; then
452                 umount /initrd/dev 2>/dev/null
453                 umount /initrd
454                 /sbin/blockdev --flushbufs /dev/ram0 >/dev/null 2>&1
455         fi
456
457         # Start logging console output since we have all /dev stuff setup
458         if [ "$RC_BOOTLOG" ]; then
459                 /sbin/blogd
460         fi
461
462         # Configure Linux kernel (initial configuration, some required modules still may be missing).
463         apply_sysctl
464
465         # Check if timezone definition is available
466         if [ -e /etc/localtime ] && [ -e /dev/rtc -o -e /dev/rtc0 ] ; then
467                 if run_cmd "$(nls 'Setting clock')" hwclock --hctosys; then
468                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
469                 fi
470         else
471                 TIME_SETUP_DELAYED=yes
472         fi
473
474         delay_cryptsetup=0
475         if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
476                 # XXX might need modules dep
477                 # Device mapper & related initialization
478                 if ! grep -qF device-mapper /proc/devices; then
479                         modprobe -s dm-mod
480                 fi
481
482                 . /etc/rc.d/init.d/cryptsetup
483                 show "Starting disk encryption"
484                 init_crypto 0
485                 delay_cryptsetup=$?
486                 [ $delay_cryptsetup = 0 ] && ok || fail
487         fi
488
489         # Start up swapping
490         enable_swap -e
491
492         # Initialize USB controllers
493         usb=0
494         if [ -z "$nousb" ] && ! is_fsmounted usbfs /proc/bus/usb; then
495                 aliases=$(modprobe_c | awk '/^alias[[:space:]]+usb[-_]controller[[:space:]]+/{ print $3 }')
496                 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
497                         modprobe -s usbcore
498                         for alias in $aliases ; do
499                                 [ "$alias" = "off" ] && continue
500                                 run_cmd "$(nls 'Initializing USB controller') ($alias)" modprobe -s $alias
501                         done
502                         [ $? -eq 0 -a -n "$aliases" ] && usb=1
503                 fi
504                 if grep -iq "usb" /proc/devices 2>/dev/null ; then
505                         usb=1
506                 fi
507         fi
508
509         if [ "$usb" = "1" -a -d /proc/bus/usb ] && ! is_fsmounted usbfs /proc/bus/usb; then
510                 run_cmd "Mounting USB filesystem" mount -n -t usbfs -o devgid=78,devmode=664 usbfs /proc/bus/usb
511         fi
512
513         needusbstorage=
514         if [ "$usb" = "1" ]; then
515                 needusbstorage=$(cat /proc/bus/usb/devices 2>/dev/null | grep -e "^I.*Cls=08" 2>/dev/null)
516                 if [ "$(kernelverser)" -lt "002006" ]; then
517                         grep -Fq 'hid' /proc/bus/usb/drivers 2>/dev/null || run_cmd "Initializing USB HID interface" modprobe -s hid
518                         mouseoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=02" 2>/dev/null)
519                         kbdoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01" 2>/dev/null)
520                         if [ -n "$kbdoutput" ]; then
521                                 run_cmd "Initializing USB keyboard" modprobe -s keybdev
522                         fi
523                         if [ -n "$mouseoutput" ]; then
524                                 run_cmd "Initializing USB mouse" modprobe -s mousedev
525                         fi
526                 fi
527         fi
528
529         # Setup hdparm thing (if exists and is needed)
530         if [ -z "$nohdparm" ]; then
531                 [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
532         fi
533
534         if [ -z "$fastboot" ] && [ -f /fastboot ]; then
535                 fastboot=1
536         fi
537
538         if [ -f /fsckoptions ]; then
539                 fsckoptions=$(cat /fsckoptions)
540         else
541                 fsckoptions=''
542         fi
543
544         if [ -f /forcefsck ]; then
545                 fsckoptions="-f $fsckoptions"
546         else
547                 # Obey the fs_passno setting for / (see fstab(5))
548                 # - find the / entry
549                 # - make sure we have at least 6 fields
550                 _ROOTFS_PASSNO=$(awk '($1 !~ /^#/ && $2 == "/" && NF >= 6) { print $6}' /etc/fstab)
551         fi
552
553         _RUN_QUOTACHECK=0
554         _ROOTFS_DEVICE=$(awk '($1 !~ /^#/ && $2 == "/" && NF >= 6) { print $1}' /etc/fstab)
555         _ROOTFS_TYPE=$(awk '$2 == "/" && $3 != "rootfs" { print $3 }' /proc/mounts 2>/dev/null)
556
557         if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "aufs" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" -a "$_ROOTFS_TYPE" != "tmpfs" -a "$_ROOTFS_TYPE" != "squashfs" -a "$_ROOTFS_PASSNO" != 0 -a -e $_ROOTFS_DEVICE ] && [[ "$container" != lxc* ]]; then
558                 check_root_fs
559         fi
560
561         # set up pnp and kernel pnp
562         if is_yes "$RUN_USERPNP" || is_yes "$RUN_KERNELPNP"; then
563                 if [ -z "$nopnp" ] && is_yes "$RUN_USERPNP" && [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
564                         run_cmd "Setting up ISA PNP devices (userspace pnp)" /sbin/isapnp /etc/isapnp/isapnp.conf
565                 fi
566                 if [ -z "$nopnp" ] && is_yes "$RUN_KERNELPNP"; then
567                         modprobe -s isa-pnp
568                         if [ -e /proc/isapnp -a -f /etc/isapnp/isapnp-kernel.conf ]; then
569                                 show "Setting up ISA PNP devices (kernelspace pnp)"; busy
570                                 grep -v "^#" /etc/isapnp/isapnp-kernel.conf 2>/dev/null >/proc/isapnp && (deltext; ok) || (deltext; fail)
571                         fi
572                 fi
573         fi
574
575         _ROOTFS_RO=$(awk '($1 !~ /^#/ && $2 == "/" && ($4 == "ro" || $4 ~ /,ro$/ || $4 ~ /^ro,/ || $4 ~ /,ro,/ ) && NF >= 6) { print "ro" }' /etc/fstab)
576         # Remount the root filesystem read-write
577         if [ -z "$_ROOTFS_RO" ]; then
578                 run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
579         fi
580
581         # Update quotas if fsck was run on /
582         if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
583                 run_cmd "Checking root filesystem quotas" /sbin/quotacheck -vnug /
584         fi
585
586         # Clean up SELinux labels
587         if is_yes "$SELINUX"; then
588                 for file in /etc/mtab /etc/cryptomtab /etc/ld.so.cache; do
589                         [ -r $file ] && restorecon $file >/dev/null 2>&1
590                 done
591         fi
592
593         if [ "$delay_cryptsetup" != 0 ]; then
594                 show "Starting disk encryption using the RNG"
595                 init_crypto 1
596                 delay_cryptsetup=$?
597                 [ $delay_cryptsetup = 0 ] && ok || fail
598         fi
599 else
600         # Start logging console output since we have all /dev stuff setup
601         if [ "$RC_BOOTLOG" ]; then
602                 /sbin/blogd -q
603         fi
604 fi
605
606 # Remove stale backups
607 rm -f /etc/mtab~ /etc/mtab~~ /etc/cryptomtab~ /etc/cryptomtab~~ >/dev/null 2>&1
608
609 # Remove /etc/nologin when starting system
610 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
611
612 if ! is_no "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
613         show "Enabling Delay Login"; busy
614         echo > /etc/nologin
615         nls "System bootup in progress - please wait" >> /etc/nologin
616         echo >> /etc/nologin
617         chmod 644 /etc/nologin
618         cp -fp /etc/nologin /etc/nologin.boot
619         ok
620 fi
621
622 # The root filesystem is now read-write, so we can now log via
623 # syslog() directly...
624 if [ -n "$IN_INITLOG" ]; then
625         IN_INITLOG=""
626 fi
627
628 if [[ "$container" != lxc* ]]; then
629         # Clear mtab
630         > /etc/mtab
631         [ -f /etc/cryptomtab ] && > /etc/cryptomtab
632
633         # Enter root, /proc, /sys and other into mtab.
634         mount -f / 2> /dev/null
635         mount -f /proc 2> /dev/null
636         if is_fsmounted devtmpfs /dev; then
637                 mount -f -t devtmpfs devtmpfs /dev 2> /dev/null
638         fi
639         if is_fsmounted tmpfs /run; then
640                 mount -f -t tmpfs run /run -o mode=0755,noexec,nosuid,nodev 2> /dev/null
641         fi
642
643         if is_fsmounted usbfs /proc/bus/usb; then
644                 mount -f -t usbfs -o devgid=78,devmode=664 usbfs /proc/bus/usb 2> /dev/null
645         fi
646
647         if is_fsmounted sysfs /sys; then
648                 mount -f -t sysfs sysfs /sys 2> /dev/null
649                 if is_fsmounted securityfs /sys/kernel/security ; then
650                         mount -f -t securityfs securityfs /sys/kernel/security 2> /dev/null
651                 fi
652                 if [ -d /sys/firmware/efi ] && is_fsmounted efivarfs /sys/firmware/efi/efivars ; then
653                         mount -f -t efivarfs efivarfs /sys/firmware/efi/efivars 2> /dev/null
654                 fi
655         fi
656
657         if is_fsmounted selinuxfs $selinuxfsdir; then
658                 mount -f -t selinuxfs selinuxfs $selinuxfsdir 2> /dev/null
659         fi
660
661         if [ ! -f /proc/modules ]; then
662                 USEMODULES=
663         elif [ -z "$nomodules" ]; then
664                 USEMODULES=y
665         else
666                 USEMODULES=
667         fi
668
669         uname_r=$(uname -r)
670         # Adjust symlinks as necessary in /boot to keep system services from
671         # spewing messages about mismatched System maps and so on.
672         if ! is_no "$SET_SLINKS"; then
673                 if [ -L /boot/System.map -a -r /boot/System.map-$uname_r ] ; then
674                         ln -s -f System.map-$uname_r /boot/System.map
675                 fi
676                 if [ ! -e /boot/System.map -a -r /boot/System.map-$uname_r ] ; then
677                         ln -s -f System.map-$uname_r /boot/System.map
678                 fi
679         fi
680
681         # Run depmod if RUN_DEPMOD != "no" and:
682         # a) user requested or RUN_DEPMOD="";
683         # b) modules.dep is missing
684         if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
685                 if is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ]; then
686                         run_cmd "Finding module dependencies" depmod -a
687                 elif [ "$RUN_DEPMOD" = "ifmissing" ] && [ ! -f /lib/modules/$uname_r/modules.dep ]; then
688                         run_cmd "Finding module dependencies" depmod -A
689                 fi
690         fi
691         unset uname_r
692
693         if [ -f /proc/sys/kernel/modprobe ]; then
694                 if [ -n "$USEMODULES" ]; then
695                         sysctl -q -w kernel.modprobe="/sbin/modprobe"
696                 else
697                         # We used to set this to NULL, but that causes
698                         # 'failed to exec' messages"
699                         sysctl -q -w kernel.modprobe="/bin/true"
700                 fi
701         fi
702
703         # Load usb storage here, to match most other things
704         if [ -n "$needusbstorage" ]; then
705                 modprobe -s usb-storage
706         fi
707
708         # Load firewire devices
709         if [ -z "$nofirewire" ]; then
710                 aliases=$(modprobe_c | awk '/^alias[[:space:]]+ieee1394[-_]controller[[:space:]]+/{ print $3 }')
711                 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
712                         for alias in $aliases ; do
713                                 [ "$alias" = "off" ] && continue
714                                 run_cmd "$(nls 'Initializing firewire controller') ($alias)" modprobe $alias
715                         done
716                         grep -E "SBP2" /proc/bus/ieee1394/devices 2>/dev/null && modprobe -s sbp2
717                 fi
718         fi
719
720         # Load sound modules if they need persistent DMA buffers
721         if modprobe_c | grep -q "^options sound dmabuf=1"; then
722                 RETURN=0
723                 alias=$(modprobe_c | awk '/^alias[[:space:]]+sound[[:space:]]+/{ print $3 }')
724                 if [ -n "$alias" -a "$alias" != "off" ] ; then
725                         run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
726                         RETURN=$?
727                 fi
728                 alias=$(modprobe_c | awk '/^alias[[:space:]]+sound[-_]slot[-_]0[[:space:]]+/ { print $3 }')
729                 if [ -n "$alias" -a "$alias" != "off" ] ; then
730                         run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
731                         RETURN=$?
732                 fi
733         fi
734
735         # Load modules
736         load_kernel_modules modules
737         for f in /etc/modules-load.d/*.conf; do
738                 # already loaded by implicit "modules" load
739                 [ "${f##*/}" = "modules.conf" ] && continue
740
741                 [ -r $f ] || continue
742                 load_kernel_modules ${f##/etc/}
743         done
744
745         if ! is_no "$DM_MULTIPATH" && [ -x /sbin/multipath ]; then
746                 modprobe -s dm-mod
747                 modprobe -s dm-multipath
748                 # make nodes that were discarded due (possible) new /dev mount
749                 /sbin/dmsetup mknodes
750                 run_cmd "Activating dm-multipath" /sbin/multipath -v 0
751                 /sbin/dmsetup ls --target multipath --exec '/sbin/kpartx -a -p p'
752         fi
753
754         if ! is_no "$DMRAID" && [ -x /sbin/dmraid ]; then
755                 run_cmd "Activating ATARAID devices" /sbin/dmraid -ay
756         fi
757
758         # Find and activate volume groups:
759         # EVMS
760         if is_yes "$EVMS_LVM" && [ -x /sbin/evms_activate ]; then
761                 if [ "$(kernelverser)" -lt "002006" ]; then
762                         # Linux 2.4 core modules
763                         modprobe -s evms
764                         modprobe -s evms_passthru
765                         modprobe -s ldev_mgr
766                         modprobe -s dos_part
767                 else
768                         # Linux 2.6 core module
769                         modprobe -s evmscore
770                 fi
771
772                 is_yes "$EVMS_GUID_PTABLE" && modprobe -s gpt_part
773                 is_yes "$EVMS_LVM" && modprobe -s lvm_vge
774                 is_yes "$EVMS_AIX" && modprobe -s AIXlvm_vge
775                 is_yes "$EVMS_OS2" && modprobe -s os2lvm_vge
776                 run_cmd "Discovering EVMS volumes" /sbin/evms_activate
777                 if is_yes "$EVMS_LVM" && is_yes "$EVMS_LVM_COMPAT_NODES" ; then
778                         # Link nodes for compatibility with LVM
779                         if [ "$(echo /dev/evms/lvm/*)" != '/dev/evms/lvm/*' ] ; then
780                                 ln -s /dev/evms/lvm/* /dev
781                         fi
782                 fi
783         fi
784
785         if ! is_no "$MDADM"; then
786                 init_mdadm
787         fi
788
789         if ! is_no "$LVM2"; then
790                 init_lvm
791         fi
792
793         if [ "$delay_cryptsetup" != 0 ]; then
794                 show "Starting disk encryption"
795                 init_crypto 1
796                 delay_cryptsetup=$?
797                 [ $delay_cryptsetup = 0 ] && ok || fail
798         fi
799
800         _RUN_QUOTACHECK=0
801         # Check filesystems
802         if [ -z "$fastboot" ] && [ -z "$nofsck" ]; then
803                 rc_splash "fsck start"
804                 show "Checking filesystems"; started
805                 initlog -c "fsck -C -T -R -A -a -P $fsckoptions"
806
807                 rc=$?
808
809                 # A return of 2 or higher means there were serious problems
810                 if [ $rc -gt 1 ]; then
811                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
812
813                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
814                         repair_shell "$(nls '*** An error occurred during the file system check.')"
815
816                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
817                         _RUN_QUOTACHECK=1
818                 fi
819                 rc_splash "fsck stop"
820         fi
821
822         # Mount all other filesystems (except for NFS and /proc, which is already
823         # mounted). Contrary to standard usage,
824         # filesystems are NOT unmounted in single user mode.
825         run_cmd "Mounting local filesystems" mount -a -t nonfs,nfs4,smbfs,ncpfs,proc,cifs -O no_netdev
826
827         # now we have /usr mounted, recheck if we have gettext and tput available.
828         if is_no "$TPUT"; then
829                 GETTEXT=
830                 TPUT=
831                 rc_gettext_init
832         fi
833
834         # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
835         # before mount - that's where the password is entered.
836         # mount is buggy - when remounting loopback filesystem, loop=XXX
837         # option is removed from /etc/mtab
838         if [ -z "$fastboot" ] && grep "^[^#].*encryption=" /etc/fstab 2>/dev/null | grep -v -q "noauto" 2>/dev/null; then
839                 show "Checking encrypted filesystems"; started
840                 LOOPLIST="$(LC_ALL=C awk '
841                 FILENAME=="/proc/mounts" {
842                         TAB[$2]=$1;
843                 }
844                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && /[^a-zA-Z_]ro[^a-zA-Z_]/ {
845                         if ($2 in TAB){print TAB[$2];}
846                 }
847                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
848                         if ($2 in TAB){print TAB[$2];}
849                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",ro",$4);
850                         cmd="mount " $2 " -o remount," $4;
851                         system(cmd);
852                 }
853                 ' /proc/mounts /etc/fstab)"
854                 initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
855                 rc=$?
856
857                 # A return of 2 or higher means there were serious problems.
858                 if [ $rc -gt 1 ]; then
859                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
860
861                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
862                         repair_shell "$(nls '*** An error occurred during the file system check.')"
863
864                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
865                         _RUN_QUOTACHECK=1
866                 fi
867
868                 show "Remounting encrypted filesystems back in rw mode"; busy
869                 LC_ALL=C awk '
870                 FILENAME=="/proc/mounts" {
871                         TAB[$2]=$1;
872                 }
873                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
874                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",rw",$4);
875                         cmd="mount " $2 " -o remount," $4;
876                         system(cmd);
877                 }
878                 ' /proc/mounts /etc/fstab
879                 ok
880         fi
881
882         # /var/log should be writable now, so start saving the boot output
883         if [ "$RC_BOOTLOG" ]; then
884                 echo > /var/log/boot.log
885                 killall -IO blogd
886         fi
887
888         if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
889                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -vnugRa
890         fi
891
892         # Turn on quota
893         if [ -x /sbin/quotaon ]; then
894                 run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
895         fi
896
897         # Turn on process accounting
898         if [ -x /etc/rc.d/rc.acct ]; then
899                 /etc/rc.d/rc.acct start
900         fi
901
902         # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
903         if is_yes "$TIME_SETUP_DELAYED" && [ -e /dev/rtc -o -e /dev/rtc0 ]; then
904                 if run_cmd "$(nls 'Setting clock')" hwclock --hctosys; then
905                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
906                 fi
907         fi
908
909         # Initialize the serial ports
910         if [ -f /etc/rc.d/rc.serial ]; then
911                 . /etc/rc.d/rc.serial
912         fi
913
914         if [ -n "$PANIC_REBOOT_TIME" ] && [ "$PANIC_REBOOT_TIME" -gt "0" ] && [ -f /proc/sys/kernel/panic ]; then
915                 show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
916                 # DEPRECATED: use /etc/sysctl.conf or kernel commandline instead
917                 if sysctl -q -w kernel.panic=$PANIC_REBOOT_TIME; then ok; else fail; fi
918         fi
919
920         # ... and here finish configuring parameters
921         apply_sysctl
922 else
923         # /var/log should be writable now, so start saving the boot output
924         if [ "$RC_BOOTLOG" ]; then
925                 echo > /var/log/boot.log
926                 killall -IO blogd
927         fi
928
929 fi
930
931 is_yes "$SELINUX" && [ -f /.autorelabel ] && relabel_selinux
932
933 # Clean up /.
934 rm -f /fastboot /fsckoptions /forcefsck /halt /poweroff >/dev/null 2>&1
935
936 # Clean up /var
937 # /usr could be still not mounted if it is on NFS.
938 for afile in /var/lock/* /var/run/*; do
939         bafile=${afile##*/}
940         if [ -d "$afile" ]; then
941                 case $bafile in
942                 news|sudo|mon|cvs)
943                         ;;
944                 *)
945                         echo $afile/* | xargs rm -rf
946                         ;;
947                 esac
948         else
949                 [ "$bafile" != "hwprofile" -a "$bafile" != "random-seed" ] && rm -f $afile 2> /dev/null
950         fi
951 done
952
953 # Delete stale files
954 rm -f /var/lib/rpm/__db* /var/spool/postoffice/.pid.* /tmp/.X*-lock \
955         /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*
956 rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
957         /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \
958         /tmp/scrollkeeper-* /tmp/ssh-*
959
960 {
961 # Clean up utmp/wtmp
962 rm -f /var/run/utmpx
963 > /var/run/utmp
964 if [ -e /var/log/wtmpx ]; then
965         if [ -e /var/log/wtmp ]; then
966                 rm -f /var/log/wtmpx
967         else
968                 mv /var/log/wtmpx /var/log/wtmp
969         fi
970 fi
971 touch /var/log/wtmp
972 chown root:utmp /var/run/utmp /var/log/wtmp
973 chmod 0664 /var/run/utmp /var/log/wtmp
974
975 # Clean /tmp
976 if is_yes "$CLEAN_TMP" && ! is_fsmounted tmpfs /tmp; then
977         LC_ALL=C rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
978 fi
979
980 # System protected dirs
981 mkdir -m 1777 -p /tmp/.ICE-unix > /dev/null 2>&1
982 chown root:root /tmp/.ICE-unix
983 is_yes "$SELINUX" && restorecon /tmp/.ICE-unix >/dev/null 2>&1
984
985 test -d /var/run/netreport || mkdir -m 770 /var/run/netreport
986
987 enable_swap
988
989 # If a SCSI tape has been detected, load the st module unconditionally
990 # since many SCSI tapes don't deal well with st being loaded and unloaded
991 if [ -f /proc/scsi/scsi ] && grep -q 'Type:   Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
992         if grep -qv ' 9 st' /proc/devices 2>/dev/null; then
993                 if [ -n "$USEMODULES" ] ; then
994                         # Try to load the module. If it fails, ignore it...
995                         insmod -p st >/dev/null 2>&1 && modprobe -s st
996                 fi
997         fi
998 fi
999
1000 # Now that we have all of our basic modules loaded and the kernel going,
1001 # let's dump the syslog ring somewhere so we can find it later
1002 mode=0600
1003 if [ "$(cat /proc/sys/kernel/dmesg_restrict)" = 0 ]; then
1004         mode=0644
1005 fi
1006 dmesg --raw > /var/log/dmesg
1007 chmod $mode /var/log/dmesg
1008 i=5
1009 while [ $i -ge 0 ]; do
1010         if [ -f /var/log/dmesg.$i ]; then
1011                 mv -f /var/log/dmesg.$i /var/log/dmesg.$(($i+1))
1012         fi
1013         i=$(($i-1))
1014 done
1015 cp -pf /var/log/dmesg /var/log/dmesg.0
1016
1017 if ! is_no "$RC_PROMPT"; then
1018         while :; do
1019                 pid=$(/sbin/pidof getkey)
1020                 [ -n "$pid" -o -e /var/run/getkey_done ] && break
1021                 usleep 100000
1022         done
1023         [ -n "$pid" ] && kill -TERM "$pid" >/dev/null 2>&1
1024 fi
1025 } &
1026
1027 # /proc extra check if the background process we just spawned is still running
1028 # as it may finish quite instantly.
1029 if ! is_no "$RC_PROMPT" && [ -d /proc/$! ]; then
1030         /sbin/getkey i && touch /var/run/confirm
1031         touch /var/run/getkey_done
1032 fi
1033 wait
1034 if ! is_no "$RC_PROMPT"; then
1035         rm -f /var/run/getkey_done
1036 fi
1037 echo