36

This question may vary between distros but, in general, what are the advantages/disadvantages of using a hard or soft mount in the UNIX world?

Are there certain situations where one is more beneficial or are the uses fairly universal?

4 Answers 4

28

A hard mount is generally used for block resources like a local disk or SAN. A soft mount is usually used for network file protocols like NFS or CIFS.

The advantage of a soft mount is that if your NFS server is unavailable, the kernel will time out the I/O operation after a pre-configured period of time. The disadvantage is that if your NFS driver caches data and the soft mount times out, your application may not know which writes to the NFS volumes were actually committed to disk.

1
  • 1
    nfsstat -m or mount | grep nfs to check mount flags
    – yurenchen
    Sep 22, 2022 at 22:03
11

hard mounts and "intr" (interruptible) is a good compromise (for kernels before 2.6.25, see comment by Ryan Horrisberger) . The application is not fooled about successful writes, yet you can kill them if something clogs up the tubes.

1
  • 11
    the intr option is deprecated and ignored in recent versions on linux from: linux.die.net/man/5/nfs : The intr / nointr mount option is deprecated after kernel 2.6.25. Only SIGKILL can interrupt a pending NFS operation on these kernels, and if specified, this mount option is ignored to provide backwards compatibility with older kernels. Feb 20, 2013 at 17:26
8

A hard mount using some kind of network file system (nfs or fuse) can (sometimes) block forever while trying to re-establish a broken connection. This means, every process trying to access that mount goes into disk sleep (D) until the device is available again or the system is rebooted.

Disk sleep can not be interrupted or killed. Its like the zombie of zombie processes.

In short, do not use hard mounts for network file systems, ever. You want the file system to fail (immediately, to processes using syscalls) if I/O is not possible. Otherwise, the memory that they claim may as well be leaked if the FS fails.

4
  • I agree with your general recommendation re hard mounts. However, some people who deploy VMWare on NFS recommend using hard mounts. I'm not 100% familiar with why they do that, but it's something to consider and research closely before implementing. May 18, 2009 at 16:32
  • Given that hard mounts hang forever, and in the Olden Days machines would sometimes hang on reboot because of a hard NFS mount, isn't it possible to lose data on hard mounts? Imagine that your NFS fileserver goes down, now your clients are unable to reach it, they're totally confused, you reboot them... their potential writes are gone. Back in the days before soft mounts existed, hard mounts caused problems rebooting computers. If you booted a fileserver before a client, the client would hang. We'd have to power-cycle them, sometimes. People make mistakes. Is it still an issue today?
    – Mike S
    Nov 21, 2019 at 14:55
  • @MikeS There are many such setups out there running happily. You never know what you'll run into in labs or factories where decade old machines are still happily controlling equipment. It's not so much an issue for folks that work on modern stuff. But yes, hard mounts can cost you data (but soft mounts can too!) - but any network file system that doesn't use battery-backed caching I/O has the same potential for that problem. Hard mounts just make it extra awful when it comes to automating detection & recovery.
    – Tim Post
    Nov 22, 2019 at 4:56
  • AWS has implemented hosted NFS with EFS. They default to using hard mount. "We recommend that you use the hard mount option (hard) to ensure data integrity."
    – Sam
    Aug 30, 2022 at 22:51
2

A soft or hard mount depends on the usage of the filesystem and impacts the write operation guarantees from the underlying software stack. From the nfs man page (the mount options also apply to nfsv4), "A so-called "soft" timeout can cause silent data corruption in certain cases. As such, use the soft option only when client responsiveness is more important than data integrity."

For mission critical read-write application use, always use hard mounts to prevent file corruption (this is the reason why it is default for most systems).

For read-only filesystems it is safe to use soft because there is no danger of losing data an application thought has been written to the filesystem and therefore preferred because it won't block the application; only return no-data or an error - both of which can and should be detected by an application.

2
  • nfsv4 no longer supports soft? According to the man page, "Options supported by all versions These options are valid to use with any NFS version. soft / hard Determines the recovery behavior of the NFS client after an NFS request times out. If neither option is specified (or if the hard option is specified), NFS requests are retried indefinitely. If the soft option is specified, then the NFS client fails an NFS request after retrans retransmissions have been sent, causing the NFS client to return an error to the calling application." See linux.die.net/man/5/nfs
    – Mike S
    Nov 21, 2019 at 14:48
  • I think you're contradicting yourself... "soft is only used by people who don't understand..." and "for ro filesystem it is safe to use soft..." Also, see @Tim Post's post, above.
    – Mike S
    Nov 21, 2019 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .