wok-stable view busybox/stuff/init @ rev 5052
fix typos: add scanner group
author | Rohit Joshi <jozee@slitaz.org> |
---|---|
date | Sat Mar 06 18:48:28 2010 +0000 (2010-03-06) |
parents | ed4e00c9b798 |
children | 1e76f9aab153 |
line source
1 #!/bin/sh
3 launch_init()
4 {
5 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
6 exec /sbin/switch_root mnt /sbin/init
7 }
9 try_init()
10 {
11 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
12 modprobe dm-mod
13 modprobe dm-crypt
14 modprobe aes-i586
15 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
16 dev=${root#/dev/}
17 dmlabel=crypto-$dev
18 if cryptsetup isLuks $root 2> /dev/null; then
19 cryptsetup luksOpen $root $dmlabel
20 else
21 read -s -t 60 -p "Pass phrase : " passphrase
22 key=$(echo $passphrase | hashalot -x -n 32 sha512)
23 blocks=$(cat $(find /sys/block | grep /$dev/size))
24 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
25 dmsetup create $dmlabel
26 fi
27 mount /dev/mapper/$dmlabel /mnt
28 fi
29 if [ -d /mnt/etc ]; then
30 umount /sys
31 [ -n "$1" ] && for i in $@ ; do
32 cp -a $i /mnt$i
33 done
34 umount /proc
35 launch_init
36 fi
37 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
38 }
40 mount_mapper()
41 {
42 mount $root /mnt
43 try_init /dev/mapper $@
44 }
46 mount -t proc proc /proc
47 mount -t sysfs sysfs /sys
48 if grep -q dmraid= /proc/cmdline; then
49 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
50 echo -n "Switching / to dmraid $root..."
51 case "$(dmraid -s | grep ^type | awk '{ print $3 }')" in
52 mirror) modprobe dm-mirror;;
53 raid[456]*) modprobe raid456;;
54 esac
55 name=$(dmraid -s | grep ^name | awk '{ print $3 }')
56 case "$root" in
57 /dev/*);;
58 p*) root=/dev/mapper/${name}$root ;;
59 *) root=/dev/mapper/${name}p$root ;;
60 esac
61 dmraid -ay
62 mount_mapper
63 fi
64 if grep -q softraid= /proc/cmdline; then
65 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
66 echo -n "Switching / to softraid $root..."
67 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
68 grep level=raid /etc/mdadm.conf | while read line; do
69 case "$line" in
70 *=raid1\ *) modprobe dm-mirror ;;
71 *=raid[456]\ *) modprobe raid456 ;;
72 esac
73 done
74 mdadm --assemble --scan
75 mount_mapper /etc/mdadm.conf
76 fi
77 if grep -q loopfs= /proc/cmdline; then
78 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
79 dev=${loopfs%,*}
80 loopfs=${loopfs#*,}
81 echo -n "Switching / to loop $loopfs on $dev..."
82 if ! mount $dev /mnt; then
83 if echo $dev | grep -q "/dev/sd"; then
84 delay=`cat /sys/module/usb_storage/parameters/delay_use`
85 delay=$((1+$delay))
86 echo -n "sleep for $delay seconds..."
87 sleep $delay
88 fi
89 mount $dev /mnt || loopfs=""
90 fi
91 if [ -n "$loopfs" ]; then
92 losetup /dev/loop0 /mnt/$loopfs
93 mount /dev/loop0 /mnt 2> /dev/null
94 fi
95 try_init
96 fi
97 grep -q cryptoroot= /proc/cmdline && try_init
98 umount /sys
99 echo -n "Switching / to tmpfs..."
100 size="$(grep rootfssize= < /proc/cmdline | \
101 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
102 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
103 umount /proc
104 [ -n "$size" ] || size="-o size=90%"
105 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
106 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
107 exec /sbin/init
108 fi
109 for i in $(ls -a /); do
110 case "$i" in
111 .|..) ;;
112 mnt) mkdir /mnt/mnt;;
113 *) if ! cp -a /$i /mnt 2> /dev/null; then
114 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
115 umount /mnt
116 exec /sbin/init
117 fi;;
118 esac
119 done
120 launch_init