wok-current diff busybox/stuff/init @ rev 5657
Up: libogg (1.2.0)
author | Alexander Medvedev <devl547@gmail.com> |
---|---|
date | Sun May 30 02:45:16 2010 +0000 (2010-05-30) |
parents | ed4e00c9b798 |
children | 1e76f9aab153 |
line diff
1.1 --- a/busybox/stuff/init Mon Nov 09 17:17:30 2009 +0100 1.2 +++ b/busybox/stuff/init Sun May 30 02:45:16 2010 +0000 1.3 @@ -1,18 +1,46 @@ 1.4 #!/bin/sh 1.5 1.6 +launch_init() 1.7 +{ 1.8 + echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]" 1.9 + exec /sbin/switch_root mnt /sbin/init 1.10 +} 1.11 + 1.12 +try_init() 1.13 +{ 1.14 + if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then 1.15 + modprobe dm-mod 1.16 + modprobe dm-crypt 1.17 + modprobe aes-i586 1.18 + root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)" 1.19 + dev=${root#/dev/} 1.20 + dmlabel=crypto-$dev 1.21 + if cryptsetup isLuks $root 2> /dev/null; then 1.22 + cryptsetup luksOpen $root $dmlabel 1.23 + else 1.24 + read -s -t 60 -p "Pass phrase : " passphrase 1.25 + key=$(echo $passphrase | hashalot -x -n 32 sha512) 1.26 + blocks=$(cat $(find /sys/block | grep /$dev/size)) 1.27 + echo 0 $blocks crypt aes-plain $key 0 $root 0 | \ 1.28 + dmsetup create $dmlabel 1.29 + fi 1.30 + mount /dev/mapper/$dmlabel /mnt 1.31 + fi 1.32 + if [ -d /mnt/etc ]; then 1.33 + umount /sys 1.34 + [ -n "$1" ] && for i in $@ ; do 1.35 + cp -a $i /mnt$i 1.36 + done 1.37 + umount /proc 1.38 + launch_init 1.39 + fi 1.40 + echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]" 1.41 +} 1.42 + 1.43 mount_mapper() 1.44 { 1.45 mount $root /mnt 1.46 - if [ -d /mnt/etc ]; then 1.47 - umount /sys 1.48 - for i in /dev/mapper $@ ; do 1.49 - cp -a $i /mnt$i 1.50 - done 1.51 - umount /proc 1.52 - echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]" 1.53 - exec /sbin/switch_root mnt /sbin/init 1.54 - fi 1.55 - echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]" 1.56 + try_init /dev/mapper $@ 1.57 } 1.58 1.59 mount -t proc proc /proc 1.60 @@ -32,7 +60,8 @@ 1.61 esac 1.62 dmraid -ay 1.63 mount_mapper 1.64 -elif grep -q softraid= /proc/cmdline; then 1.65 +fi 1.66 +if grep -q softraid= /proc/cmdline; then 1.67 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)" 1.68 echo -n "Switching / to softraid $root..." 1.69 mdadm --examine --scan --config=partitions > /etc/mdadm.conf 1.70 @@ -45,6 +74,27 @@ 1.71 mdadm --assemble --scan 1.72 mount_mapper /etc/mdadm.conf 1.73 fi 1.74 +if grep -q loopfs= /proc/cmdline; then 1.75 + loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)" 1.76 + dev=${loopfs%,*} 1.77 + loopfs=${loopfs#*,} 1.78 + echo -n "Switching / to loop $loopfs on $dev..." 1.79 + if ! mount $dev /mnt; then 1.80 + if echo $dev | grep -q "/dev/sd"; then 1.81 + delay=`cat /sys/module/usb_storage/parameters/delay_use` 1.82 + delay=$((1+$delay)) 1.83 + echo -n "sleep for $delay seconds..." 1.84 + sleep $delay 1.85 + fi 1.86 + mount $dev /mnt || loopfs="" 1.87 + fi 1.88 + if [ -n "$loopfs" ]; then 1.89 + losetup /dev/loop0 /mnt/$loopfs 1.90 + mount /dev/loop0 /mnt 2> /dev/null 1.91 + fi 1.92 + try_init 1.93 +fi 1.94 +grep -q cryptoroot= /proc/cmdline && try_init 1.95 umount /sys 1.96 echo -n "Switching / to tmpfs..." 1.97 size="$(grep rootfssize= < /proc/cmdline | \ 1.98 @@ -67,5 +117,4 @@ 1.99 fi;; 1.100 esac 1.101 done 1.102 -echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]" 1.103 -exec /sbin/switch_root mnt /sbin/init 1.104 +launch_init