Debian NFS Root Filesystem Client

First you need to install some base packages:

server:~# aptitude install debootstrap nfs-kernel-server

Now it's time to build the first stage of debootstrap:

server:~# mkdir /srv/rootfs
server:~# echo "/srv/rootfs 10.20.30.0/24(rw,no_subtree_check,no_root_squash)" >> /etc/exports
server:~# /etc/init.d/nfs-kernel-server reload

server:~# cd /srv
server:/srv# debootstrap --verbose --foreign --arch=<ARCH> --variant=minbase --include=module-init-tools,locales,udev,aptitude,dialog,ifupdown,procps,iproute,iputils-ping,pump,nano,wget,ntp,netbase,nfs-common,initramfs-tools,linux-image-2.6-<SYSTEM> squeeze rootfs http://ftp.uk.debian.org/debian

Where '<ARCH>' is the architecture such as 'i386', 'sparc64', 'armel', etc and '<PROCESSOR>' is a suitable system taken from the Debian Kernel List such as '686'.

N.B. if the output of 'uname -m' on server matches what you want to use for '<ARCH>' then you can drop '--foreign'

You should now boot the client machine (or chroot into the rootfs directory) with something like Recovery is Possible off a DVD or USB and mount the NFS export and run through the second stage of debootstrap:

client:~# mkdir rootfs
client:~# mount -o nolock server:/srv/rootfs rootfs
client:~# chroot rootfs
I have no name!@client:/# ./debootstrap/debootstrap --verbose --second-stage
[snipped extracting and configuration of 'rootfs']

I have no name!@client:/# passwd
I have no name!@client:/# dpkg-reconfigure tzdata

Now it's time to make the initramfs file NFS capable:

[snipped editing of /etc/initramfs-tools/initramfs.conf using nano]
I have no name!@client:/# grep -v '^\(#\|$\)' /etc/initramfs-tools/initramfs.conf
MODULES=netboot
BUSYBOX=y
KEYMAP=n
BOOT=nfs
DEVICE=
NFSROOT=auto

I have no name!@client:/# update-initramfs -v -u

Now back on the server:

server:/srv# cat <<'EOF' > rootfs/etc/apt/apt.conf.d/07tmpexec
DPkg::Pre-Invoke {"mount -o remount,exec /tmp";};
DPkg::Post-Invoke {"mount -o remount /tmp";};
EOF

server:/srv# cat <<'EOF' > rootfs/etc/apt/sources.list
deb http://ftp.uk.debian.org/debian/ squeeze main contrib non-free
#deb-src http://ftp.uk.debian.org/debian/ squeeze main contrib non-free

deb http://security.debian.org/ squeeze/updates main contrib non-free
#deb-src http://security.debian.org/ squeeze/updates main contrib non-free

deb http://ftp.uk.debian.org/debian squeeze-updates main
#deb-src http://ftp.uk.debian.org/debian squeeze-updates main
EOF

server:/srv# cat <<'EOF' > rootfs/etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point>    <type>  <options>                       <d><p>
/dev/nfs        /                nfs     ro,hard                          1  1

tmpfs           /tmp             tmpfs   nodev,nosuid,noexec,size=32M     0  0
tmpfs           /var/tmp         tmpfs   nodev,nosuid,noexec,size=8M      0  0
varrun          /var/run         tmpfs   nodev,nosuid,noexec,size=512k    0  0
varlock         /var/lock        tmpfs   nodev,nosuid,noexec,size=96k     0  0

tmpfs           /etc/network/run tmpfs   nodev,nosuid,noexec,size=16k     0  0
tmpfs           /var/lib/nfs     tmpfs   nodev,nosuid,noexec,size=16k     0  0
tmpfs           /var/log         tmpfs   nodev,nosuid,noexec,size=1M      0  0
EOF

server:/srv# cat <<'EOF' > rootfs/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF

server:/srv# ln -s /proc/mounts rootfs/etc/mtab
server:/srv# rm rootfs/etc/udev/rules.d/*-persistent-*.rules
server:/srv# rm rootfs/etc/network/run/ifstate
server:/srv# rm rootfs/var/lib/urandom/random-seed

Now copy the /boot/vmlinuz and /boot/initrd.img into your TFTP directory and use pxelinux like so:

LABEL test
  MENU LABEL TEST
  KERNEL /nfs-booter/vmlinuz
  APPEND initrd=/nfs-booter/initrd.img ip=::::diskless:eth0:dhcp nfsroot=192.0.2.1:/srv/rootfs root=/dev/nfs panic=10 ro ipv6.disable=1

N.B. we unfortunately have to add 'ipv6.disable=1' as a kernel parameter as NFS is not yet IPv6 enabled (means lockd works and we avoid 'svc: failed to register lockdv1 RPC service')

www: debian-nfs-root (last edited 2011-07-05 12:04:27 by alex)