From 5d068b368f9b6858395ca99067d9d3aa64734c65 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 10 Jun 2007 22:59:35 +0000 Subject: initramfs-nfsboot 0.1: Sample initramfs script to boot from NFS. * Need too add parsing of kernel cmdline instead of hardcoded params. --- packages/initrdscripts/files/.mtn2git_empty | 0 packages/initrdscripts/files/nfsboot.sh | 10 ++++++++++ 2 files changed, 10 insertions(+) create mode 100644 packages/initrdscripts/files/.mtn2git_empty create mode 100644 packages/initrdscripts/files/nfsboot.sh (limited to 'packages/initrdscripts/files') diff --git a/packages/initrdscripts/files/.mtn2git_empty b/packages/initrdscripts/files/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/initrdscripts/files/nfsboot.sh b/packages/initrdscripts/files/nfsboot.sh new file mode 100644 index 0000000000..bb689fa3b8 --- /dev/null +++ b/packages/initrdscripts/files/nfsboot.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +echo "Starting initramfs boot..." +mkdir /proc +mount -t proc proc /proc +ifconfig eth0 192.168.20.230 +mkdir /mnt +mount -t nfs 192.168.20.210:/home/nfs/Angstrom-opie-image-test-h4000 /mnt +cd /mnt +exec switch_root -c /dev/console /mnt /sbin/init -- cgit v1.2.3 From 1d8ccb8276d860a7470943b063533503da72a2a6 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 17 Jul 2007 23:39:10 +0000 Subject: initramfs-nfsboot: Add parsing of kernel commandline params, bump version to 0.2 * Untested. --- packages/initrdscripts/files/nfsboot.sh | 44 +++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'packages/initrdscripts/files') diff --git a/packages/initrdscripts/files/nfsboot.sh b/packages/initrdscripts/files/nfsboot.sh index bb689fa3b8..b536c4042b 100644 --- a/packages/initrdscripts/files/nfsboot.sh +++ b/packages/initrdscripts/files/nfsboot.sh @@ -3,8 +3,48 @@ echo "Starting initramfs boot..." mkdir /proc mount -t proc proc /proc -ifconfig eth0 192.168.20.230 + +for arg in `cat /proc/cmdline`; do + echo $arg + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + echo $optarg + case $arg in + root=*) + root=$optarg ;; + 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 "x$device" in + usb*) + echo "USB" + modprobe g_ether + ;; +esac + +ifconfig $device $client_ip +) + mkdir /mnt -mount -t nfs 192.168.20.210:/home/nfs/Angstrom-opie-image-test-h4000 /mnt +if [ "x$root" = "x/dev/nfs" ]; then + echo "booting from NFS: $nfsroot" + mount -t nfs $nfsroot /mnt +else + echo "booting from: $root" + mount $root /mnt +fi + cd /mnt exec switch_root -c /dev/console /mnt /sbin/init -- cgit v1.2.3 From 2603e7f62a5a9e902a554855ed601d0619817b71 Mon Sep 17 00:00:00 2001 From: Alex Osborne Date: Thu, 19 Jul 2007 20:55:15 +0000 Subject: initramfs: New modular initramfs for booting kernel from various media. * Design principles: * This initramfs just mounts roots and runs init on it, nothing else. * Whenever possible, existing kernel parameters are used. When extended boot methods are provided, new parameters mimick/adhere to existing conventions. * System is modular/pluggable - each mount method is in own module with more or less well defined interface, it's possible to construct complete system with any combination of modules. * Modules includes: initramfs-module-loop, initramfs-module-nfs, to boot from loop devices (including recursive loops) and NFS, correspondingly. --- packages/initrdscripts/files/init.sh | 65 ++++++++++++++++++++++++++++ packages/initrdscripts/files/loopboot.sh | 54 +++++++++++++++++++++++ packages/initrdscripts/files/nfsboot.sh | 74 +++++++++++++------------------- 3 files changed, 150 insertions(+), 43 deletions(-) create mode 100644 packages/initrdscripts/files/init.sh create mode 100644 packages/initrdscripts/files/loopboot.sh (limited to 'packages/initrdscripts/files') diff --git a/packages/initrdscripts/files/init.sh b/packages/initrdscripts/files/init.sh new file mode 100644 index 0000000000..8c9803f21b --- /dev/null +++ b/packages/initrdscripts/files/init.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +MODULE_DIR=/initrd.d +BOOT_ROOT= +ROOT_DEVICE=/dev/null + +early_setup() { + mkdir /proc + mount -t proc proc /proc + mkdir /mnt + + echo -n "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() { + CMDLINE=`cat /proc/cmdline` + for arg in $CMDLINE; do + optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` + case $arg in + root=*) + ROOT_DEVICE=$optarg ;; + rootdelay=*) + rootdelay=$optarg ;; + esac + done +} + +load_modules() { + for module in $MODULE_DIR/*; do + source $module + done +} + +boot_root() { + cd $BOOT_ROOT + exec switch_root -c /dev/console $BOOT_ROOT /sbin/init +} + +boot_failed() { + echo "No valid root device was specified. Please add root=/dev/something to" + echo "the kernel command-line and try again." + echo + exec sh +} + +echo "Starting initramfs boot..." +early_setup +read_args + +if [ -n "$rootdelay" ]; then + echo "Waiting $rootdelay seconds for devices to settle..." + sleep $rootdelay +fi + +load_modules +[ -n "$BOOT_ROOT" ] && boot_root +boot_failed diff --git a/packages/initrdscripts/files/loopboot.sh b/packages/initrdscripts/files/loopboot.sh new file mode 100644 index 0000000000..55a1948db8 --- /dev/null +++ b/packages/initrdscripts/files/loopboot.sh @@ -0,0 +1,54 @@ +#!/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 + cd $hostpt + fi + + echo "Loopback setup of $path (offset $offset)" + losetup -o "$offset" "$loopdev" "$path" + + echo "Mounting $loopdev on $mountpt" + mkdir "$mountpt" + mount "$loopdev" "$mountpt" + cd "$mountpt" + BOOT_ROOT="$mountpt" + loop_num=`expr "$loop_num" + 1` + } + + modprobe vfat + 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/packages/initrdscripts/files/nfsboot.sh b/packages/initrdscripts/files/nfsboot.sh index b536c4042b..62a044267a 100644 --- a/packages/initrdscripts/files/nfsboot.sh +++ b/packages/initrdscripts/files/nfsboot.sh @@ -1,50 +1,38 @@ #!/bin/sh -echo "Starting initramfs boot..." -mkdir /proc -mount -t proc proc /proc - -for arg in `cat /proc/cmdline`; do - echo $arg - optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'` - echo $optarg - case $arg in - root=*) - root=$optarg ;; - nfsroot=*) - nfsroot=$optarg ;; - ip=*) - ip=$optarg ;; +if [ "$ROOT_DEVICE" = "/dev/nfs" ]; then + 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 + ;; 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 "x$device" in - usb*) - echo "USB" - modprobe g_ether - ;; -esac + + ifconfig $device $client_ip + ) -ifconfig $device $client_ip -) - -mkdir /mnt -if [ "x$root" = "x/dev/nfs" ]; then echo "booting from NFS: $nfsroot" mount -t nfs $nfsroot /mnt -else - echo "booting from: $root" - mount $root /mnt + BOOT_ROOT=/mnt fi - -cd /mnt -exec switch_root -c /dev/console /mnt /sbin/init -- cgit v1.2.3 From d25cb314d2672973d3eed42e736e681a3e3a4337 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 19 Jul 2007 21:11:07 +0000 Subject: initramfs-module-nfs: Make it actually mount NFS by using the same option as kernel does. --- packages/initrdscripts/files/nfsboot.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'packages/initrdscripts/files') diff --git a/packages/initrdscripts/files/nfsboot.sh b/packages/initrdscripts/files/nfsboot.sh index 62a044267a..5129a53ebb 100644 --- a/packages/initrdscripts/files/nfsboot.sh +++ b/packages/initrdscripts/files/nfsboot.sh @@ -1,6 +1,11 @@ #!/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[^=]*=\(.*\)'` @@ -33,6 +38,6 @@ if [ "$ROOT_DEVICE" = "/dev/nfs" ]; then ) echo "booting from NFS: $nfsroot" - mount -t nfs $nfsroot /mnt + mount -t nfs $NFS_OPTIONS $nfsroot /mnt BOOT_ROOT=/mnt fi -- cgit v1.2.3 From 4dbe593fa51cf0286431c13f78c7a769efb10ff7 Mon Sep 17 00:00:00 2001 From: Alex Osborne Date: Fri, 20 Jul 2007 13:24:07 +0000 Subject: initramfs: Add blockboot plugin and cleanup dependency handling. --- packages/initrdscripts/files/blockboot.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/initrdscripts/files/blockboot.sh (limited to 'packages/initrdscripts/files') diff --git a/packages/initrdscripts/files/blockboot.sh b/packages/initrdscripts/files/blockboot.sh new file mode 100644 index 0000000000..567f7e29b3 --- /dev/null +++ b/packages/initrdscripts/files/blockboot.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Allow booting from a normal block device. + +if [ -e "$ROOT_DEVICE" ]; then + echo "booting from: $ROOT_DEVICE" + mount "$ROOT_DEVICE" /mnt + BOOT_ROOT=/mnt +fi -- cgit v1.2.3