RHEL7: How can I setup and use "multi mount protection" for the ext4 filesystem?
Environment
- Red Hat Enterprise Linux (RHEL) 7
ext4filesystem- Multi Mount Protection (MMP)
Issue
- How can I setup and use "multi mount protection" for the ext4 filesystem?
- I have a blockdevice (for example a SAN LUN) which can be accessed by multiple Red Hat Enterprise Linux (RHEL) 7 systems. I want to use the
ext4filesystem ontop. How can I in a simple way prevent multiple systems to mount this filesystem at the same time? I do not want to use a cluster infrastructure.
Resolution
To use Multi Mount Protection, the ext4 filesystem has to be created with special options, for example:
mkfs -t ext4 -O mmp /dev/sda -E mmp_update_interval=5
On RHEL7, attempts to mount the filesystem multiple times will then not succeed.
Root Cause
RHEL7 contains both the userland and kernelland parts to use Multi Mount Protection (MMP) with the ext4 filesystem. Following the Keep it simple and stupid idea, this does not need any further infrastructure to be used (like cluster interconnect between multiple RHEL systems). Instead informations in the filesystem header are used to ensure only one accessing system at a time.
This is done with informations in the ext4 filesystem which are regularly updated by the system which has the filesystem mounted.
Diagnostic Steps
testing MMP functionality
A minimal test of MMP on a single system could look like the following procedure. We will create a sparse file, create a symlink. The symlink and the file will be used to get presented as blockdevices using losetup. We then create the filesystem with MMP options and attempt to mount the filesystem multiple times. The second mount attempt fails.
[root@rhel7a ~]# truncate -s 1G file
[root@rhel7a ~]# ln -s file file.symlink
[root@rhel7a ~]# losetup --show -f file
/dev/loop2
[root@rhel7a ~]# losetup --show -f file.symlink
/dev/loop3
[root@rhel7a ~]# mkfs -t ext4 -O mmp /dev/loop2 -E mmp_update_interval=5
[...]
[root@rhel7a ~]# mkdir -p /mnt/tmp1 /mnt/tmp2
[root@rhel7a ~]# mount /dev/loop2 /mnt/tmp1
[root@rhel7a ~]# mount /dev/loop3 /mnt/tmp2
[.. this command does not perform the mount.. ]
mount: wrong fs type, bad option, bad superblock on /dev/loop3,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
The systemlog contains this:
kernel: EXT4-fs warning (device loop3): ext4_multi_mount_protect:320: MMP interval 42 higher than expected, please wait.
kernel: EXT4-fs warning (device loop3): ext4_multi_mount_protect:333: Device is already active on another node.
kernel: EXT4-fs warning (device loop3): ext4_multi_mount_protect:333: MMP failure info: last update time: 1416843985, last update node: rhel7a, last update device: loop2
debugging MMP
- The interval information can be accessed with
dumpe2fs:
[root@rhel7a ~]# dumpe2fs -h /dev/sda | grep interval
dumpe2fs 1.42.9 (28-Dec-2013)
Check interval: 0 (<none>)
MMP update interval: 5
- If an MMP enabled filesystem is mounted, regular accesses to the blockdevice can be observed, i.e. using
blktrace. These are used to update the header.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.