diff options
Diffstat (limited to 'recipes/initrdscripts/files')
-rw-r--r-- | recipes/initrdscripts/files/00-psplash.sh | 6 | ||||
-rw-r--r-- | recipes/initrdscripts/files/01-bootldr-buster.sh | 41 | ||||
-rw-r--r-- | recipes/initrdscripts/files/10-initfs.sh | 6 | ||||
-rw-r--r-- | recipes/initrdscripts/files/30-bootmenu.sh | 180 | ||||
-rw-r--r-- | recipes/initrdscripts/files/80-ext3.sh | 17 | ||||
-rw-r--r-- | recipes/initrdscripts/files/80-loopboot.sh | 52 | ||||
-rw-r--r-- | recipes/initrdscripts/files/80-nfsboot.sh | 45 | ||||
-rw-r--r-- | recipes/initrdscripts/files/80-squashfs.sh | 17 | ||||
-rw-r--r-- | recipes/initrdscripts/files/85-blockboot.sh | 12 | ||||
-rw-r--r-- | recipes/initrdscripts/files/87-kexecboot.sh | 19 | ||||
-rw-r--r-- | recipes/initrdscripts/files/90-check-modules.sh | 24 | ||||
-rw-r--r-- | recipes/initrdscripts/files/98-aufs.sh | 17 | ||||
-rw-r--r-- | recipes/initrdscripts/files/99-psplash.sh | 4 | ||||
-rw-r--r-- | recipes/initrdscripts/files/init.sh | 97 |
14 files changed, 537 insertions, 0 deletions
diff --git a/recipes/initrdscripts/files/00-psplash.sh b/recipes/initrdscripts/files/00-psplash.sh new file mode 100644 index 0000000000..db8aabedd7 --- /dev/null +++ b/recipes/initrdscripts/files/00-psplash.sh @@ -0,0 +1,6 @@ +if ! grep -Eq '\s?psplash=false\s?' /proc/cmdline; then + mkdir -p /mnt/.psplash + mount tmpfs -t tmpfs /mnt/.psplash -o,size=40k + + psplash & +fi diff --git a/recipes/initrdscripts/files/01-bootldr-buster.sh b/recipes/initrdscripts/files/01-bootldr-buster.sh new file mode 100644 index 0000000000..c3b79b5328 --- /dev/null +++ b/recipes/initrdscripts/files/01-bootldr-buster.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +cmdl=`cat /proc/cmdline` +#cmdl="console=ttySA0,115200 console=ttySB0,115200" +if expr "$cmdl" : '.*mtdparts=ipaq' > /dev/null; then + echo "!!!!!!!!" + echo "Detected Compaq bootldr or derivative" + echo "Kernel command line is assumed to be bogus and ignored" + echo "!!!!!!!!" + CMDLINE="console=ttyS0,115200 console=tty0" + sleep 3 +fi + +# The main trouble is the bogus console=ttySA0 passed by bootldr +# It appears that kernel doesn't have protection against only invalid +# consoles being passed on the command line, which means that the +# kernel is deaf and dumb when booted by bootldr + +INVALID_CONSOLE=0 +VALID_CONSOLE=0 + +for arg in $cmdl; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + case $arg in + console=*) + if expr "$optarg" : 'ttySA[0-9]\+' > /dev/null; then + INVALID_CONSOLE=1 + elif expr "$optarg" : 'ttyS\?[0-9]\+' > /dev/null; then + VALID_CONSOLE=1 + fi + ;; + esac +done + +if [ $INVALID_CONSOLE -eq 1 -a $VALID_CONSOLE -eq 0 ]; then + echo "!!!!!!!!" + echo "No valid system console is detected" + echo "Explicitly using /dev/tty0 for input/output" + echo "!!!!!!!!" + CONSOLE="/dev/tty0" +fi diff --git a/recipes/initrdscripts/files/10-initfs.sh b/recipes/initrdscripts/files/10-initfs.sh new file mode 100644 index 0000000000..c2a843eb12 --- /dev/null +++ b/recipes/initrdscripts/files/10-initfs.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +modprobe -q vfat >/dev/null 2>&1 +modprobe -q ext2 >/dev/null 2>&1 +modprobe -q ext3 >/dev/null 2>&1 +modprobe -q jffs2 >/dev/null 2>&1 diff --git a/recipes/initrdscripts/files/30-bootmenu.sh b/recipes/initrdscripts/files/30-bootmenu.sh new file mode 100644 index 0000000000..5ebeead430 --- /dev/null +++ b/recipes/initrdscripts/files/30-bootmenu.sh @@ -0,0 +1,180 @@ +# +# (c) 2007 Paul Sokolovsky +# + +# 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" >$CONSOLE + cnt=0 + echo -e $list | \ + while read l; do + if [ $cnt == $num ]; then + echo -e -n "${E}1m" >$CONSOLE + fi + echo -e "$cnt: $l${E}0m" >$CONSOLE + 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` + fstype=`fstype </dev/$dev` + fstype=`expr "$fstype" : 'FSTYPE=\([A-Za-z0-9]*\).*'` +} + +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" -a "$fstype" != "jffs2" ]; then + # Comment following line to show all available block devices regardless of FS (for debug purposes) + 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:/srv/nfs/oe/image)" +add_menu_item "Shell" + +total=`echo -e $list | wc -l` +num=0 + +# Draw UI +stty -F $CONSOLE -echo +echo -e -n "${E}2J" >$CONSOLE +echo -e -n "${E}0;0H" >$CONSOLE +echo "Select boot image:" >$CONSOLE + +# Main loop +show_menu +while read -s -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 < $CONSOLE + +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" : '[^/]*\([^ ]*\).*'` +fstype=`expr "$sel" : '[^ ]* *\(.*\)'` + +if [ "$dev" == "Shell" ]; then + if [ -x /usr/sbin/dropbear ]; then + modprobe g_ether + ifconfig usb0 192.168.2.202 + mkdir -p /dev/pts + mount -t devpts devpts /dev/pts + export PATH=$PATH:/usr/sbin + /usr/sbin/dropbear -E + echo "Started dropbear @192.168.2.202" + fi + + exec /bin/sh +elif [ "$dev" == "NFS" ]; then + ROOT_DEVICE="/dev/nfs" + CMDLINE="$CMDLINE root=/dev/nfs nfsroot=192.168.2.200:/srv/nfs/oe/image" +elif [ -n "$path" ]; then + ROOT_DEVICE="/dev/loop" + CMDLINE="$CMDLINE root=/dev/loop looproot=/dev/$dev:$path" +else + ROOT_DEVICE="/dev/$dev" + # jffs2 is not recognized by mount automagically + if [ "$fstype" == "(jffs2)" ]; then + ROOT_FSTYPE="jffs2" + fi + CMDLINE="$CMDLINE root=$ROOT_DEVICE" +fi + +echo ROOT_DEVICE=$ROOT_DEVICE >$CONSOLE +echo CMDLINE=$CMDLINE >$CONSOLE + +############################## +fi diff --git a/recipes/initrdscripts/files/80-ext3.sh b/recipes/initrdscripts/files/80-ext3.sh new file mode 100644 index 0000000000..1f52d391fa --- /dev/null +++ b/recipes/initrdscripts/files/80-ext3.sh @@ -0,0 +1,17 @@ +ext3_mount () { + modprobe -q ext3 + + mkdir -p $2 + mount -t ext3 -onoatime,data=journal,errors=continue $1 $2 +} + +for arg in $CMDLINE; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + echo $arg xxx $optarg + case $arg in + ext3=*) + dev=`expr "$optarg" : '\([^:]*\).*'` + path=`expr "$optarg" : '[^:]*:\([^:]*\).*'` + ext3_mount $dev $path ;; + esac +done diff --git a/recipes/initrdscripts/files/80-loopboot.sh b/recipes/initrdscripts/files/80-loopboot.sh new file mode 100644 index 0000000000..d84244428e --- /dev/null +++ b/recipes/initrdscripts/files/80-loopboot.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +if [ "$ROOT_DEVICE" = "/dev/loop" ]; then + loop_mount() { + loopdev=/dev/loop$loop_num + mountpt=/mnt/loop$loop_num + + [ -e $loopdev ] || mknod $loopdev b 7 $loop_num + + # if only one argument was specified, let it be path not dev + if [ -z "$path" ] && [ -n "$dev" ]; then + path="$dev" + dev="" + fi + [ -z "$offset" ] && offset=0 + + if [ -n "$dev" ]; then + hostpt=`expr "$dev" : '.*/\([^/]*\)'` + [ -z "$hostpt" ] && hostpt="$dev" + + echo "Mounting $dev on $hostpt" + mkdir $hostpt + mount $dev $hostpt + fi + + echo "Loopback setup of $path (offset $offset)" + losetup -o "$offset" "$loopdev" "$hostpt/$path" + + echo "Mounting $loopdev on $mountpt" + mkdir "$mountpt" + mount "$loopdev" "$mountpt" + cd "$mountpt" + BOOT_ROOT="$mountpt" + loop_num=`expr "$loop_num" + 1` + } + + modprobe loop + + loop_num=0 + + for arg in $CMDLINE; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + echo $arg xxx $optarg + case $arg in + looproot=*) + dev=`expr "$optarg" : '\([^:]*\).*'` + path=`expr "$optarg" : '[^:]*:\([^:]*\).*'` + offset=`expr "$optarg" : '[^:]*:[^:]*:\([^:]*\).*'` + loop_mount ;; + esac + done +fi diff --git a/recipes/initrdscripts/files/80-nfsboot.sh b/recipes/initrdscripts/files/80-nfsboot.sh new file mode 100644 index 0000000000..e1588c16a8 --- /dev/null +++ b/recipes/initrdscripts/files/80-nfsboot.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +if [ "$ROOT_DEVICE" = "/dev/nfs" ]; then + + # These correspond to what kernel itself uses + # DO NOT CHANGE! + NFS_OPTIONS="-o nfsvers=2,nolock" + + for arg in $CMDLINE; do + echo $arg + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + echo $optarg + case $arg in + nfsroot=*) + nfsroot=$optarg ;; + ip=*) + ip=$optarg ;; + esac + done + + echo $ip | (IFS=: read client_ip server_ip gw_ip netmask hostname device autoconf; \ + echo client_ip=$client_ip; + echo server_ip=$server_ip; + echo gw_ip=$gw_ip; + echo netmask=$netmask; + echo hostname=$hostname; + echo device=$device; + echo autoconf=$autoconf; + + case "$device" in + usb*) + echo "USB" + modprobe g_ether + sleep 5 + ;; + esac + + ifconfig $device $client_ip + ping -c 2 $server_ip + ) + + echo "booting from NFS: $nfsroot" + mount -t nfs $NFS_OPTIONS $nfsroot /mnt + BOOT_ROOT=/mnt +fi diff --git a/recipes/initrdscripts/files/80-squashfs.sh b/recipes/initrdscripts/files/80-squashfs.sh new file mode 100644 index 0000000000..22c09544a0 --- /dev/null +++ b/recipes/initrdscripts/files/80-squashfs.sh @@ -0,0 +1,17 @@ +squashfs_mount () { + modprobe -q squashfs + + mkdir $2 + mount -t squashfs $1 $2 +} + +for arg in $CMDLINE; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + echo $arg xxx $optarg + case $arg in + squashfs=*) + dev=`expr "$optarg" : '\([^:]*\).*'` + path=`expr "$optarg" : '[^:]*:\([^:]*\).*'` + squashfs_mount $dev $path ;; + esac +done diff --git a/recipes/initrdscripts/files/85-blockboot.sh b/recipes/initrdscripts/files/85-blockboot.sh new file mode 100644 index 0000000000..e1c3ed893e --- /dev/null +++ b/recipes/initrdscripts/files/85-blockboot.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Allow booting from a normal block device. + +if [ -e "$ROOT_DEVICE" ]; then + echo "booting from: $ROOT_DEVICE" + type="" + if [ -n "$ROOT_FSTYPE" ]; then + type="-t $ROOT_FSTYPE" + fi + mount $type "$ROOT_DEVICE" /mnt || fatal "Unable to mount rootfs device" + BOOT_ROOT=/mnt +fi diff --git a/recipes/initrdscripts/files/87-kexecboot.sh b/recipes/initrdscripts/files/87-kexecboot.sh new file mode 100644 index 0000000000..0d2f040a83 --- /dev/null +++ b/recipes/initrdscripts/files/87-kexecboot.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Allow kexecing to kernel in rootfs + +if [ -n "$BOOT_ROOT" -a -f "$BOOT_ROOT/boot/zImage" ]; then + if ! expr "$CMDLINE" : '.*nokexec'; then + echo "Kernel found in rootfs:" >$CONSOLE + ls -l "$BOOT_ROOT/boot/zImage" >$CONSOLE + initramfs="" + if [ -f "$BOOT_ROOT/boot/initramfs.bin" ]; then + echo "Initramfs found in rootfs:" + ls -l "$BOOT_ROOT/boot/initramfs.bin" + initramfs="--initrd=$BOOT_ROOT/boot/initramfs.bin" + fi + echo /usr/sbin/kexec $initramfs --command-line="$CMDLINE nokexec" -f "$BOOT_ROOT/boot/zImage" >$CONSOLE + sleep 10 + /usr/sbin/kexec $initramfs --command-line="$CMDLINE nokexec" -f "$BOOT_ROOT/boot/zImage" + sleep 10000 + fi +fi diff --git a/recipes/initrdscripts/files/90-check-modules.sh b/recipes/initrdscripts/files/90-check-modules.sh new file mode 100644 index 0000000000..2423d7f8c5 --- /dev/null +++ b/recipes/initrdscripts/files/90-check-modules.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# Check that modules for the current kernel exist, error out otherwise + +uname=`cat /proc/version` +ver=`expr "x$uname" : 'xLinux version \([^ ]\+\) '` + +if [ -n "$BOOT_ROOT" -a ! -d "$BOOT_ROOT/lib/modules/$ver" ]; then + echo -e "\033[1m====================" + echo "ERROR!" + echo "There are no modules for this kernel" + echo "version ($ver) in the root file " + echo "system, which will lead to boot failure or" + echo "broken functionally. If you performed" + echo "a kernel upgrade, make sure that version" + echo "installed in root filesystem matches" + echo "version used in bootloader." + echo -e "====================\033[0m" + echo + + echo "System halted" + while true; do + sleep 10000 + done +fi diff --git a/recipes/initrdscripts/files/98-aufs.sh b/recipes/initrdscripts/files/98-aufs.sh new file mode 100644 index 0000000000..5f7cc11432 --- /dev/null +++ b/recipes/initrdscripts/files/98-aufs.sh @@ -0,0 +1,17 @@ +aufs_mount () { + modprobe -q aufs + + mkdir -p $2 /mnt + mount -t aufs -o br:$1:$2 none /mnt +} + +for arg in $CMDLINE; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + case $arg in + aufs=*) + rw=`expr "$optarg" : '\([^:]*\).*'` + ro=`expr "$optarg" : '[^:]*:\([^:]*\).*'` + aufs_mount $rw $ro + BOOT_ROOT=/mnt ;; + esac +done diff --git a/recipes/initrdscripts/files/99-psplash.sh b/recipes/initrdscripts/files/99-psplash.sh new file mode 100644 index 0000000000..3d5f1d60d1 --- /dev/null +++ b/recipes/initrdscripts/files/99-psplash.sh @@ -0,0 +1,4 @@ +if ! grep -Eq '\s?psplash=false\s?' /proc/cmdline; then + mkdir -p /mnt/mnt/.psplash + mount -n -o move /mnt/.psplash /mnt/mnt/.psplash +fi diff --git a/recipes/initrdscripts/files/init.sh b/recipes/initrdscripts/files/init.sh new file mode 100644 index 0000000000..221b8f56b9 --- /dev/null +++ b/recipes/initrdscripts/files/init.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +MODULE_DIR=/initrd.d +BOOT_ROOT= +ROOT_DEVICE= + +early_setup() { + mkdir /proc + mount -t proc proc /proc + mkdir /mnt + modprobe -q mtdblock +} + +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 + echo -n "$dev " + [ -e /dev/$dev ] || mknod /dev/$dev b $major $minor + fi + done + echo +} + +read_args() { + [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline` + for arg in $CMDLINE; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + case $arg in + root=*) + ROOT_DEVICE=$optarg ;; + rootfstype=*) + ROOT_FSTYPE=$optarg ;; + rootdelay=*) + rootdelay=$optarg ;; + debug) set -x ;; + shell) sh ;; + esac + done +} + +do_depmod() { + [ -e "/lib/modules/$(uname -r)/modules.dep" ] || depmod +} + +load_module() { + # Cannot redir to $CONSOLE here easily - may not be set yet + echo "initramfs: Loading $module module" + source $1 +} + +load_modules() { + for module in $MODULE_DIR/$1; do + [ -e "$module" ] && load_module $module + done +} + +boot_root() { + cd $BOOT_ROOT + exec switch_root -c /dev/console $BOOT_ROOT /sbin/init +} + +fatal() { + echo $1 >$CONSOLE + echo >$CONSOLE + exec sh +} + + +echo "Starting initramfs boot..." +early_setup +load_modules '0*' +do_depmod + +[ -z "$CONSOLE" ] && CONSOLE="/dev/console" + +read_args + +if [ -z "$rootdelay" ]; then + echo "rootdelay parameter was not passed on kernel command line - assuming 2s delay" + echo "If you would like to avoid this delay, pass explicit rootdelay=0" + rootdelay="2" +fi +if [ -n "$rootdelay" ]; then + echo "Waiting $rootdelay seconds for devices to settle..." >$CONSOLE + sleep $rootdelay +fi + +dev_setup + +load_modules '[1-9]*' + +[ -n "$BOOT_ROOT" ] && boot_root + +fatal "No valid root device was specified. Please add root=/dev/something to the kernel command-line and try again." |