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