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