]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- remove duplicate entries in vserver guest /etc/mtab
[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 # Changes:      Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
8 #
9
10 # Set the path
11 PATH=/bin:/sbin:/usr/bin:/usr/sbin
12 export PATH
13
14 # reasonable start values for bootsplash progress.
15 export progress=0
16 export sscripts=45
17 export kscripts=45
18
19 # we need /proc mounted before everything
20 mount -n -o gid=17 -t proc /proc /proc
21
22 # NLS
23 if [ -r /etc/sysconfig/i18n ]; then
24         . /etc/sysconfig/i18n
25         [ -n "$LANG" ] && export LANG || unset LANG
26         [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
27         [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
28         [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
29         [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
30         [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
31         [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
32         [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
33         [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
34         [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
35 fi
36
37 # Read network config data
38 if [ -r /etc/sysconfig/network ]; then
39         . /etc/sysconfig/network
40 else
41         NETWORKING=no
42         HOSTNAME=localhost
43 fi
44
45 # Read system config data
46 if [ -r /etc/sysconfig/system ]; then
47         . /etc/sysconfig/system
48 else
49         RUN_SULOGIN_ON_ERR=yes
50         RUN_USERPNP=yes
51         RUN_KERNELPNP=yes
52         PANIC_REBOOT_TIME=0
53         DELAY_LOGIN=yes
54         CLEAN_TMP=no
55         CONSOLE_LOGLEVEL=1
56         SET_SLINKS=yes
57         RUN_LDCONFIG=yes
58 fi
59
60 # Read functions
61 . /etc/rc.d/init.d/functions
62
63 # sysfs is also needed before any other things (under kernel > 2.5)
64 if ! is_yes "$VSERVER" && grep -q sysfs /proc/filesystems 2>/dev/null ; then
65         mount -n -o gid=17 -t sysfs sysfs /sys
66         if [ "$(kernelver)" -ge "002006014" ] && \
67                 grep -q securityfs /proc/filesystems 2>/dev/null ; then
68                         mount -n -o gid=17 -t securityfs securityfs /sys/kernel/security
69         fi
70                                                                                                         
71 fi
72
73 # selinux
74 if ! is_yes "$VSERVER" && grep -q selinuxfs /proc/filesystems 2>/dev/null && ! grep -q selinuxfs /proc/mounts 2>/dev/null; then
75         mount -n -o gid=17 -t selinuxfs selinuxfs /selinux
76 fi
77
78 if [ $(kernelverser) = "002006" ]; then
79         MODULES_CONF=/etc/modprobe.conf
80 elif [ -r /etc/modules.conf ]; then
81         MODULES_CONF=/etc/modules.conf
82 else
83         MODULES_CONF=/etc/conf.modules
84 fi
85
86 # PLD LiveCD support
87 if [ -x /etc/rc.d/rc.live ]; then
88         /etc/rc.d/rc.live
89 fi
90
91 # Choose Hardware profile
92 if [ -f /etc/sysconfig/hwprof ]; then
93         . /etc/sysconfig/hwprof
94         if is_yes "${HWPROFILES}" && [ -x /sbin/hwprofile -a -d /etc/sysconfig/hwprofiles/data ]; then
95                 mount -n / -o rw,remount
96                 /sbin/hwprofile -qf
97                 mount -n / -o ro,remount
98         fi
99 fi
100
101 # Disable splash when requested
102 [ -e /proc/splash ] && is_no "$BOOT_SPLASH" && echo "0" > /proc/splash
103
104 # Check SELinux status
105 selinuxfs=$(awk '/ selinuxfs / { print $2 }' /proc/mounts)
106 SELINUX=
107 if [ -n "$selinuxfs" ] && [ "$(cat /proc/self/attr/current)" != "kernel" ]; then
108         if [ -r $selinuxfs/enforce ] ; then
109                 SELINUX=$(cat $selinuxfs/enforce)
110         else
111                 # assume enforcing if you can't read it
112                 SELINUX=1
113         fi
114 fi
115
116 if [ -x /sbin/restorecon ] && LC_ALL=C fgrep -q " /dev " /proc/mounts 2>/dev/null ; then
117         /sbin/restorecon -R /dev 2>/dev/null
118 fi
119
120
121 if [ "$CONSOLETYPE" = "vt" -a -x /sbin/setsysfont ]; then
122         run_cmd "Setting default font" /sbin/setsysfont
123 fi
124
125 # Print welcome message
126 nls "\t\t\t%sPowered by %sPLD Linux Distribution%s" "$(termput setaf $CPOWEREDBY)" "$(termput setaf $CPLD)" "$(termput op)"
127 if is_yes "$PROMPT"; then
128         nls -n "\t\t  Press %sI%s to enter interactive startup" "$(termput setaf $CI)" "$(termput op)"
129         echo
130         sleep 1
131 fi
132
133 # Set the hostname
134 run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
135
136 # Set the NIS domain name
137 if [ -n "$NISDOMAIN" ]; then
138         run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
139 else
140         domainname ""
141 fi
142
143 if ! is_yes "$VSERVER"; then
144         # Set console loglevel
145         if [ -n "$CONSOLE_LOGLEVEL" ]; then
146                 /bin/dmesg -n $CONSOLE_LOGLEVEL
147         fi
148
149         if [ -f /etc/udev/udev.conf ];then
150                 . /etc/udev/udev.conf
151         fi
152
153         [ -x /sbin/start_udev ] && run_cmd "Starting udev" /sbin/start_udev
154
155         # /dev must be also mounted before everything but only if we want use them ;-)
156         if is_yes "$MOUNT_DEVFS"; then
157                 run_cmd "Mounting Device Filesystem" mount -n -t devfs /dev /dev
158         fi
159
160         # set up devfsd
161         if [ -e /dev/.devfsd -a -x /sbin/devfsd ]; then
162                 run_cmd "Starting Device Filesystem Daemon" /sbin/devfsd /dev
163         fi
164
165         # cpuset support (mounted unconditionally, shouldn't be a problem)
166         if grep -q cpuset /proc/filesystems 2>/dev/null ; then
167                 mount -n -t cpuset none /dev/cpuset
168         fi
169
170         # Configure Linux kernel (initial configuration, some required modules still
171         # may be missing).
172         /sbin/sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
173
174         # Set the system clock.
175         ARC=0
176         SRM=0
177         UTC=0
178
179         if [ -f /etc/sysconfig/clock ]; then
180                 . /etc/sysconfig/clock
181
182                 # convert old style clock config to new values
183                 if [ "${CLOCKMODE}" = "GMT" ]; then
184                         UTC=true
185                 elif [ "${CLOCKMODE}" = "ARC" ]; then
186                         ARC=true
187                 fi
188         fi
189
190         if grep "system serial" /proc/cpuinfo 2>/dev/null | grep -q MILO 2>/dev/null ; then
191                 ARC=true
192         fi
193
194         CLOCKDEF=""
195         CLOCKFLAGS="--hctosys"
196
197         if is_yes "$UTC" ; then
198                 CLOCKFLAGS="$CLOCKFLAGS --utc"
199                 CLOCKDEF="$CLOCKDEF (utc)"
200         else
201                 CLOCKFLAGS="$CLOCKFLAGS --localtime"
202                 CLOCKDEF="$CLOCKDEF (local)"
203         fi
204
205         if is_yes "$ARC" ; then
206                 CLOCKFLAGS="$CLOCKFLAGS -A"
207                 CLOCKDEF="$CLOCKDEF (arc)"
208         fi
209
210         if is_yes "$SRM" ; then
211                 CLOCKFLAGS="$CLOCKFLAGS -S"
212                 CLOCKDEF="$CLOCKDEF (srm)"
213         fi
214
215         # Check if timezone definition is available
216         if [ -e /etc/localtime ] ; then
217                 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
218                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
219                 fi
220         else
221                 TIME_SETUP_DELAYED=yes
222         fi
223
224         # Start up swapping
225         run_cmd "Activating swap partitions" swapon -a -e
226
227         # Initialize USB controllers
228         usb=0
229         if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && ! grep -q "usb" /proc/devices 2>/dev/null ; then
230                 aliases=$(/sbin/modprobe -c | awk '/^alias usb-controller/ { print $3 }')
231                 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
232                         /sbin/modprobe -k usbcore
233                         for alias in $aliases ; do
234                                 [ "$alias" = "off" ] && continue
235                                 run_cmd "$(nls 'Initializing USB controller') ($alias)" /sbin/modprobe $alias
236                         done
237                         [ $? -eq 0 -a -n "$aliases" ] && usb=1
238                 fi
239                 if grep -iq "usb" /proc/devices 2>/dev/null ; then
240                         usb=1
241                 fi
242         fi
243
244         if [ "$usb" = "1" -a ! -f /proc/bus/usb/devices ]; then
245                 run_cmd "Mounting USB filesystem" mount -t usbfs usbfs /proc/bus/usb
246         fi
247
248         needusbstorage=
249         if [ "$usb" = "1" ]; then
250                 needusbstorage=$(LC_ALL=C cat /proc/bus/usb/devices 2>/dev/null|grep -e "^I.*Cls=08" 2>/dev/null)
251                 if [ "$(kernelverser)" -lt "002006" ]; then
252                         LC_ALL=C grep -q 'hid' /proc/bus/usb/drivers 2>/dev/null || run_cmd "Initializing USB HID interface" modprobe hid 2> /dev/null
253                         mouseoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=02" 2>/dev/null)
254                         kbdoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01" 2>/dev/null)
255                         if [ -n "$kbdoutput" ]; then
256                                 run_cmd "Initializing USB keyboard" modprobe keybdev
257                         fi
258                         if [ -n "$mouseoutput" ]; then
259                                 run_cmd "Initializing USB mouse" modprobe mousedev
260                         fi
261                 fi
262         fi
263
264         # Setup hdparm thing (if exists and is needed)
265         if ! grep -iq nohdparm /proc/cmdline 2>/dev/null; then
266                 [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
267         fi
268
269         if [ -f /fastboot ] || grep -iq "fastboot" /proc/cmdline 2>/dev/null ; then
270                 fastboot=yes
271         else
272                 fastboot=
273         fi
274
275         if [ -f /fsckoptions ]; then
276                 fsckoptions=$(cat /fsckoptions)
277         else
278                 fsckoptions=''
279         fi
280
281         if [ -f /forcefsck ]; then
282                 fsckoptions="-f $fsckoptions"
283         fi
284
285         _RUN_QUOTACHECK=0
286         _ROOTFS_TYPE=$(grep " / " /proc/mounts 2>/dev/null | awk '{ print $3 }')
287
288         if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" ]; then
289                 show "Checking root filesystem"; started
290                 initlog -c "fsck -C -T -a $fsckoptions /"
291
292                 rc=$?
293
294                 # A return of 4 or higher means there were serious problems.
295                 if [ $rc -gt 3 ]; then
296                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
297                         # don't use '\n' in nls macro !
298                         echo
299                         echo
300                         nls "*** An error occurred during the file system check."
301                         nls "*** Dropping you to a shell; the system will reboot"
302                         nls "*** when you leave the shell."
303                         echo
304
305                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
306                         [ "$SELINUX" = "1" ] && disable_selinux
307                         if is_yes "$RUN_SULOGIN_ON_ERR"; then
308                                 /sbin/sulogin
309                         else
310                                 /bin/sh
311                         fi
312
313                         run_cmd "Unmounting file systems" umount -a
314                         mount -n -o remount,ro /
315                         run_cmd "Automatic reboot in progress" reboot
316                 # A return of 2 or 3 means that filesystem was repaired but we need
317                 # to reboot.
318                 elif [ "$rc" = "2" -o "$rc" = "3" ]; then
319                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
320                         echo
321                         nls "*** Filesystem was repaired but system needs to be"
322                         nls "*** rebooted before mounting it."
323                         nls "*** REBOOTING ***"
324                         echo
325
326                         run_cmd "Unmounting file systems" umount -a
327                         mount -n -o remount,ro /
328                         run_cmd "Automatic reboot in progress" reboot
329                 elif [ "$rc" = "1" ]; then
330                         _RUN_QUOTACHECK=1
331                 fi
332         fi
333
334         # Unmount the initrd, if necessary
335         if LC_ALL=C grep -q /initrd /proc/mounts 2>/dev/null && ! LC_ALL=C grep -q /initrd/loopfs /proc/mounts 2>/dev/null ; then
336                 if [ -e /initrd/dev/.devfsd ]; then
337                         umount /initrd/dev
338                 fi
339                 umount /initrd
340                 /sbin/blockdev --flushbufs /dev/ram0 >/dev/null 2>&1
341         fi
342
343         # Check for arguments
344         if grep -iq nopnp /proc/cmdline 2>/dev/null; then
345                 PNP=
346         else
347                 PNP=yes
348         fi
349
350         # set up pnp and kernel pnp
351         if [ -n "$PNP" ]; then
352                 if is_yes "$RUN_USERPNP" && [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
353                         run_cmd "Setting up ISA PNP devices (userspace pnp)" /sbin/isapnp /etc/isapnp/isapnp.conf
354                 fi
355                 if is_yes "$RUN_KERNELPNP"; then
356                         /sbin/modprobe -k isa-pnp 2> /dev/null
357                         if [ -e /proc/isapnp -a -f /etc/isapnp/isapnp-kernel.conf ]; then
358                                 show "Setting up ISA PNP devices (kernelspace pnp)"; busy
359                                 grep -v "^#" /etc/isapnp/isapnp-kernel.conf 2>/dev/null >/proc/isapnp && (deltext; ok) || (deltext; fail)
360                         fi
361                 fi
362         fi
363
364         # Remount the root filesystem read-write
365         run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
366
367         # Update quotas if fsck was run on /
368         if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
369                 run_cmd "Checking root filesystem quotas" /sbin/quotacheck -vnug /
370         fi
371 fi
372
373 # Clean up SELinux labels
374 if [ -n "$SELINUX" ]; then
375         for file in /etc/mtab /etc/cryptomtab /etc/ld.so.cache ; do
376                 [ -r $file ] && restorecon $file >/dev/null 2>&1
377         done
378 fi
379
380 # Remove stale backups
381 rm -f /etc/mtab~ /etc/mtab~~ /etc/cryptomtab~ /etc/cryptomtab~~
382
383 if ! is_yes "$VSERVER"; then
384         # Clear mtab
385         :>/etc/mtab
386         [ -f /etc/cryptomtab ] && :>/etc/cryptomtab
387
388         # Enter root, /proc, /sys, devfs and other into mtab.
389         mount -f /
390         mount -f /proc
391         [ -f /proc/bus/usb/devices ] && mount -f -t usbfs usbfs /proc/bus/usb
392         [ -e /dev/.devfsd ] && mount -f -t devfs devfs /dev
393
394         if grep -q sysfs /proc/filesystems 2>/dev/null ; then
395                 mount -f -t sysfs sysfs /sys
396                 if [ "$(kernelver)" -ge "002006014" ] && \
397                         grep -q securityfs /proc/filesystems 2>/dev/null ; then
398                                 mount -f -t securityfs securityfs /sys/kernel/security
399                 fi
400         fi
401
402         if grep -q selinuxfs /proc/filesystems 2>/dev/null ; then
403                 mount -f -t selinuxfs selinuxfs /selinux
404         fi
405
406         if grep -q cpuset /proc/filesystems 2>/dev/null ; then
407                 mount -n -t cpuset none /dev/cpuset
408         fi
409 else
410         clean_vserver_mtab
411 fi
412
413 # Remove /etc/nologin when starting system
414 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
415
416 if is_yes "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
417         show "Enabling Delay Login"; busy
418         echo > /etc/nologin
419         nls "System bootup in progress - please wait" >> /etc/nologin
420         echo >> /etc/nologin
421         chmod 644 /etc/nologin
422         cp -fp /etc/nologin /etc/nologin.boot
423         ok
424 fi
425
426 # The root filesystem is now read-write, so we can now log via
427 # syslog() directly...
428 if [ -n "$IN_INITLOG" ]; then
429         IN_INITLOG=""
430 fi
431
432 if ! is_yes "$VSERVER"; then
433         if [ ! -f /proc/modules ]; then
434                 USEMODULES=
435         elif ! grep -iq nomodules /proc/cmdline 2>/dev/null; then
436                 USEMODULES=y
437         else
438                 USEMODULES=
439         fi
440
441         # Adjust symlinks as necessary in /boot to keep system services from
442         # spewing messages about mismatched System maps and so on.
443         if is_yes "$SET_SLINKS"; then
444                 if [ -L /boot/System.map -a -r /boot/System.map-`uname -r` ] ; then
445                         ln -s -f System.map-`uname -r` /boot/System.map
446                 fi
447                 if [ ! -e /boot/System.map -a -r /boot/System.map-`uname -r` ] ; then
448                         ln -s -f System.map-`uname -r` /boot/System.map
449                 fi
450         fi
451
452         # Run depmod if RUN_DEPMOD != "no" and:
453         # a) user requested or RUN_DEPMOD="";
454         # b) modules.dep is missing
455         # c) modules.dep is older than /etc/modules.conf or /lib/modules/`uname -r`
456         if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
457                 if is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ]; then
458                         run_cmd "Finding module dependencies" depmod -a
459                 elif [ "$RUN_DEPMOD" = "ifmissing" ]; then
460                         run_cmd "Finding module dependencies" depmod -A
461                 fi
462         fi
463
464         if [ -f /proc/sys/kernel/modprobe ]; then
465                 if [ -n "$USEMODULES" ]; then
466                         sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
467                         sysctl -w kernel.hotplug="/sbin/hotplug" >/dev/null 2>&1
468                 else
469                         # We used to set this to NULL, but that causes
470                         # 'failed to exec' messages"
471                         sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
472                         sysctl -w kernel.hotplug="/bin/true" >/dev/null 2>&1
473                 fi
474         fi
475
476         # Load usb storage here, to match most other things
477         if [ -n "$needusbstorage" ]; then
478                 modprobe -k usb-storage >/dev/null 2>&1
479         fi
480
481         # Load firewire devices
482         if ! grep -iq "nofirewire" /proc/cmdline 2>/dev/null ; then
483                 aliases=$(/sbin/modprobe -c | awk '/^alias ieee1394-controller/ { print $3 }')
484                 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
485                         for alias in $aliases ; do
486                                 [ "$alias" = "off" ] && continue
487                                 run_cmd "$(nls 'Initializing firewire controller') ($alias)" /sbin/modprobe $alias
488                         done
489                         LC_ALL=C grep -E "SBP2" /proc/bus/ieee1394/devices 2>/dev/null && /sbin/modprobe -s sbp2 > /dev/null 2>&1
490                 fi
491         fi
492
493         # Load sound modules if they need persistent DMA buffers
494         if grep -q "^options sound dmabuf=1" "$MODULES_CONF" 2>/dev/null ; then
495                 RETURN=0
496                 alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
497                 if [ -n "$alias" -a "$alias" != "off" ] ; then
498                         run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
499                         RETURN=$?
500                 fi
501                 alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound-slot-0[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
502                 if [ -n "$alias" -a "$alias" != "off" ] ; then
503                         run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
504                         RETURN=$?
505                 fi
506         fi
507
508         # Load modules
509         if [ -x /etc/rc.d/rc.modules ]; then
510                 /etc/rc.d/rc.modules
511         fi
512
513         # Find and activate volume groups:
514         # EVMS
515         if [ -x /sbin/evms_activate ]; then
516                 if [ "$(kernelverser)" -lt "002006" ]; then
517                         # Linux 2.4 core modules
518                         modprobe -s -k evms > /dev/null 2>&1
519                         modprobe -s -k evms_passthru > /dev/null 2>&1
520                         modprobe -s -k ldev_mgr > /dev/null 2>&1
521                         modprobe -s -k dos_part > /dev/null 2>&1
522                 else
523                         # Linux 2.6 core module
524                         modprobe -s -k evmscore > /dev/null 2>&1
525                 fi
526
527                 is_yes "$EVMS_GUID_PTABLE" && modprobe -s -k gpt_part >/dev/null 2>&1
528                 is_yes "$EVMS_LVM" && modprobe -s -k lvm_vge >/dev/null 2>&1
529                 is_yes "$EVMS_AIX" && modprobe -s -k AIXlvm_vge >/dev/null 2>&1
530                 is_yes "$EVMS_OS2" && modprobe -s -k os2lvm_vge >/dev/null 2>&1
531                 run_cmd "Discovering EVMS volumes" /sbin/evms_activate
532                 if is_yes "$EVMS_LVM" && is_yes "$EVMS_LVM_COMPAT_NODES" ; then
533                         # Link nodes for compatibility with LVM
534                         if [ "echo /dev/evms/lvm/*" != '/dev/evms/lvm/*' ] ; then
535                                 ln -s /dev/evms/lvm/* /dev/
536                         fi
537                 fi
538         fi
539         # LVM (keep in sync with LVM starting after RAID run!)
540         if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
541                 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version:     ",""); gsub(/\..*/,"");print $1; exit}')
542                 if [ "$lvmversion" = "1" ] ; then
543                         modprobe -s -k lvm-mod >/dev/null 2>&1
544                         lvmignorelock=""
545                 elif [ "$lvmversion" = "2" ] ; then
546                         modprobe -s -k dm-mod >/dev/null 2>&1
547                         lvmignorelock="--ignorelockingfailure"
548                 else
549                         modprobe -s -k lvm-mod >/dev/null 2>&1
550                         # device mapper (2.5+ and patched 2.4)
551                         modprobe -s -k dm-mod >/dev/null 2>&1
552                         lvmignorelock=""
553                 fi
554
555                 run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelock && \
556                 run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmignorelock
557                 [ "$lvmversion" = "2" ] && /sbin/vgscan --mknodes $lvmignorelock > /dev/null 2>&1
558
559         fi
560
561         # Add raid devices
562         if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ] || [ -f /etc/raidtab ]; then
563                 modprobe -s md >/dev/null 2>&1
564                 if [ -f /proc/mdstat ]; then
565                         goraidtab=1
566                         golvm=0
567                         rc=0
568                         if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
569                                 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
570                                         run_cmd "Starting up RAID devices" /sbin/mdadm --assemble --scan
571                                         rc=$?
572                                         [ "$rc" -eq 0 ] && goraidtab=0 && golvm=1
573                                 fi
574                         fi
575
576                         if [ -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
577                                 for i in $(grep -v "^#" /etc/raidtab 2>/dev/null | grep "raiddev" 2>/dev/null | awk '{print $2}') ; do
578                                         golvm=1
579                                         RAIDDEV=$(basename $i)
580                                         RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat 2>/dev/null)
581                                         show "Starting up RAID device %s" $RAIDDEV
582                                         busy
583                                         if [ -z "$RAIDSTAT" ]; then
584                                                 # Try raidstart first...if that fails then
585                                                 # fall back to raid0run and if that fails too
586                                                 # fall back to raidadd, raidrun.
587                                                 RESULT=1
588                                                 if [ -x /sbin/raidstart ]; then
589                                                         /sbin/raidstart $i
590                                                         RESULT=$?
591                                                 fi
592                                                 if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
593                                                         /sbin/raid0run $i
594                                                         RESULT=$?
595                                                 fi
596                                                 if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
597                                                         /sbin/raidadd $i
598                                                         /sbin/raidrun $i
599                                                         RESULT=$?
600                                                 fi
601                                                 if [ $RESULT -gt 0 ]; then
602                                                         rc=1
603                                                         fail
604                                                 else
605                                                         ok
606                                                 fi
607                                         else
608                                                 ok
609                                         fi
610                                 done
611                         fi
612
613                         # A non-zero return means there were problems
614                         if [ $rc -gt 0 ]; then
615                                 [ -e /proc/splash ] && echo "verbose" > /proc/splash
616                                 show "Starting up RAID devices"; fail
617                                 echo
618                                 echo
619                                 nls "*** An error occurred during the RAID startup."
620                                 nls "*** Dropping you to a shell; the system will reboot"
621                                 nls "*** when you leave the shell."
622                                 echo
623
624                                 PS1="$(nls '(RAID Repair)# ')"; export PS1
625                                 [ "$SELINUX" = "1" ] && disable_selinux
626                                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
627                                         /sbin/sulogin
628                                 else
629                                         /bin/sh
630                                 fi
631
632                                 run_cmd "Unmounting file systems" umount -a
633                                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
634                                 run_cmd "Automatic reboot in progress" reboot
635                         fi
636                         # LVM on RAID (keep in sync with LVM setting few lines above)
637                         if [ "$golvm" -eq "1" ]; then
638                                 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
639                                         run_cmd "Scanning for LVM volume groups (on RAID)" /sbin/vgscan $lvmignorelock && \
640                                         run_cmd "Activating LVM volume groups (on RAID)" /sbin/vgchange -a y $lvmignorelock
641                                         [ "$lvmversion" = "2" ] && /sbin/vgscan --mknodes $lvmignorelock > /dev/null 2>&1
642                                 fi
643                         fi
644                         show "Starting up RAID devices"; ok
645                 fi
646         fi
647
648         _RUN_QUOTACHECK=0
649         # Check filesystems
650         if [ -z "$fastboot" ] && ! grep -q nofsck /proc/cmdline 2>/dev/null; then
651                 rc_splash "fsck start"
652                 show "Checking filesystems"; started
653                 initlog -c "fsck -C -T -R -A -a $fsckoptions"
654
655                 rc=$?
656
657                 # A return of 2 or higher means there were serious problems
658                 if [ $rc -gt 1 ]; then
659                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
660                         echo
661                         echo
662                         nls "*** An error occurred during the file system check."
663                         nls "*** Dropping you to a shell; the system will reboot"
664                         nls "*** when you leave the shell."
665                         echo
666
667                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
668                         [ "$SELINUX" = "1" ] && disable_selinux
669                         if is_yes "$RUN_SULOGIN_ON_ERR"; then
670                                 /sbin/sulogin
671                         else
672                                 /bin/sh
673                         fi
674
675                         run_cmd "Unmounting file systems" umount -a
676                         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
677                         run_cmd "Automatic reboot in progress" reboot
678                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
679                         _RUN_QUOTACHECK=1
680                 fi
681                 rc_splash "fsck stop"
682         fi
683
684         # Mount all other filesystems (except for NFS and /proc, which is already
685         # mounted). Contrary to standard usage,
686         # filesystems are NOT unmounted in single user mode.
687
688         run_cmd "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc,cifs -O no_netdev
689
690         # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
691         # before mount - that's where the password is entered.
692         # mount is buggy - when remounting loopback filesystem, loop=XXX
693         # option is removed from /etc/mtab
694         if [ -z "$fastboot" ] && grep "^[^#].*encryption=" /etc/fstab 2>/dev/null | grep -v -q "noauto" 2>/dev/null; then
695                 show "Checking encrypted filesystems"; started
696                 LOOPLIST="$(awk '
697                 FILENAME=="/proc/mounts" {
698                         TAB[$2]=$1;
699                 }
700                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && /[^a-zA-Z_]ro[^a-zA-Z_]/ {
701                         if ($2 in TAB){print TAB[$2];}
702                 }
703                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
704                         if ($2 in TAB){print TAB[$2];}
705                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",ro",$4);
706                         cmd="mount " $2 " -o remount," $4;
707                         system(cmd);
708                 }
709                 ' /proc/mounts /etc/fstab)"
710                 initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
711                 rc=$?
712
713                 # A return of 2 or higher means there were serious problems.
714                 if [ $rc -gt 1 ]; then
715                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
716                         echo
717                         echo
718                         nls "*** An error occurred during the file system check."
719                         nls "*** Dropping you to a shell; the system will reboot"
720                         nls "*** when you leave the shell."
721                         echo
722
723                         PS1="`nls '(Repair filesystem)# '`"; export PS1
724                         [ "$SELINUX" = "1" ] && disable_selinux
725                         if is_yes "$RUN_SULOGIN_ON_ERR"; then
726                                 /sbin/sulogin
727                         else
728                                 /bin/sh
729                         fi
730
731                         run_cmd "Unmounting file systems" umount -a
732                         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
733                         run_cmd "Automatic reboot in progress" reboot
734                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
735                         _RUN_QUOTACHECK=1
736                 fi
737
738                 show "Remounting encrypted filesystems back in rw mode"; busy
739                 awk '
740                 FILENAME=="/proc/mounts" {
741                         TAB[$2]=$1;
742                 }
743                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
744                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",rw",$4);
745                         cmd="mount " $2 " -o remount," $4;
746                         system(cmd);
747                 }
748                 ' /proc/mounts /etc/fstab
749                 ok
750         fi
751 fi
752
753 if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
754         run_cmd "Checking filesystem quotas" /sbin/quotacheck -vnugRa
755 fi
756
757 # Turn on quota
758 if [ -x /sbin/quotaon ]; then
759         run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
760 fi
761
762 [ -n "$SELINUX" ] && [ -f /.autorelabel ] && relabel_selinux
763
764 # Turn on process accounting
765 if [ -x /etc/rc.d/rc.acct ]; then
766         /etc/rc.d/rc.acct start
767 fi
768
769 if ! is_yes "$VSERVER"; then
770         # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
771         if is_yes "$TIME_SETUP_DELAYED"; then
772                 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
773                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
774                 fi
775         fi
776
777         # Initialize the serial ports
778         if [ -f /etc/rc.d/rc.serial ]; then
779                 . /etc/rc.d/rc.serial
780         fi
781
782         if [ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
783                 show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
784                 if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME >/dev/null 2>&1); then ok; else fail; fi
785         fi
786
787         # ... and here finish configuring parameters
788         /sbin/sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
789 fi
790
791 # Clean up /.
792 rm -f /fastboot /fsckoptions /forcefsck /halt /poweroff
793
794 # Clean up /var
795 # I'd use find, but /usr may not be mounted.
796 for afile in /var/lock/* /var/run/*; do
797         bafile=$(basename $afile)
798         if [ -d "$afile" ]; then
799                 [ "$bafile" != "news" -a "$bafile" != "sudo" -a "$bafile" != "mon" ] && rm -rf $afile/*
800         else
801                 [ "$bafile" != "hwprofile" ] && rm -f $afile 2> /dev/null
802         fi
803 done
804 # Delete stale files
805 rm -f /var/lib/rpm/__db* /var/spool/postoffice/.pid.* /tmp/.X*-lock \
806         /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*
807 rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
808         /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \
809         /tmp/scrollkeeper-* /tmp/ssh-*
810
811 {
812 # Clean up utmp/wtmp
813 if ! is_no "$NEED_XFILES" ; then
814         :>/var/run/utmpx
815         touch /var/log/wtmpx
816         chown root.utmp /var/run/utmpx /var/log/wtmpx
817         chmod 0664 /var/run/utmpx /var/log/wtmpx
818 else
819         :>/var/run/utmp
820         touch /var/log/wtmp
821         chown root.utmp /var/run/utmp /var/log/wtmp
822         chmod 0664 /var/run/utmp /var/log/wtmp
823 fi
824
825 # Clean /tmp
826 if is_yes "$CLEAN_TMP"; then
827         rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
828 fi
829
830 # System protected dirs
831 mkdir -m 1777 -p /tmp/.ICE-unix > /dev/null 2>&1
832 chown root:root /tmp/.ICE-unix
833 [ -n "$SELINUX" ] && restorecon /tmp/.ICE-unix >/dev/null 2>&1
834
835 # Right, now turn on swap in case we swap to files
836 swapon -a >/dev/null 2>&1
837 run_cmd "Enabling swap space" /bin/true
838
839 # If a SCSI tape has been detected, load the st module unconditionally
840 # since many SCSI tapes don't deal well with st being loaded and unloaded
841 if [ -f /proc/scsi/scsi ] && grep -q 'Type:   Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
842         if grep -qv ' 9 st' /proc/devices 2>/dev/null; then
843                 if [ -n "$USEMODULES" ] ; then
844                         # Try to load the module. If it fails, ignore it...
845                         insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
846                 fi
847         fi
848 fi
849
850 # There could be a new kernel version. Remove old psdevtab database
851 rm -f /etc/psdevtab
852
853 if ! is_yes "$VSERVER"; then
854         # Now that we have all of our basic modules loaded and the kernel going,
855         # let's dump the syslog ring somewhere so we can find it later
856         dmesg -s 131072 > /var/log/dmesg
857         i=5
858         while [ $i -ge 0 ]; do
859                 if [ -f /var/log/dmesg.$i ]; then
860                         chmod 0600 /var/log/dmesg.$i
861                         mv -f /var/log/dmesg.$i /var/log/dmesg.$(($i+1))
862                 fi
863                 i=$(($i-1))
864         done
865         cp -f /var/log/dmesg /var/log/dmesg.0
866         chmod 0600 /var/log/dmesg /var/log/dmesg.0
867 fi
868
869 kill -TERM $(/sbin/pidof getkey) >/dev/null 2>&1
870 } &
871 if is_yes "$PROMPT"; then
872         /sbin/getkey i && touch /var/run/confirm
873 fi
874 wait
875 echo
876
877 # This must be last line !
878 # vi:syntax=sh
This page took 0.086921 seconds and 4 git commands to generate.