wok annotate busybox/stuff/init @ rev 11010
Up: getmail to 4.22.1.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Thu Oct 13 03:18:30 2011 +0000 (2011-10-13) |
parents | 3ef65672ad0a |
children |
rev | line source |
---|---|
pascal@1703 | 1 #!/bin/sh |
pascal@1703 | 2 |
pascal@4545 | 3 launch_init() |
pascal@4545 | 4 { |
pascal@8401 | 5 [ -d /proc/sys ] && umount /proc |
pascal@10769 | 6 echo -e "\\033[70G[ \\033[1;32mOK\\033[0;39m ]" |
pascal@7850 | 7 exec /sbin/switch_root mnt /sbin/init |
pascal@4545 | 8 } |
pascal@4545 | 9 |
pascal@5978 | 10 failed() |
pascal@5978 | 11 { |
pascal@7844 | 12 umount /proc |
pascal@5978 | 13 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]" |
pascal@8147 | 14 conspy -d 1 > /init.log |
pascal@5978 | 15 } |
pascal@5978 | 16 |
pascal@4545 | 17 try_init() |
pascal@4545 | 18 { |
pascal@7850 | 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@7850 | 37 if [ -d /mnt/etc ]; then |
pascal@4545 | 38 umount /sys |
pascal@4545 | 39 [ -n "$1" ] && for i in $@ ; do |
pascal@7850 | 40 cp -a $i /mnt$(dirname $i) |
pascal@4545 | 41 done |
pascal@7844 | 42 mount /mnt -o remount,ro |
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@8066 | 56 grep -q lvmroot= /proc/cmdline || return 1 |
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 } |
pascal@5978 | 63 |
pascal@5978 | 64 load_raid() |
pascal@5978 | 65 { |
pascal@5978 | 66 while read line; do |
pascal@5978 | 67 case "$line" in |
pascal@5983 | 68 *raid10*) modprobe raid10 ;; |
pascal@5983 | 69 *raid0*) modprobe raid0 ;; |
pascal@5983 | 70 *raid1*) modprobe raid1 ;; |
pascal@5978 | 71 *raid[456]*) modprobe raid456 ;; |
pascal@5978 | 72 esac |
pascal@5978 | 73 done |
pascal@5978 | 74 } |
pascal@5978 | 75 |
pascal@4469 | 76 mount -t proc proc /proc |
pascal@4469 | 77 mount -t sysfs sysfs /sys |
pascal@10901 | 78 echo -n "Switching / to " |
pascal@4469 | 79 if grep -q dmraid= /proc/cmdline; then |
pascal@4469 | 80 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)" |
pascal@10901 | 81 echo -n "dmraid $root..." |
pascal@5978 | 82 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid |
pascal@4469 | 83 case "$root" in |
pascal@4469 | 84 /dev/*);; |
pascal@5978 | 85 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};; |
pascal@4469 | 86 esac |
pascal@4469 | 87 dmraid -ay |
pascal@5978 | 88 lvmsetup |
pascal@4469 | 89 mount_mapper |
pascal@4545 | 90 fi |
pascal@4545 | 91 if grep -q softraid= /proc/cmdline; then |
pascal@4469 | 92 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)" |
pascal@10901 | 93 echo -n "softraid $root..." |
pascal@4469 | 94 mdadm --examine --scan --config=partitions > /etc/mdadm.conf |
pascal@6674 | 95 grep -qs " $root " /etc/mdadm.conf || |
pascal@6674 | 96 root=$(awk '/dev.md/ { print $2; exit }' < /etc/mdadm.conf) |
pascal@5978 | 97 grep level=raid /etc/mdadm.conf | load_raid |
pascal@10901 | 98 for i in 1 2 3 4 5 6 7 8 9; do |
pascal@10901 | 99 sleep $i |
pascal@10901 | 100 mdadm --assemble --scan |
pascal@10901 | 101 grep -qs ': active' /proc/mdstat && break |
pascal@10901 | 102 done |
pascal@5978 | 103 lvmsetup |
pascal@4469 | 104 mount_mapper /etc/mdadm.conf |
pascal@4469 | 105 fi |
pascal@5978 | 106 if lvmsetup; then |
pascal@10901 | 107 echo -n "lvm $root..." |
pascal@5978 | 108 mount_mapper |
pascal@5978 | 109 fi |
pascal@7844 | 110 if grep -q mount= /proc/cmdline; then |
pascal@7844 | 111 root="$(sed 's/.*mount=\([^ ]*\).*/\1/' < /proc/cmdline)" |
pascal@7844 | 112 dev=$(blkid | grep $root | sed 's/:.*//;q') |
pascal@7844 | 113 echo -n "Mounting $dev ($root) ..." |
pascal@4545 | 114 if ! mount $dev /mnt; then |
pascal@4545 | 115 if echo $dev | grep -q "/dev/sd"; then |
pascal@4545 | 116 delay=`cat /sys/module/usb_storage/parameters/delay_use` |
pascal@4545 | 117 delay=$((1+$delay)) |
pascal@4545 | 118 echo -n "sleep for $delay seconds..." |
pascal@4545 | 119 sleep $delay |
pascal@4545 | 120 fi |
pascal@7844 | 121 mount $dev /mnt |
pascal@4545 | 122 fi |
pascal@10916 | 123 grep -q posixovl /proc/cmdline && mount.posixovl /mnt |
pascal@7844 | 124 fi |
pascal@7844 | 125 if grep -q loopfs= /proc/cmdline; then |
pascal@7844 | 126 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)" |
pascal@10901 | 127 echo -n "loop $loopfs..." |
pascal@7844 | 128 losetup /dev/loop0 /mnt/$loopfs |
pascal@7844 | 129 mount /dev/loop0 /mnt 2> /dev/null |
pascal@4545 | 130 fi |
pascal@10916 | 131 if grep -q bindfs= /proc/cmdline; then |
pascal@10916 | 132 bind="$(sed 's/.*bindfs=\([^ ]*\).*/\1/' < /proc/cmdline)" |
pascal@10916 | 133 mount --bind /mnt/${bind%,*} /mnt/${bind%,*}/${bind#*,} |
pascal@10916 | 134 fi |
pascal@4545 | 135 grep -q cryptoroot= /proc/cmdline && try_init |
pascal@7845 | 136 umount /sys |
pascal@7850 | 137 if grep -q subroot= /proc/cmdline; then |
pascal@7845 | 138 subroot="/$(sed 's/.*subroot=\([^ ]*\).*/\1/' < /proc/cmdline)" && |
pascal@7850 | 139 if [ -s /usr/share/boot/busybox-static ]; then |
pascal@7850 | 140 mv /usr/share/boot/busybox-static . |
pascal@7850 | 141 /busybox-static rm -rf /etc /lib /*bin /usr /var |
pascal@7850 | 142 exec /busybox-static chroot /mnt$subroot /sbin/init |
pascal@7850 | 143 else |
pascal@7850 | 144 exec chroot /mnt$subroot /sbin/init |
pascal@7850 | 145 fi |
pascal@7850 | 146 fi |
pascal@10901 | 147 echo -n "tmpfs..." |
pascal@1704 | 148 size="$(grep rootfssize= < /proc/cmdline | \ |
pascal@1704 | 149 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')" |
pascal@1772 | 150 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }') |
slaxemulator@8013 | 151 umount /proc |
pascal@1775 | 152 [ -n "$size" ] || size="-o size=90%" |
pascal@1772 | 153 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then |
pascal@1772 | 154 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]" |
pascal@1772 | 155 exec /sbin/init |
pascal@1772 | 156 fi |
pascal@1704 | 157 for i in $(ls -a /); do |
pascal@1704 | 158 case "$i" in |
pascal@1705 | 159 .|..) ;; |
pascal@1704 | 160 mnt) mkdir /mnt/mnt;; |
pascal@1704 | 161 *) if ! cp -a /$i /mnt 2> /dev/null; then |
pascal@5978 | 162 failed |
pascal@1704 | 163 umount /mnt |
pascal@1704 | 164 exec /sbin/init |
pascal@1704 | 165 fi;; |
pascal@1704 | 166 esac |
pascal@1704 | 167 done |
pascal@4545 | 168 launch_init |