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