Linux – Change NFS to use UDP instead of TCP

bootlinuxmountnfs

I have a Debian 10 machine using NFS, it is using TCP protocol and I would like to change it to UDP.

This is output from the netbooted machine:

mount | grep 1
10.10.1.1:/remotesys on / type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,nolock,proto=tcp,port=2049,timeo=7,retrans=10,sec=sys,local_lock=all,addr=10.10.1.1)

Where can I change that proto=tcp parameter permanently ? I would guess that this could be set in pxelinux.cfg/default file but I have not found any docs for this file so I have no idea about the syntax used here.

EDIT: What I have tried so far:

  • Adding option "proto=udp" to /etc/exports (booted but tcp is still in use)
  • Adding option "udp" to /etc/exports (booted but tcp is still in use)
  • Adding option ",proto=udp" to nfsroot option in pxelinux.cfg/default (failed to boot – invalid option proto)
  • Adding option "proto=udp" to pxelinux.cfg/default (booted but tcp is still in use)
  • Adding option "udp" to pxelinux.cfg/default (booted but tcp is still in use)

Best Answer

in your pxelinux.cfg/default, you have probably specified something like this:

LABEL       Ubuntu
MENU LABEL  ^Ubuntu 20.04 LTS Desktop
MENU DEFAULT
KERNEL     ubuntu-live/casper/vmlinuz
APPEND     root=/dev/nfs boot=casper ip=dhcp netboot=nfs nfsroot=192.168.xx.yy:/srv/ubuntu initrd=ubuntu-live/casper/initrd

Here is the documentation for the nfsroot parameter inside the kernel command line. It says:

nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]

so the answer to your question is, just append the proto=udp option to the nfsroot parameter as specified above, like this:

APPEND     root=/dev/nfs boot=casper ip=dhcp netboot=nfs nfsroot=192.168.xx.xx:/srv/ubuntu,proto=udp initrd=ubuntu-live/casper/initrd

[edit]
This Should be the documentation of the file format used for the pxelinux.cfg/default file.

[edit2]
After a long thorough search, I think I finally found the reason, why the options in the kernel command line are ignored: Bugreport for ubuntu casper

  1. the scripts/casper script uses nfsmount, which doesn’t accept the -o udp option. Changing »nfsmount« to »mount -t nfs« is a simple change and works.

So the solution would be to fix the initrd in use for your image...