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