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