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