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