Unmount volume or halt Linux on disk IO error

DavisNT asked:

Is there a way to dismount a volume (with open files on it) or cause kernel panic if IO error occurs on underlying disk?
OS is Linux. This is needed to prevent data corruption in case of storage availability problems.

My answer:

Set the appropriate errors mount option, e.g. in /etc/fstab. See the mount(8) man page.

              Define the behaviour when  an  error  is  encountered.   (Either
              ignore  errors  and  just mark the filesystem erroneous and con‐
              tinue, or remount the filesystem read-only, or  panic  and  halt
              the  system.)   The default is set in the filesystem superblock,
              and can be changed using tune2fs(8).

For example:

/dev/mapper/storage-libvirt /var/lib/libvirt        ext4    errors=panic     1 2

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.