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