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