How to supply nfsroot path via DHCP when network booting
1
vote
1
answer
2474
views
I'm trying to network boot some Linux machines, so they mount their root filesystem over NFS. I would like to supply the path to the NFS mount via DHCP, so that all the machines can share the same TFTP configuration but mount different NFS folders according to the value in the DHCP response.
If I supply the
nfsroot
kernel parameter (e.g. nfsroot=1.2.3.4:/srv/client
) then they will happily mount the root filesystem from that NFS server and path and boot normally, so the set up is working as long as I supply the path in the kernel parameters.
However I don't want to hard-code this parameter on the kernel command line, and I want it loaded from the DHCP response, but I can't get this to work.
If I set DHCP option 17 with option root-path "1.2.3.4:/srv/client"
in my DHCP server config then the kernel boot log shows IP-Config: Complete
and rootserver=1.2.3.4, rootpath=/srv/client
so the kernel autoconfiguration is picking up this DHCP option correctly.
However once I remove the nfsroot
parameter from the kernel command line it appears to skip some of the NFS steps:
:: mounting '' on real root
nfs: Bad value for 'source'
So if I add nfsroot=
back (but leave it empty) then the missing NFS messages come back but fail because there is no path - it is not picking the path supplied by DHCP:
NFS-Mount: y:y
Waiting 10 seconds for device /dev/nfs ...
nfsmount: need a path
ERROR: Failed to mount the real root device.
Looking at [the kernel code](https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/fs/nfs/nfsroot.c#L141) it seems if the path starts with /
, ,
or a digit then it will parse it, otherwise it populates the path with the default /tftproot/%s
string instead. So I tried supplying the path as ,
(i.e. empty server, empty path, the options separator character, and then no options) which made a little progress - now the DHCP-supplied path appears:
NFS-Mount: ,:/srv/client
Waiting 10 seconds for device /dev/nfs ...
nfsmount: can't parse IP address ','
ERROR: Failed to mount the real root device.
However now it's treating the comma as the server IP. Testing out my theory to see what happens if I do supply an actual path with nfsroot=/dummy
, sure enough it overrides the DHCP response:
NFS-Mount: /dummy:/dummy
Waiting 10 seconds for device /dev/nfs ...
nfsmount: can't parse IP address '/dummy'
ERROR: Failed to mount the real root device.
I'm kind of stuck at this point. It seems that if you omit the nfsroot
parameter then it won't try to do an NFS mount, but if you supply it then it will overwrite the value returned from the DHCP server.
Any ideas how I can tell the kernel to do an nfsroot mount but to use the values from the DHCP response?
Asked by Malvineous
(7395 rep)
Jul 16, 2021, 11:58 AM
Last activity: Jul 16, 2021, 12:06 PM
Last activity: Jul 16, 2021, 12:06 PM