wok view busybox/stuff/init @ rev 10722
usbutils: fix usb.ids path (see BUGS in receipt)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun May 29 00:27:29 2011 +0200 (2011-05-29) |
parents | ed659050472b |
children | cf6c2a7bde09 |
line source
1 #!/bin/sh
3 launch_init()
4 {
5 [ -d /proc/sys ] && umount /proc
6 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
7 exec /sbin/switch_root mnt /sbin/init
8 }
10 failed()
11 {
12 umount /proc
13 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
14 conspy -d 1 > /init.log
15 }
17 try_init()
18 {
19 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
20 modprobe dm-mod
21 modprobe dm-crypt
22 modprobe aes-i586
23 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
24 dev=${root#/dev/}
25 dmlabel=crypto-$dev
26 if cryptsetup isLuks $root 2> /dev/null; then
27 cryptsetup luksOpen $root $dmlabel
28 else
29 read -s -t 60 -p "Pass phrase : " passphrase
30 key=$(echo $passphrase | hashalot -x -n 32 sha512)
31 blocks=$(cat $(find /sys/block | grep /$dev/size))
32 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
33 dmsetup create $dmlabel
34 fi
35 mount /dev/mapper/$dmlabel /mnt
36 fi
37 if [ -d /mnt/etc ]; then
38 umount /sys
39 [ -n "$1" ] && for i in $@ ; do
40 cp -a $i /mnt$(dirname $i)
41 done
42 mount /mnt -o remount,ro
43 launch_init
44 fi
45 failed
46 }
48 mount_mapper()
49 {
50 mount $root /mnt
51 try_init /dev/mapper $@
52 }
54 lvmsetup()
55 {
56 grep -q lvmroot= /proc/cmdline || return 1
57 modprobe dm-mod
58 vgscan --ignorelockingfailure
59 vgchange -ay --ignorelockingfailure
60 root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
61 return 0
62 }
64 load_raid()
65 {
66 while read line; do
67 case "$line" in
68 *raid10*) modprobe raid10 ;;
69 *raid0*) modprobe raid0 ;;
70 *raid1*) modprobe raid1 ;;
71 *raid[456]*) modprobe raid456 ;;
72 esac
73 done
74 }
76 mount -t proc proc /proc
77 mount -t sysfs sysfs /sys
78 if grep -q dmraid= /proc/cmdline; then
79 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
80 echo -n "Switching / to dmraid $root..."
81 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
82 case "$root" in
83 /dev/*);;
84 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
85 esac
86 dmraid -ay
87 lvmsetup
88 mount_mapper
89 fi
90 if grep -q softraid= /proc/cmdline; then
91 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
92 echo -n "Switching / to softraid $root..."
93 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
94 grep -qs " $root " /etc/mdadm.conf ||
95 root=$(awk '/dev.md/ { print $2; exit }' < /etc/mdadm.conf)
96 grep level=raid /etc/mdadm.conf | load_raid
97 mdadm --assemble --scan
98 lvmsetup
99 mount_mapper /etc/mdadm.conf
100 fi
101 if lvmsetup; then
102 echo -n "Switching / to lvm $root..."
103 mount_mapper
104 fi
105 if grep -q mount= /proc/cmdline; then
106 root="$(sed 's/.*mount=\([^ ]*\).*/\1/' < /proc/cmdline)"
107 dev=$(blkid | grep $root | sed 's/:.*//;q')
108 echo -n "Mounting $dev ($root) ..."
109 if ! mount $dev /mnt; then
110 if echo $dev | grep -q "/dev/sd"; then
111 delay=`cat /sys/module/usb_storage/parameters/delay_use`
112 delay=$((1+$delay))
113 echo -n "sleep for $delay seconds..."
114 sleep $delay
115 fi
116 mount $dev /mnt
117 fi
118 fi
119 if grep -q loopfs= /proc/cmdline; then
120 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
121 echo -n "Switching / to loop $loopfs..."
122 losetup /dev/loop0 /mnt/$loopfs
123 mount /dev/loop0 /mnt 2> /dev/null
124 fi
125 grep -q cryptoroot= /proc/cmdline && try_init
126 umount /sys
127 if grep -q subroot= /proc/cmdline; then
128 subroot="/$(sed 's/.*subroot=\([^ ]*\).*/\1/' < /proc/cmdline)" &&
129 if [ -s /usr/share/boot/busybox-static ]; then
130 mv /usr/share/boot/busybox-static .
131 /busybox-static rm -rf /etc /lib /*bin /usr /var
132 exec /busybox-static chroot /mnt$subroot /sbin/init
133 else
134 exec chroot /mnt$subroot /sbin/init
135 fi
136 fi
137 echo -n "Switching / to tmpfs..."
138 size="$(grep rootfssize= < /proc/cmdline | \
139 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
140 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
141 umount /proc
142 [ -n "$size" ] || size="-o size=90%"
143 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
144 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
145 exec /sbin/init
146 fi
147 for i in $(ls -a /); do
148 case "$i" in
149 .|..) ;;
150 mnt) mkdir /mnt/mnt;;
151 *) if ! cp -a /$i /mnt 2> /dev/null; then
152 failed
153 umount /mnt
154 exec /sbin/init
155 fi;;
156 esac
157 done
158 launch_init