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