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