Skip to content

Instantly share code, notes, and snippets.

@yangxuan8282
Last active September 27, 2022 10:52
Show Gist options
  • Save yangxuan8282/24e8d5ff70049afc7bb12a8f4a46e8b6 to your computer and use it in GitHub Desktop.
Save yangxuan8282/24e8d5ff70049afc7bb12a8f4a46e8b6 to your computer and use it in GitHub Desktop.
pi netboot with docker

⚠️ NFS server version 3 in docker behavior is strange, it won't work after restart the containter, and seems raspberry pi kernel have not supported netboot from vers 4 yet(will got kernel panic), so use docker to do this is not reliable for now, if we want to make container work again after stopped we have to restart the host.

☞ use this compose: https://github.com/yangxuan8282/rpi3-pxe-docker , this is the working one

port=0
dhcp-range=192.168.1.255,proxy
log-dhcp
enable-tftp
tftp-root=/tftpboot
pxe-service=0,"Raspberry Pi Boot"
version: "2"
services:
netboot_boot:
image: local/dnsmasq
privileged: true
network_mode: "host"
volumes:
- ./boot:/tftpboot
- ./dnsmasq.conf:/etc/dnsmasq.conf
netboot_root:
image: local/nfs-server
privileged: true
network_mode: "host"
volumes:
# - ./exports:/etc/exports
- ./rootfs:/nfsshare
FROM arm32v6/alpine
RUN apk add --no-cache dnsmasq
EXPOSE 53/tcp \
53/udp \
67/udp
ENTRYPOINT ["dnsmasq", "--no-daemon", "--user=dnsmasq", "--group=dnsmasq"]
FROM arm32v6/alpine
RUN apk --update --no-cache add bash nfs-utils \
&& echo "/nfs/client1 *(rw,sync,no_subtree_check,no_root_squash)" | tee -a /etc/exports
COPY run_nfs /usr/bin/
COPY exports /etc/exports
#VOLUME /nfs/client1
ENTRYPOINT ["run_nfs"]
/nfsshare *(rw,sync,no_subtree_check,no_root_squash)
#!/bin/bash
set -xe
trap "stop; exit 0;" SIGTERM SIGINT
stop()
{
# We're here because we've seen SIGTERM, likely via a Docker stop command or similar
# Let's shutdown cleanly
echo "SIGTERM caught, terminating NFS process(es)..."
/usr/sbin/exportfs -ua
pid1=$(pidof rpc.nfsd)
pid2=$(pidof rpc.mountd)
kill -TERM $pid1 $pid2 > /dev/null 2>&1
echo "Terminated."
exit
}
mkdir -p /nfsshare
# Fixed nlockmgr port
#echo 'fs.nfs.nlm_tcpport=32768' >> /etc/sysctl.conf
#echo 'fs.nfs.nlm_udpport=32768' >> /etc/sysctl.conf
#sysctl -p > /dev/null
mount -t nfsd nfds /proc/fs/nfsd
rpcbind -w
rpc.nfsd -N 2 -V 3 -N 4 -N 4.1 8
exportfs -arfv
rpc.statd
rpc.mountd -N 2 -V 3 -N 4 -N 4.1 -F
@corusm
Copy link

corusm commented Mar 30, 2022

Hi there,
I just tried to get this working on my Pi and get this error message:
rpc.mountd: Bad path in mount request from 10.50.1.47: "1000:/nfsshare/root"

In addition to this, I get some errors of this kind:

dnsmasq     | dnsmasq-tftp: sent /tftpboot/bcm2711-rpi-4-b.dtb to 10.50.1.47
dnsmasq     | dnsmasq-tftp: error 0 Early terminate received from 10.50.1.47
dnsmasq     | dnsmasq-tftp: failed sending /tftpboot/overlays/overlay_map.dtb to 10.50.1.47

I attempted to restart the docker container, but this didn't work either. The Kernel on the pi panicked. :/

Here is my approach (based on your repo and this gist)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment