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