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