The project of the day: boot multiple raspberry pi’s from the network, with each their own OS. An additional requirement: it has to fit in with my existing pxe server. There’s a raspberry pi doc that explains pxe booting from a pi, and I’m using it as a reference (link).
So let’s get to work.
References:
- Raspberry pi 3b+ 192.168.1.131 (dhcp reservation)
- Pxe server (debian with atftpd) 192.168.1.155
Since I’m following an existing guide and adapting it to my own environment, the original guide is marked in green, with my own additions in red.
On my raspberry pi:
sudo mkdir -p /nfs/LVDHERPI01
sudo apt-get install rsync
sudo rsync -xa –progress –exclude /nfs / /nfs/LVDHERPI01
Regenerate SSH host keys on the client filesystem by chrooting into it:
cd /nfs/LVDHERPI01
sudo mount –bind /dev dev
sudo mount –bind /sys sys
sudo mount –bind /proc proc
sudo chroot .
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
exit
sudo umount dev
sudo umount sys
sudo umount proc
Since I’m not using a raspberry pi as a server, but my existing pxe server, I’m going to copy the data over through scp.
move the files to my pxe server:
The OS data into an nfs share
scp -r /nfs/ 192.168.1.155:/
The boot folder into a subdir of the tftpboot folder with the IP address as name
scp -r /boot/* 192.168.1.155:/tftpboot/192.168.1.131
on the pxe server:
Edit my existing dnsmasq.conf and add the unique-root setting.
This redirects the requests of a client matching the IP addres to a subfolder in the tftpboot. As listed in the man pages:
For instance, if tftp-root is “/tftp” and client 1.2.3.4 requests file “myfile” then the effective path will be “/tftp/1.2.3.4/myfile” if /tftp/1.2.3.4 exists or /tftp/myfile otherwise.
Add the following line:
Tftp-unique-root
Then we’re back to the original guide, setting up the nfs root:
sudo apt-get install nfs-kernel-server
echo “/nfs/LVDHERPI01 *(rw,sync,no_subtree_check,no_root_squash)” | sudo tee -a /etc/exports
sudo systemctl enable rpcbind
sudo systemctl restart rpcbind
sudo systemctl enable nfs-kernel-server
sudo systemctl restart nfs-kernel-server
Edit /tftpboot/192.168.1.131/cmdline.txt and from root= onwards, and replace it with
root=/dev/nfs nfsroot=192.168.1.155:/nfs/LVDHERPI01,vers=3 rw ip=dhcp rootwait elevator=deadline
Finally, edit /nfs/LVDHERPI01/etc/fstab and remove the /dev/mmcblkp1 and p2 lines (only proc should be left).
That should do it. To add more raspberry pi’s:
- Create the folder /nfs/LVDHERPI02 and add the OS data (note, if you’re copying existing an existing folder, the ssh keys will have to be regenerated)
- copy the /tftpboot/192.168.1.131 folder to /tftpboot/new.ip.add.ress
- Edit /tftpboot/new.ip.add.ress/cmdline.txt to the correct nfsroot