diff options
Diffstat (limited to 'packages/initrdscripts/files')
-rw-r--r-- | packages/initrdscripts/files/10-initfs.sh | 5 | ||||
-rw-r--r-- | packages/initrdscripts/files/30-bootmenu.sh | 154 | ||||
-rw-r--r-- | packages/initrdscripts/files/80-loopboot.sh (renamed from packages/initrdscripts/files/loopboot.sh) | 4 | ||||
-rw-r--r-- | packages/initrdscripts/files/80-nfsboot.sh (renamed from packages/initrdscripts/files/nfsboot.sh) | 0 | ||||
-rw-r--r-- | packages/initrdscripts/files/85-blockboot.sh (renamed from packages/initrdscripts/files/blockboot.sh) | 0 | ||||
-rw-r--r-- | packages/initrdscripts/files/init.sh | 10 |
6 files changed, 168 insertions, 5 deletions
diff --git a/packages/initrdscripts/files/10-initfs.sh b/packages/initrdscripts/files/10-initfs.sh new file mode 100644 index 0000000000..bad649e5c2 --- /dev/null +++ b/packages/initrdscripts/files/10-initfs.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +modprobe -q vfat >/dev/null 2>&1 +modprobe -q ext2 >/dev/null 2>&1 +modprobe -q ext3 >/dev/null 2>&1 diff --git a/packages/initrdscripts/files/30-bootmenu.sh b/packages/initrdscripts/files/30-bootmenu.sh new file mode 100644 index 0000000000..5b3e7782f4 --- /dev/null +++ b/packages/initrdscripts/files/30-bootmenu.sh @@ -0,0 +1,154 @@ +# If root is explicitly specified, skip interactive selection +if [ -z "$ROOT_DEVICE" ]; then +############################## + +E="\033[" +MOUNTLOC="tmp" +LOOP_IMG_MASK='*.img' + +if ! (echo " " | read -n1 foo) >/dev/null 2>&1; then + echo "'read' command lacks -n switch support, aborting" + exit 1 +fi + +mkdir -p $MOUNTLOC + +list="" + +add_menu_item() +{ + if [ -n "$list" ]; then + list="$list\n" + fi + + list="$list$1" +} + +show_menu() { + echo -e -n "${E}3;0H" + cnt=0 + echo -e $list | \ + while read l; do + if [ $cnt == $num ]; then + echo -e -n "${E}1m" + fi + echo -e "$cnt: $l${E}0m" + cnt=$((cnt + 1)) + done +} + +get_menu_selection() +{ + cnt=0 + sel=`echo -e $list | \ + while read l; do + if [ $cnt == $num ]; then + echo $l + break + fi + cnt=$((cnt + 1)) + done` +} + +get_partition_type() +{ + fstype=`mount -f --guess-fstype /dev/$dev $MOUNTLOC` +} + +scan_for_loopimgs() +{ +# Scan a device for loopback images, add to the list if found + mount /dev/$dev $MOUNTLOC + p=$PWD + cd $MOUNTLOC + for img in `ls -1 $LOOP_IMG_MASK 2>/dev/null`; do + add_menu_item "$dev/$img (loop img on vfat)" + done + cd $p + umount $MOUNTLOC +} + +# Scan all available device/partitions +while read maj min nblk dev; do + if [ -z "$maj" -o "$maj" == "major" ]; then + continue; + fi + + get_partition_type + if [ "$fstype" != "ext2" -a "$fstype" != "ext3" -a "$fstype" != "vfat" ]; then +# continue + true + fi + + if [ "$fstype" == "vfat" ]; then + scan_for_loopimgs + continue + fi + + add_menu_item "$dev ($fstype)" +done < /proc/partitions + +add_menu_item "NFS (nfsroot=192.168.2.200:/nfs/image)" + +total=`echo -e $list | wc -l` +num=0 + +# Draw UI +stty -echo +echo -e -n "${E}2J" +echo -e -n "${E}0;0H" +echo "Select boot image:" + +# Main loop +show_menu +while read -n1 i; do + case "$i" in + "A") + num=$((num - 1)) + if [ $num -lt 0 ]; then + num=$(($total - 1)) + fi + ;; + ["B"-"Z"]) + num=$((num + 1)) + if [ $num -ge $total ]; then + num=0 + fi + ;; + "q") + exec sh + ;; + "") + break + ;; + esac + show_menu +# echo "*$esc$i" +done + +stty echo + +# Process results of user selection, prepare input arguments +# for boot modules + +get_menu_selection +echo Selected: $sel + +dev=`expr "$sel" : '\([^ /]*\)'` +path=`expr "$sel" : '[^/]*\([^ ]*\).*'` + +if [ "$dev" == "NFS" ]; then + ROOT_DEVICE="/dev/nfs" + CMDLINE="$CMDLINE nfsroot=192.168.2.200:/nfs/image" +elif [ -n "$path" ]; then + ROOT_DEVICE="/dev/loop" + CMDLINE="looproot=/dev/$dev:$path" +else + ROOT_DEVICE="/dev/$dev" +fi + +echo ROOT_DEVICE=$ROOT_DEVICE +echo CMDLINE=$CMDLINE + +############################## +fi diff --git a/packages/initrdscripts/files/loopboot.sh b/packages/initrdscripts/files/80-loopboot.sh index 55a1948db8..d84244428e 100644 --- a/packages/initrdscripts/files/loopboot.sh +++ b/packages/initrdscripts/files/80-loopboot.sh @@ -21,11 +21,10 @@ if [ "$ROOT_DEVICE" = "/dev/loop" ]; then echo "Mounting $dev on $hostpt" mkdir $hostpt mount $dev $hostpt - cd $hostpt fi echo "Loopback setup of $path (offset $offset)" - losetup -o "$offset" "$loopdev" "$path" + losetup -o "$offset" "$loopdev" "$hostpt/$path" echo "Mounting $loopdev on $mountpt" mkdir "$mountpt" @@ -35,7 +34,6 @@ if [ "$ROOT_DEVICE" = "/dev/loop" ]; then loop_num=`expr "$loop_num" + 1` } - modprobe vfat modprobe loop loop_num=0 diff --git a/packages/initrdscripts/files/nfsboot.sh b/packages/initrdscripts/files/80-nfsboot.sh index 5129a53ebb..5129a53ebb 100644 --- a/packages/initrdscripts/files/nfsboot.sh +++ b/packages/initrdscripts/files/80-nfsboot.sh diff --git a/packages/initrdscripts/files/blockboot.sh b/packages/initrdscripts/files/85-blockboot.sh index 567f7e29b3..567f7e29b3 100644 --- a/packages/initrdscripts/files/blockboot.sh +++ b/packages/initrdscripts/files/85-blockboot.sh diff --git a/packages/initrdscripts/files/init.sh b/packages/initrdscripts/files/init.sh index 8c9803f21b..f8d5de9173 100644 --- a/packages/initrdscripts/files/init.sh +++ b/packages/initrdscripts/files/init.sh @@ -2,14 +2,17 @@ MODULE_DIR=/initrd.d BOOT_ROOT= -ROOT_DEVICE=/dev/null +ROOT_DEVICE= early_setup() { mkdir /proc mount -t proc proc /proc mkdir /mnt +} - echo -n "creating device nodes: " +dev_setup() +{ + echo -n "initramfs: Creating device nodes: " grep '^ *[0-9]' /proc/partitions | while read major minor blocks dev do if [ ! -e /dev/$dev ]; then @@ -35,6 +38,7 @@ read_args() { load_modules() { for module in $MODULE_DIR/*; do + echo "initramfs: Loading $module module" source $module done } @@ -60,6 +64,8 @@ if [ -n "$rootdelay" ]; then sleep $rootdelay fi +dev_setup + load_modules [ -n "$BOOT_ROOT" ] && boot_root boot_failed |