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