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