updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / quick-boot / qinit.sysinit
blob5a93b88f8a4dc0ec45f5921490e635a2c41ac562
1 #!/bin/bash
3 # /etc/rc.sysinit
9 . /etc/rc.conf
10 . /etc/rc.d/functions
12 echo " "
13 printhl "Arch Linux\n"
14 printhl "${C_H2}http://www.archlinux.org"
15 printhl "Copyright 2002-2007 Judd Vinet"
16 printhl "Copyright 2007-2009 Aaron Griffin"
17 printhl "Distributed under the GNU General Public License (GPL)"
18 printsep
20 # mount /proc, /sys and our RAM /dev
21 /bin/mount -n -t tmpfs none /dev -o mode=0755
22 /bin/mount -n -t proc none /proc
23 /bin/mount -n -t sysfs none /sys
25 # Copy static device nodes to /dev
26 /bin/cp -a /lib/udev/devices/* /dev/
30 ./etc/qinit.mknod_blocks
34 # Default nodes
35 /bin/mknod -m 666 /dev/random c 1 8
36 /bin/mknod -m 666 /dev/urandom c 1 9
37 /bin/mknod /dev/full c 1 7
38 /bin/mknod -m 640 /dev/kmem c 1 2
39 /bin/mknod -m 755 /dev/ptmx c 5 2
41 /bin/mknod -m 666 /dev/tty c 5 0
42 /bin/mknod -m 620 /dev/tty0 c 4 0
43 /bin/mknod -m 620 /dev/tty1 c 4 1
44 /bin/mknod -m 620 /dev/tty2 c 4 2
45 /bin/mknod -m 620 /dev/tty3 c 4 3
46 /bin/mknod -m 620 /dev/tty4 c 4 4
47 /bin/mknod -m 620 /dev/tty5 c 4 5
48 /bin/mknod -m 620 /dev/tty6 c 4 6
49 /bin/mknod -m 620 /dev/tty7 c 4 7
51 /bin/mknod -m 660 /dev/vcs c 7 0
52 /bin/mknod -m 660 /dev/vcs1 c 7 1
53 /bin/mknod -m 660 /dev/vcs2 c 7 2
54 /bin/mknod -m 660 /dev/vcs3 c 7 3
55 /bin/mknod -m 660 /dev/vcs4 c 7 4
56 /bin/mknod -m 660 /dev/vcs5 c 7 5
57 /bin/mknod -m 660 /dev/vcs6 c 7 6
58 /bin/mknod -m 660 /dev/vcs7 c 7 7
60 /bin/mknod -m 660 /dev/vcsa c 7 128
61 /bin/mknod -m 660 /dev/vcsa1 c 7 129
62 /bin/mknod -m 660 /dev/vcsa2 c 7 130
63 /bin/mknod -m 660 /dev/vcsa3 c 7 131
64 /bin/mknod -m 660 /dev/vcsa4 c 7 132
65 /bin/mknod -m 660 /dev/vcsa5 c 7 133
66 /bin/mknod -m 660 /dev/vcsa6 c 7 134
67 /bin/mknod -m 660 /dev/vcsa7 c 7 135
69 /bin/mknod -m 640 /dev/mem c 1 1
72 #ATI
73 /bin/mkdir -m 755 /dev/dri
74 /bin/mknod -m 666 /dev/dri/card0 c 226 0
75 #INTEL
76 /bin/mkdir -p /dev/misc
77 /bin/mknod -m 600 /dev/misc/agpgart c 10 175
78 /bin/ln -sfn /dev/misc/agpgart /dev/agpgart
79 #NVIDIA
80 /bin/mknod -m 666 /dev/nvidia0 c 195 0
81 /bin/mknod -m 666 /dev/nvidiactl c 195 255
84 # start up our mini logger until syslog takes over
85 /sbin/minilogd
88 # Start readahead
89 if [ -e /.readahead ]; then
90 stat_busy "Starting readahead-collector - collecting data"
91 /sbin/readahead-collector
92 stat_done
93 else
94 stat_busy "Starting readahead - early read"
95 /sbin/readahead /etc/readahead.d/*.early
96 stat_done
100 # anything more serious than KERN_WARNING goes to the console
101 # 'verbose' cmdline parameter enables more messages
102 if /bin/grep -q " verbose" /proc/cmdline; then
103 /bin/dmesg -n 8
104 else
105 /bin/dmesg -n 3
108 # enable rtc access
109 /sbin/modprobe rtc-cmos >/dev/null 2>&1
110 RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null)
111 RTC_MAJOR="${RTC_MAJOR%% *}"
112 if [ -n "$RTC_MAJOR" ]; then
113 /bin/mknod /dev/rtc0 c $RTC_MAJOR 0
114 /bin/ln -s /dev/rtc0 /dev/rtc
117 HWCLOCK_PARAMS="--hctosys"
118 if [ "$HARDWARECLOCK" = "UTC" ]; then
119 HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
120 elif [ "$HARDWARECLOCK" = "localtime" ]; then
121 HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
122 else
123 HWCLOCK_PARAMS=""
126 # Set clock early to fix some bugs with filesystem checks
127 # Clock is set again later to match rc.conf
128 if [ -n "$HWCLOCK_PARAMS" -a -f /etc/localtime ]; then
129 /sbin/hwclock $HWCLOCK_PARAMS --noadjfile
132 echo > /proc/sys/kernel/hotplug
134 # Load modules from the MODULES array defined in rc.conf
135 if ! [ "$load_modules" = "off" ]; then
136 if [ -f /proc/modules ]; then
137 stat_busy "Loading Modules"
138 for mod in "${MODULES[@]}"; do
139 if [ "$mod" = "${mod#!}" ]; then
140 /sbin/modprobe $mod
142 done
143 stat_done
145 if [ -d /proc/acpi ]; then
146 stat_busy "Loading standard ACPI modules"
147 ACPI_MODULES="ac battery button fan processor thermal"
148 k="$(echo $BLACKLIST ${MOD_BLACKLIST[@]} | /bin/sed 's|-|_|g')"
149 j="$(echo ${MODULES[@]} | /bin/sed 's|-|_|g')"
150 #add disabled MODULES (!) to blacklist - much requested feature
151 for m in ${j}; do
152 [ "$m" != "${m#!}" ] && k="${k} ${m#!}"
153 done
154 # add disablemodules= from commandline to blacklist
155 k="${k} $(echo ${disablemodules} | /bin/sed 's|-|_|g' | /bin/sed 's|,| |g')"
156 for n in ${ACPI_MODULES}; do
157 if ! echo ${k} | /bin/grep "\<$n\>" 2>&1 >/dev/null; then
158 /sbin/modprobe $n > /dev/null 2>&1
160 done
161 stat_done
166 # bring up the loopback interface
167 if [ -d /sys/class/net/lo ]; then
168 stat_busy "Bringing up loopback interface"
169 /sbin/ifconfig lo 127.0.0.1 up
170 if [ $? -ne 0 ]; then
171 stat_fail
172 else
173 stat_done
177 # If necessary, find md devices and manually assemble RAID arrays
178 if [ -f /etc/mdadm.conf -a "$(/bin/grep ^ARRAY /etc/mdadm.conf 2>/dev/null)" ]; then
179 # udev won't create these md nodes, so we do it ourselves
180 for dev in $(/bin/grep ^ARRAY /etc/mdadm.conf | /bin/awk '{print $2}'); do
181 path=$(echo $dev | /bin/sed 's|/[^/]*$||')
182 node=$(echo $dev | /bin/sed "s|^$path/||")
183 minor=$(echo $node | /bin/sed 's|^[^0-9]*||')
184 [ ! -e $path/$node ] && /bin/mknod $path/$node b 9 $minor
185 done
186 status "Activating RAID arrays" /sbin/mdadm --assemble --scan
189 if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
190 if [ -x /sbin/lvm -a -d /sys/block ]; then
191 # Kernel 2.6.x, LVM2 groups
192 /sbin/modprobe -q dm-mod 2>/dev/null
193 stat_busy "Activating LVM2 groups"
194 /sbin/lvm vgscan --ignorelockingfailure --mknodes >/dev/null
195 /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null
196 if [ $? -ne 0 ]; then
197 stat_fail
198 else
199 stat_done
204 # Set up non-root encrypted partition mappings
205 if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then
206 /sbin/modprobe -q dm-mod 2>/dev/null
207 stat_busy "Unlocking encrypted volumes:"
208 csfailed=0
209 CS=/sbin/cryptsetup.static
210 do_crypt() {
211 if [ $# -ge 3 ]; then
212 cname="$1"
213 csrc="$2"
214 cpass="$3"
215 shift 3
216 copts="$*"
217 stat_append "${cname}.."
218 # For some fun reason, the parameter ordering varies for
219 # LUKS and non-LUKS devices. Joy.
220 if [ "${cpass}" = "SWAP" ]; then
221 # This is DANGEROUS! The only possible safety check
222 # is to not proceed in case we find a LUKS device
223 # This may cause dataloss if it is not used carefully
224 if $CS isLuks $csrc 2>/dev/null; then
225 false
226 else
227 $CS -d /dev/urandom $copts create $cname $csrc >/dev/null
228 if [ $? -eq 0 ]; then
229 stat_append "creating swapspace.."
230 /sbin/mkswap -f -L $cname /dev/mapper/$cname >/dev/null
233 elif [ "${cpass}" = "ASK" ]; then
234 printf "\nOpening '${cname}' volume:\n"
236 if $CS isLuks $csrc 2>/dev/null; then
237 $CS $copts luksOpen $csrc $cname < /dev/console
238 else
239 $CS $copts create $cname $csrc < /dev/console
241 elif [ "${cpass:0:1}" != "/" ]; then
242 if $CS isLuks $csrc 2>/dev/null; then
243 echo "$cpass" | $CS $copts luksOpen $csrc $cname >/dev/null
244 else
245 echo "$cpass" | $CS $copts create $cname $csrc >/dev/null
247 else
248 if $CS isLuks $csrc 2>/dev/null; then
249 $CS -d $cpass $copts luksOpen $csrc $cname >/dev/null
250 else
251 $CS -d $cpass $copts create $cname $csrc >/dev/null
254 if [ $? -ne 0 ]; then
255 csfailed=1
256 stat_append "failed "
257 else
258 stat_append "ok "
262 while read line; do
263 eval do_crypt "$line"
264 done </etc/crypttab
265 if [ $csfailed -eq 0 ]; then
266 stat_done
267 else
268 stat_fail
270 # Maybe someone has LVM on an encrypted block device
271 if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
272 if [ -x /sbin/lvm -a -d /sys/block ]; then
273 /sbin/lvm vgscan --ignorelockingfailure --mknodes >/dev/null
274 /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null
279 status "Mounting Root Read-only" /bin/mount -n -o remount,ro /
281 FORCEFSCK=
282 [ -f /forcefsck ] && FORCEFSCK="-- -f"
283 NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs"
285 fsck_reboot() {
286 echo "Automatic reboot in progress..."
287 /bin/umount -a
288 /bin/mount -n -o remount,ro /
289 /sbin/reboot -f
290 exit 0
293 if [ -x /sbin/fsck ]; then
294 stat_busy "Checking Filesystems"
295 FSCK_OUT=/dev/stdout
296 FSCK_ERR=/dev/null
297 /sbin/fsck -A -T -C -a -t $NETFS $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR
298 fsckret=$?
299 if [ ${fsckret} -gt 1 ]; then
300 stat_fail
302 if [ $((${fsckret}&2)) -eq 2 ]; then
303 echo
304 echo "********************** REBOOT REQUIRED *********************"
305 echo "* *"
306 echo "* The system will be rebooted automatically in 15 seconds. *"
307 echo "* *"
308 echo "************************************************************"
309 echo
310 /bin/sleep 15
311 fsck_reboot
313 if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then
314 echo
315 echo "***************** FILESYSTEM CHECK FAILED ****************"
316 echo "* *"
317 echo "* Please repair manually and reboot. Note that the root *"
318 echo "* file system is currently mounted read-only. To remount *"
319 echo "* it read-write type: mount -n -o remount,rw / *"
320 echo "* When you exit the maintenance shell the system will *"
321 echo "* reboot automatically. *"
322 echo "* *"
323 echo "************************************************************"
324 echo
325 /sbin/sulogin -p
326 fsck_reboot
328 stat_done
331 stat_busy "Mounting Local Filesystems"
332 /bin/mount -n -o remount,rw /
333 /bin/rm -f /etc/mtab*
334 # make sure / gets written to /etc/mtab
335 /bin/mount -o remount,rw /
336 # Write /proc, /sys and /dev to /etc/mtab
337 if [ -e /proc/mounts ]; then
338 /bin/grep -e "/proc " -e "/sys " -e "/dev " /proc/mounts >> /etc/mtab
340 # now mount all the local filesystems
341 /bin/mount -a -t $NETFS -O no_netdev
342 stat_done
344 stat_busy "Removing Leftover Files"
345 /bin/rm -f /etc/nologin &>/dev/null
346 /bin/rm -f /etc/shutdownpid &>/dev/null
347 /bin/rm -f /var/lock/* &>/dev/null
348 /bin/rm -rf /tmp/* /tmp/.* &>/dev/null
349 /bin/rm -f /forcefsck &>/dev/null
350 (cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; )
351 : > /var/run/utmp
352 /bin/chmod 0664 /var/run/utmp
353 # Keep {x,k,g}dm happy with xorg
354 /bin/mkdir /tmp/.ICE-unix && /bin/chmod 1777 /tmp/.ICE-unix
355 /bin/mkdir /tmp/.X11-unix && /bin/chmod 1777 /tmp/.X11-unix
356 stat_done
358 #status "Updating Shared Library Links" /sbin/ldconfig
360 if [ "$HOSTNAME" != "" ]; then
361 status "Setting Hostname: $HOSTNAME" /bin/hostname $HOSTNAME
365 #status "Updating Module Dependencies" /sbin/depmod -A
367 # Flush old locale settings
368 #: >/etc/profile.d/locale.sh
369 #/bin/chmod 755 /etc/profile.d/locale.sh
370 # Set user defined locale
371 #[ -z "$LOCALE" ] && LOCALE="en_US"
372 #stat_busy "Setting Locale: $LOCALE"
373 #echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh
374 #stat_done
376 #if echo "$LOCALE" | /bin/grep -qi utf ; then
377 # stat_busy "Setting Consoles to UTF-8 mode"
378 # # UTF-8 consoles are default since 2.6.24 kernel
379 # # this code is needed not only for older kernels,
380 # # but also when user has set vt.default_utf8=0 but LOCALE is *.UTF-8.
381 # for i in /dev/tty[0-9]*; do
382 # /usr/bin/kbd_mode -u < ${i}
383 # printf "\e%%G" > ${i}
384 # done
385 # # the $CONSOLE check helps us avoid this when running scripts from cron
386 # echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\e%%G"; fi' >>/etc/profile.d/locale.sh
387 # stat_done
388 # [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u $KEYMAP
389 #else
390 # stat_busy "Setting Consoles to legacy mode"
391 # # make non-UTF-8 consoles work on 2.6.24 and newer kernels
392 # for i in /dev/tty[0-9]*; do
393 # /usr/bin/kbd_mode -a < ${i}
394 # printf "\e%%@" > ${i}
395 # done
396 # # the $CONSOLE check helps us avoid this when running scripts from cron
397 # echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\e%%@"; fi' >>/etc/profile.d/locale.sh
398 # stat_done
399 # [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP
402 #if [ -n "$CONSOLEFONT" ]; then
403 # stat_busy "Loading Console Font: $CONSOLEFONT"
404 # #CONSOLEMAP in UTF-8 shouldn't be used
405 # if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then
406 # CONSOLEMAP=""
407 # fi
408 # for i in /dev/tty[0-9]*; do
409 # if [ -n "$CONSOLEMAP" ]; then
410 # /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} >/dev/null 2>&1
411 # else
412 # /usr/bin/setfont $CONSOLEFONT -C ${i} >/dev/null 2>&1
413 # fi
414 # done
415 # if [ $? -ne 0 ]; then
416 # stat_fail
417 # else
418 # for i in /dev/tty[0-9]*; do
419 # printf "\e(K" > ${i}
420 # done
421 # # the $CONSOLE check helps us avoid this when running scripts from cron
422 # echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\e(K"; fi' >>/etc/profile.d/locale.sh
423 # stat_done
424 # fi
427 # Setting console lang
428 /bin/loadkeys -q $KEYMAP
433 # Starting Xorg
434 if [ -x /etc/rc.local ]; then
435 /etc/rc.local &
438 # End of file
439 # vim: set ts=2 noet: