Sharing Linux Files with NFS

Samba has been my go-to for file sharing on my network. However I want to use my ubuntu file server with my nextcloud server. I think it’s time for NFS. Digital Ocean comes through again with a good tutorial. The method is to “export” the directory on the server and “mount” the exported directory on the client. Export definitions are in /etc/export and mount definitions are in /etc/fstab.

server$  sudo apt install nfs-kernel-server

client$   sudo apt install nfs-common

server$  sudo nano /etc/exports

Enter export: /media/storage 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Use systemctl to manage the server: sudo systemctl status nfs-kernel-server.

Create the client mount point: mkdir -p /nfs/storage

client$  sudo mount fileserver:/media/storage /nfs/storage (to test path)

client$  sudo nano /etc/fstab

Enter the mount:                                                                                                                        fileserver:/media/storage /nfs/storage nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0 (You probably need a hosts entry for for the server named file.)

Refresh fstab: mount -a

Refresh exports: exportfs -ra

Update: LXC Containers

LXC containers are not priviliged to mount hard drives. The best practice is to mount the NFS share on the Proxmox host as above. Then use a bind-mount – edit /etc/pve/lxc/1xx.conf and add the line:

mp0: /mnt/storage,mp=/mnt/lxc_nfs_share

Mount Sequence with LXC Containers

For lack of a better place, it goes here. The Proxmox host cannot mount the file server NFS share until the file server starts. Jellyfin cannout mount the NFS the Proxmox host mounts the share.

Disable the fstab mount. Create a systemd mount unit. Here’s a sample /etc/systemd/storage.mount:

[Unit]
Description=Mount NFS share after LXC container 101 is ready
Requires=container@101.service
After=container@101.service

[Mount]
What=192.168.1.50:/export/storage
Where=/mnt/storage
Type=nfs
Options=_netdev,auto

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reexec
sudo systemctl enable –now storage.mount

/et

Leave a comment