more init fixes
[hdw-linux/hdw-linux.git] / misc / sysfiles / etc / init.d / boot
1 #!/bin/sh
2 #
3 # hdw - linux /etc/init.d/boot (copied from ROCK Linux + modifications)
4 #
5 # lowlevel bootup script
6 #
7
8 exec 2>&1
9
10 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
11
12 echo "** booting hdw-linux... **"
13
14 . /etc/conf/bootdown
15 [ -f /fastboot ] && FASTBOOT=1 ; [ -f /forcefsck ] && FORCEFSCK=1
16 if [ $FORCEFSCK = 1 ] ; then echo "going to force fsck" ; FASTBOOT=0 ; fi
17 [ $FASTBOOT = 1 ] && echo "fast boot mode enabled"
18
19 mount -v -n /dev
20 mount -v -n /proc ; mount -v -n /sys
21 mkdir -p /dev/shm ; mount -v -n /dev/shm
22 mkdir -p /dev/pts ; mount -v -n /dev/pts
23
24 echo "loading kernel modules and configuring the kernel ..."
25 . /etc/conf/kernel
26
27 echo "populating device nodes ..."
28 /etc/init.d/udev start
29
30 if [ -f /etc/conf/devfs ] ; then
31         echo "configuring device nodes ..."
32         . /etc/conf/devfs
33 fi
34
35 echo "activating swap-devices ..."
36 swapon -a
37
38 if [ $FASTBOOT != 1 ]
39 then
40         echo "checking file systems (1/3) ..."
41         mount -n -o remount,ro /
42         if [ $FORCEFSCK = 1 ]
43         then fsck -A -C -a -f ; fsckrc=$? ; sync ; sleep 3
44         else fsck -A -C -a    ; fsckrc=$? ; sync ; sleep 3
45         fi
46         x=2
47         [ $fsckrc -eq 1 -a $EASYFSCK = 1 ] && fsckrc=0
48         while [ $fsckrc -eq 1 -a $x -lt 4 ]
49         do
50                 echo "filesystem check modified disks!"
51                 echo "checking file systems ($x/3) ..."
52                 fsck -A -C -a -f ; fsckrc=$? ; sync ; sleep 3
53                 if [ $x -eq 3 ] ; then x=4 ; else x=3 ; fi
54         done
55         if [ $fsckrc -eq 0 ]
56         then
57                 echo "all checked filesystems are clear."
58                 if [ $x != 2 ] ; then
59                         echo " **"
60                         echo " ** filesystem check modified disks."
61                         echo " **"
62                         echo " ** going to reboot the system."
63                         echo " **"
64                         for x in 10 9 8 7 6 5 4 3 2 ; do
65                                 echo -en "\rsystem reboot in $x seconds ... "
66                                 sleep 1
67                         done ; echo -e "\rsystem reboot now!                 "
68                         /sbin/reboot -d -f
69                         exit
70                 fi
71         else
72                 echo " **"
73                 echo " ** filesystem check failed (returncode=$fsckrc)."
74                 echo " ** please repair the broken disk(s) manually."
75                 echo " **"
76                 echo " ** note: The kernel parameter '-b' can be used to boot"
77                 echo " ** directly into a single-user login shell."
78                 echo " **"
79                 echo " ** going to reboot the system."
80                 echo " **"
81                 for x in 10 9 8 7 6 5 4 3 2 ; do
82                         echo -en "\rsystem reboot in $x seconds ... "
83                         sleep 1
84                 done ; echo -e "\rsystem reboot now!                 "
85                 /sbin/reboot -d -f
86                 exit
87         fi
88 fi
89
90 mount -v -n -o remount,rw /
91 grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
92 mount -v -a -t nocoda,nfs
93
94 if type hostname > /dev/null 2>&1
95 then
96         echo "set the hostname to [`cat /etc/HOSTNAME`] ..."
97         hostname `cat /etc/HOSTNAME`
98 else
99         echo "hostname not set: no 'hostname' command found"
100 fi
101
102 echo "refresh utmp, delete lock files and other stuff ..."
103 rm -f /var/lock/* /var/lock/*/* /var/run/* 2> /dev/null
104 touch /var/run/utmp ; chmod 664 /var/run/utmp ; chown root.tty /var/run/utmp
105 rm -f /etc/nologin /nologin /fastboot /forcefsck /fastdown
106
107 if [ "$TEMPCLEAN" = 1 ] ; then
108         echo "cleaning up /tmp ..."
109         for x in /tmp/* /tmp/.[!.]* ; do
110                 if [ -O "$x" ] ; then
111                         [ "$x" != "/tmp/lost+found" ] &&
112                         [ "$x" != "/tmp/quota.user" ] &&
113                         [ "$x" != "/tmp/quota.group" ] &&
114                         rm -rf -- "$x"
115                 else
116                         rm -rf -- "$x"
117                 fi
118         done
119 fi
120
121 if type klogd > /dev/null 2>&1
122 then
123         echo "writing /var/log/boot.msg ..."
124         klogd -f /var/log/boot.new -o
125         grep '.' < /var/log/boot.new > /var/log/boot.msg
126         rm /var/log/boot.new
127 else
128         echo "kernel boot messages are not logged: no 'klogd' command found."
129 fi
130
131 if type loadkeys > /dev/null 2>&1
132 then
133         echo "set the keyboard keymappings ..."
134         if [ -L /etc/default.keymap ] ; then
135                 oldpwd="`pwd`" ; cd /etc
136                 loadkeys `ls -l default.keymap | tr -s ' ' | cut -f11 -d' '`
137                 cd "$oldpwd" ; unset oldpwd
138         elif [ -f /etc/default.keymap ] ; then
139                 loadkeys /etc/default.keymap
140         else
141                 echo "no /etc/default.keymap found."
142         fi
143 else
144         echo "keymappings not configured: no 'loadkeys' command found."
145 fi
146
147 if type ifconfig > /dev/null 2>&1
148 then
149         echo "setting up loopback networking ..."
150         ifconfig lo 127.0.0.1 netmask 255.0.0.0 up
151         route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
152 fi
153
154 echo 'setting overflow UID and GID kernel parameters ...'
155 sysctl -w kernel.overflowuid=`id -u nobody` | tr -d '\n'
156 echo -n ', ' ; sysctl -w kernel.overflowgid=`id -g nobody`
157
158 echo "initializing kernel random number generator ..."
159 [ -f /var/state/random-seed ] && cat /var/state/random-seed >/dev/urandom
160 dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
161
162 # write EOT mark for btee
163 echo -ne '\004'