wok-4.x view busybox/stuff/init @ rev 6319
Added libproxy and libproxy-dev to build_depends. libproxy is also need to run subversion so its in depends too.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Fri Sep 17 04:44:53 2010 +0000 (2010-09-17) |
parents | 1e76f9aab153 |
children | a841d189e474 |
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 failed()
10 {
11 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
12 }
14 try_init()
15 {
16 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
17 modprobe dm-mod
18 modprobe dm-crypt
19 modprobe aes-i586
20 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
21 dev=${root#/dev/}
22 dmlabel=crypto-$dev
23 if cryptsetup isLuks $root 2> /dev/null; then
24 cryptsetup luksOpen $root $dmlabel
25 else
26 read -s -t 60 -p "Pass phrase : " passphrase
27 key=$(echo $passphrase | hashalot -x -n 32 sha512)
28 blocks=$(cat $(find /sys/block | grep /$dev/size))
29 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
30 dmsetup create $dmlabel
31 fi
32 mount /dev/mapper/$dmlabel /mnt
33 fi
34 if [ -d /mnt/etc ]; then
35 umount /sys
36 [ -n "$1" ] && for i in $@ ; do
37 cp -a $i /mnt$(dirname $i)
38 done
39 umount /proc
40 launch_init
41 fi
42 failed
43 }
45 mount_mapper()
46 {
47 mount $root /mnt
48 try_init /dev/mapper $@
49 }
51 lvmsetup()
52 {
53 if grep -q lvmroot= /proc/cmdline; then
54 modprobe dm-mod
55 vgscan --ignorelockingfailure
56 vgchange -ay --ignorelockingfailure
57 root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
58 return 0
59 fi
60 return 1
61 }
63 load_raid()
64 {
65 while read line; do
66 case "$line" in
67 *raid10*) modprobe raid10 ;;
68 *raid0*) modprobe raid0 ;;
69 *raid1*) modprobe raid1 ;;
70 *raid[456]*) modprobe raid456 ;;
71 esac
72 done
73 }
75 mount -t proc proc /proc
76 mount -t sysfs sysfs /sys
77 if grep -q dmraid= /proc/cmdline; then
78 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
79 echo -n "Switching / to dmraid $root..."
80 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
81 case "$root" in
82 /dev/*);;
83 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
84 esac
85 dmraid -ay
86 lvmsetup
87 mount_mapper
88 fi
89 if grep -q softraid= /proc/cmdline; then
90 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
91 echo -n "Switching / to softraid $root..."
92 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
93 grep level=raid /etc/mdadm.conf | load_raid
94 mdadm --assemble --scan
95 lvmsetup
96 mount_mapper /etc/mdadm.conf
97 fi
98 if lvmsetup; then
99 echo -n "Switching / to lvm $root..."
100 mount_mapper
101 fi
102 if grep -q loopfs= /proc/cmdline; then
103 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
104 dev=${loopfs%,*}
105 loopfs=${loopfs#*,}
106 echo -n "Switching / to loop $loopfs on $dev..."
107 if ! mount $dev /mnt; then
108 if echo $dev | grep -q "/dev/sd"; then
109 delay=`cat /sys/module/usb_storage/parameters/delay_use`
110 delay=$((1+$delay))
111 echo -n "sleep for $delay seconds..."
112 sleep $delay
113 fi
114 mount $dev /mnt || loopfs=""
115 fi
116 if [ -n "$loopfs" ]; then
117 losetup /dev/loop0 /mnt/$loopfs
118 mount /dev/loop0 /mnt 2> /dev/null
119 fi
120 try_init
121 fi
122 grep -q cryptoroot= /proc/cmdline && try_init
123 umount /sys
124 echo -n "Switching / to tmpfs..."
125 size="$(grep rootfssize= < /proc/cmdline | \
126 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
127 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
128 umount /proc
129 [ -n "$size" ] || size="-o size=90%"
130 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
131 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
132 exec /sbin/init
133 fi
134 for i in $(ls -a /); do
135 case "$i" in
136 .|..) ;;
137 mnt) mkdir /mnt/mnt;;
138 *) if ! cp -a /$i /mnt 2> /dev/null; then
139 failed
140 umount /mnt
141 exec /sbin/init
142 fi;;
143 esac
144 done
145 launch_init