Re: initrd and NFS

Gerd Knorr (kraxel@cs.tu-berlin.de)
Mon, 19 May 1997 17:34:21 +0200


In article <m0wTDBG-0005FgC@lightning.swansea.linux.org.uk>, you wrote:
>> It seems a bad idea that the NFSroot code has to have so many extra
>> bits in the kernel. e.g. all the network setup code bootp, actual NFS
>
>I'd actually like to see the NFS root code taken completely out of the
>kernel if we can use the initrd ramdisk to accomplish all it does.
>
We can. A tiny initrd can do bootp and network setup. You can have
the ethernet driver as module too. The bootpc client from sunsite needs
a small patch...

-------------------
--- bootpc.c-dist Sun Mar 31 17:03:32 1996
+++ bootpc.c Sun Mar 31 17:02:41 1996
@@ -643,6 +643,7 @@
/* Root pathname to mount as root filesystem (ignored) */
case TAG_ROOTPATH :
len = cookie[i+1] ;
+ PrintString("ROOTPATH", cookie, i+2, len) ;
i += len + 2 ;
break ;
-------------------

... and the following script will do the network setup. Had this running
a while ago on a 4 MB box. The script returns error codes, so you can
do something like "netboot || /bin/sh" to get a prompt in case something
fails.

Gerd

-------------------
#!/bin/sh

# we need the proc fs...
test -f /proc/net/dev || mount -t proc none /proc;

# ... and nfsroot support
if test -f /proc/sys/kernel/nfs-root-addrs; then true; else
echo "Oops: kernel has no nfs root support"
umount /proc; exit 1
fi

# try bootp on ethernet devices
devices=`grep 'eth[0-9]:' /proc/net/dev | cut -d ':' -f1`
for device in $devices; do
ifconfig $device 0.0.0.0 netmask 0.0.0.0 up
route add default netmask 0.0.0.0 dev $device
echo -n "trying bootp on $device... "
if response=`bootpc --dev eth0 --returniffail`; then
echo "OK"
bootp_ok=1
else
echo "FAILED"
bootp_ok=0
fi
route del default netmask 0.0.0.0 dev $device
ifconfig $device down
test "$bootp_ok" = "1" && DEV="$device" && break
done

if test "$bootp_ok" = ""; then
echo "Oops: no network device found"
umount /proc; exit 2
fi

if test "$DEV" != ""; then
eval "$response"
# echo "--------------------------------------"
# i=$IFS;IFS="";echo $response;IFS=$i;unset i
# echo "--------------------------------------"
if [ "$HOSTNAME" != "" -a "$DOMAIN" != "" ]; then
# we have a full name...
myname="$HOSTNAME.$DOMAIN"
else
# else use the IP-address
myname="$IPADDR"
fi
addrs="$IPADDR:$SERVER:$GATEWAY:$NETMASK:$myname:$DEV"
name="$SERVER:$ROOTPATH"
echo "0" > /proc/sys/kernel/real-root-dev
echo "$addrs" > /proc/sys/kernel/nfs-root-addrs
echo "$name" > /proc/sys/kernel/nfs-root-name
echo "NFS root fs is $name"

if [ "$NETMASK" = "" -o "$NETWORK" = "" ]; then
ifconfig "$DEV" "$IPADDR"
route add -host "$SERVER" dev "$DEV"
else
ifconfig "$DEV" "$IPADDR" netmask "$NETMASK"
route add -net "$NETWORK" netmask "$NETMASK" dev "$DEV"
[ "$GATEWAY" != "" ] && route add default "$GATEWAY"
fi
if mount -t nfs $name /mnt; then umount /mnt; else probe=failed; fi
# if [ "$NETMASK" = "" -o "$NETWORK" = "" ]; then
# route del "$SERVER"
# else
# [ "$GATEWAY" != "" ] && route del default
# route del "$NETWORK"
# fi
# ifconfig $DEV down
if [ "$probe" = "failed" ]; then
echo "Hmm, can't mount the root fs. config error? server down ?"
umount /proc; exit 4
fi

# OK
route; echo
umount /proc; exit 0;
fi
echo "Hmm, no bootp response. config error? server down ?"
umount /proc; exit 3