Ubuntu nfsv4 mount
Ubuntu documentation
Server:
Create export directory or skip if exporting an existing dir:
Add directory to export, could also be an existing dir:
Server:
Create export directory or skip if exporting an existing dir:
- sudo mkdir /export/someDir
- sudo apt-get install nfs-kernel-server
Add directory to export, could also be an existing dir:
- /export/someDir *(ro,sync,no_root_squash)
- sudo /etc/init.d/nfs-kernel-server start
Client:
Create mount point:
- sudo mkdir /media/someDir
Install nfs server:
- sudo apt-get install nfs-kernel-server
Mount exported dir:
- sudo mount 192.168.25.123:/export/someDir /media/someDir
List all mounts
- mount
due to a bug, nfs mounts in /etc/fstab fail at startup
Create a start script to resolve the issue.
Startup/shutdown scripts:
Creates and removes /etc/init.d scripts:
Master/Slave Management script
#!/bin/bash
function trylock {
(
#attempt to acquire lock
flock -n 9 || { trylockResult=false; return; }
#start/set/open server as master
#perform periodic self health checks in a loop, CRUD operations
while true; do clear; date; sleep 2; done;
#if health checks fail, notify and exit releasing lock
) 9>/media/nfstest/testlockfile
}
while [ true ]
do
#perform initial health checks
trylock
if [ !$trylockResult ]
then
echo "Can't acquire lock, retry in 2 seconds"
sleep 2;
fi
done
Startup/shutdown scripts:
Creates and removes /etc/init.d scripts:
- sudo update-rc.d -f mount_nfs.sh remove
- sudo update-rc.d mount_nfs.sh defaults
Master/Slave Management script
#!/bin/bash
function trylock {
(
#attempt to acquire lock
flock -n 9 || { trylockResult=false; return; }
#start/set/open server as master
#perform periodic self health checks in a loop, CRUD operations
while true; do clear; date; sleep 2; done;
#if health checks fail, notify and exit releasing lock
) 9>/media/nfstest/testlockfile
}
while [ true ]
do
#perform initial health checks
trylock
if [ !$trylockResult ]
then
echo "Can't acquire lock, retry in 2 seconds"
sleep 2;
fi
done
Comments