Klaus Knopper answers your Linux questions
Ask Klaus
![](/var/linux_magazin/storage/images/issues/2016/191/ask-klaus/knopper_klaus.png/677534-1-eng-US/Knopper_Klaus.png_medium.png)
Mounting and unmounting network storage devices
Mounting and Unmounting Network Storage Devices
I'm using a small NAS storage server as network drive, which I mount the "Unix way" by NFS (Network File System), rather than using a Windows-compatible Samba client, which also would be supported by the device. That way, the mount point is accessible to all programs, not only the file manager or special clients that can use the smb:// protocol.
The command for mounting that I use under the directory name /media/volume1
is:
sudo mount -t nfs 10.0.0.20:/volume1 /media/volume1
Now, when suspending and disconnecting my computer from the network for traveling, I sometimes forget to unmount the NFS directory /media/volume1
, which results in all programs freezing when trying to access that directory. Trying to unmount in that situation with
sudo umount /media/volume1
does not work because the device is busy. Even when no processes are accessing the directory, unmounting fails because the server is not reachable.
Is there an "official" way to unmount NFS volumes when the server is not reachable?
NFS was built to be reliable even in the case of network dropouts or temporary server disconnects; the client will wait for a long, sometimes even an unlimited time for the server to respond again. Even signals like TERM (15) and KILL (-9) won't terminate a process that waits for an answer from the NFS server.
Furthermore, you can even reboot the NFS server and the client still won't terminate. This is the desired behavior in NFS design.
Some mount options, like -o intr
or -o timeo=n
or -o retrans=n
(see the NFS man page) change that behavior, but still you won't be able to unmount the NFS filesystem when the server is unreachable.
However, an easy trick allows you to work around the protocol: Just set the IP address of the former NFS server as the secondary IP address of your network card or loop back device first:
sudo ifconfig lo:1 10.0.0.20 netmask 255.255.255.255
For the client to detect the NFS server (it does not matter whether or not any directories are exported), start the port mapper and, if installed, the NFS kernel-based server:
sudo /etc/init.d/portmap start
or
sudo /etc/init.d/rpcbind start
then:
sudo /etc/init.d/nfs-kernel-server start
(The /etc/exports
file should exist; otherwise, the init script may decide not to start the actual NFS server.) An rpc.mountd
process should now be running, answering to mount
and umount
requests from the client.
The NFS client will now act as if the former NFS server is back online (even though there is really a new NFS server running on the client computer now), send a detach command on umount
and flush all client accesses (provided no processes are still actively using the mount point):
sudo umount -l /media/volume1
I use the -l
(lazy) option of umount
here, which will allow running processes to continue accessing the directory but hide the mount point from new processes and remove the mtab
entry, so it is not listed as a mounted volume anymore in /proc/mounts
or in the output of mount
or df
with no parameters.
Another tip: To avoid too lengthy command lines for mounting NFS volumes or Samba shares, /etc/fstab
entries can be helpful. Note that intr
and nolock
options for NFS allow you to cancel a read/write command by hitting Ctrl+C and avoids contacting the NFS locking process on the server side. Also, for NFS on Linux, the sync
option (which is known to slow down write access to local media) can actually make NFS more responsive because it avoids buffering too much data in long writes, thus avoiding a traffic jam on wireless networks (Listing 1).
Listing 1
/etc/fstab
With these entries, the network storage directories can be mounted just by typing
mount /media/volume1
or
mount /media/backup
without sudo
, as normal user.
Klaus Knopper
Klaus Knopper is an engineer, creator of Knoppix, and co-founder of LinuxTag expo. He works as a regular professor at the University of Applied Sciences, Kaiserslautern, Germany. If you have a configuration problem, or if you just want to learn more about how Linux works, send your questions to: klaus@linux-magazine.com
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.