this is obsolete doc -- see http://doc.nethence.com/ instead

Setting up a diskless NetBSD/i386 system 

 

Introduction 

This guide is mainly based on the [official one] (http://www.netbsd.org/docs/network/netboot/), but I hope, will be much more straighforward and comprehensive, as it is limited for now to the x86 hardware plateforms. 

 

Versions used: 

- NetBSD 6.1.3 amd64 for the PXE & NFS server, 

- NetBSD 6.1.3 i386 for the diskless system. 

 

Note. If you emulate the diskless system with VMware Server v1.x, ensure you are using only one virtual processor, otherwise the netbsd kernel crashes and reboots in cycles. Donno exactly what is causing that, crappy multiprocessor emulation on that old VMware product I am still using, or a NetBSD bug. But that's not the real issue here. 

 

Preparing the diskless filesystems 

Ok let's setup the Unix tree and swap device, 

mkdir -p /export/client/root/dev/
mkdir -p /export/client/root/swap/
chmod 700 /export/client/root/swap/
mkdir -p /export/client/root/home/
mkdir -p /export/client/home/
#mkdir -p /export/client/usr/
mknod /export/client/root/dev/console c 0 0
dd if=/dev/zero of=/export/client/swap bs=1024k count=256
chmod 600 /export/client/swap

Note. Fixing swap mount point to 700 and device-as-file permission to 600 otherwise you get a WARNING swap is readable by the world at the diskless system boot time (donno which one exactly is causing it but fixing both at once cannot hurt). 

 

Extract the NetBSD distribution to it, 

cd /data/netbsd613x32/ 

tar xvzpf kern-GENERIC.tgz -C /export/client/root/
#tar xvzpf kern-MONOLITHIC.tgz -C /export/client/root/
for set in base.tgz comp.tgz etc.tgz games.tgz man.tgz misc.tgz modules.tgz tests.tgz text.tgz; do
  print $set...\\c
  tar xzphfe $set -C /export/client/root/ && print done
done; unset set
#mv -f /export/client/root/usr/* /export/client/usr/
#touch /export/client/root/usr/NOT_MOUNTED

Note. Using the monolithic kernel isn't mandatory, root on nfs also works with the GENERIC one and it doesn't need the modules for that. 

 

Configure fstab to it knows where to find it, 

cd /export/client/root/etc/

nfsserver=192.168.0.1 

cat > fstab <<EOF9
$nfsserver:/export/client/swap   none  swap  sw,nfsmntpt=/swap
$nfsserver:/export/client/root   /     nfs   rw 0 0
$nfsserver:/export/client/home   /home nfs   rw 0 0
#$nfsserver:/export/client/usr    /usr  nfs   rw 0 0
EOF9
unset nfsserver

 

Setup the system so it won't auto-configure the network for now, 

cd /export/client/root/etc/
echo client.example.local > myname
echo 192.168.0.254 > mygate
cat > rc.conf <<EOF9
nfs_client=YES
auto_ifconfig=NO
net_interfaces=""
EOF9

Note. Donno why hostname= won't set the hostname, switching to the /etc/myname method simply fixed it. 

Note. Donno why defaultroute= won't work either. 

Note. No need to further configure the network as it is done at boot time already. 

 

Setup the IP address (will reference to this from the interface parameters), 

cd /export/client/root/etc/
cat > hosts <<EOF9
::1                     localhost localhost.
127.0.0.1               localhost localhost.

192.168.0.254 gw.example.local gw 

192.168.0.9 client.example.local client 

192.168.0.1 nfs.example.local nfs 

EOF9

 

Setting up the PXE boot 

Configure the DHCP daemon to point to the TFTP-server boot loader, 

cd /etc/
vi dhcpd.conf

like e.g., 

allow bootp;
ddns-update-style none;
allow unknown-clients;

 

subnet 192.168.0.0 netmask 255.255.255.0 {
        option domain-name "example.local";
        range 192.168.0.110 192.168.0.150;
        option subnet-mask 255.255.255.0;
        option routers 192.168.0.254;
        option domain-name-servers 192.168.0.254;
        option ntp-servers ntp.obspm.fr;

 

          # stage 1:
          filename "pxeboot_ia32.bin";               # relative to /tftpboot

 

          # stage 2:
          next-server 192.168.0.1;                  # IP of NFS server
          option root-path "/export/client/root";   # path on NFS server
}

Note. You could also seperate the PXE service to dedicated MAC addresses, 

host client {
        hardware ethernet 00:0c:29:77:a0:2a;
        fixed-address 192.168.0.9;

 

          # stage 1:

(...) 

apply, 

cd /etc/
cat dhcpd=yes >> rc.conf
rc.d/dhcpd restart

 

Configure the TFTP daemon to provide the boot loader, 

mkdir -p /tftpboot/
cp /export/client/root/usr/mdec/pxeboot_ia32.bin /tftpboot/
cd /etc/
vi inetd.conf

uncomment, 

tftp            dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /tftpboot
tftp            dgram   udp6    wait    root    /usr/libexec/tftpd      tftpd -l -s /tftpboot

Note. Yes both lines are recommended, otherwise you might get some name resolution issues (tftp localhost works while tftp 127.0.0.1 didn't... that was really strange). 

apply, 

/etc/rc.d/inetd restart

 

The next step is mandatory for the kernel boot to work, as it is provided by NFS directly. 

 

Setting up the NFS share 

Setup the shares, 

cat >> /etc/exports <<EOF9

/export/client/root -maproot=root:wheel 192.168.0.9 

/export/client/swap -maproot=root:wheel 192.168.0.9 

/export/client/home -maproot=nobody:nobody -network=192.168.0.0/24 

#/export/client/usr -maproot=nobody:nobody 192.168.0.9 

EOF9

Note. Careful you have to specify the client's IP or use the -network option, which is kind of an issue here for the read-write and client-specitic directories, unless you are considering -ro. Otherwise only the first share would show up. 

Ref. exporting more than one directory to the world in one filesystems failed: http://mail-index.netbsd.org/netbsd-bugs/2005/12/12/0004.html 

 

Enable the daemons, 

cd /etc/
cat >> rc.conf <<EOF9
rpcbind=yes
mountd=yes
nfs_server=yes
lockd=yes
statd=yes
nfs_client=yes
EOF9

and apply, 

/etc/rc.d/rpcbind restart 

/etc/rc.d/mountd restart 

/etc/rc.d/nfslocking restart 

/etc/rc.d/nfsd restart 

if you need to reload the exports file afterwards, on NetBSD it is, 

hup mountd

 

Check, 

showmount -e 127.0.0.1

 

Diskless' first boot 

You will enter single user mode as it will find /etc/rc.conf without rc_configured. Create the device files, 

  wsconsctl -w encoding=fr 

cd /dev/
./MAKEDEV all
swapctl -A
swapctl -l

configure RC (doing this on the server side may be easyer), 

cd /export/client/root/etc/
cat >> rc.conf <<EOF
if [ -r /etc/defaults/rc.conf ]; then
        . /etc/defaults/rc.conf
fi
rc_configured=YES
wscons=YES
sshd=YES
EOF
echo "encoding fr" >> wscons.conf

then back to the diskless system prompt, reboot, 

sync
reboot

Note. The /swap/ folder needs to exist so you can remotely mount the already prepared swap file through NFS. 

 

Check that you don't have any warnings at system boot time and check that swap is now enabled by default, 

swapctl -l

 

Additional notes 

You could also export /home/ instead of /export/client/home/ but this would be rather interesting in a [NIS situation] (http://pbraun.nethence.com/unix/net/nis.html). 

 

References 

Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/ 

Introduction, Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/intro.html 

Introduction (i386-specific), Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/intro.i386.html 

Setting up the dhcpd server, Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/dhcpd.html 

Setting up the tftpd server, Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/tftpd.html 

Setting up the NFS server, Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/nfs.html 

Setting up the filesystem, Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/files.html 

Finishing up your installation, Diskless NetBSD HOW-TO: http://www.netbsd.org/docs/network/netboot/finish.html