CentOS – Best Practices for Running Filesystem Check on LVM Volume

centosfilesystemsfscklvmroot-filesystem

Have many systems with ext4 directly on the block device and others on lvm. I routinely create new systems with ext4 directly on the block device and use tune2fs to have automatic filesystem checks. In older versions of CentOS such as 4,5, or 6, i could do the same with ext filesystems on LVM, but not with newer versions. What is the best practice set of commands to make certain that filesystems are checked when they reside on LVM?

What is the best way to ensure a lvm volume is not corrupt? How to run fsck against a LVM filesystem? Is there something built in to lvm to automatically check the fs? If so, which logfile entry actually proves a check was done?

  1. Boot into single user mode, stop the diskmapper service and run mount to make certain all lvm volumes are NOT mounted. fsck /dev/mapper/vg0 with what parameters?
  2. Or boot from a LiveCD / that does not automatically mount LVM and run fsck from there?

Is there a way to use tune2fs for an ext filesystem on LVM? The most frequent way i have filesystem checks run is to have the OS do them automatically upon startup at regular intervals via tune2fs: tunefs -c 5 -i 7days /dev/sda1 but that does not work with lvm.

If fsck is the way, what switches does one pass to it? Without lvm, i fsck -c -c -D -C0 /dev/sda1 to get badblocks out of the picture and optimize folder structure. What lvm commands should be run before running the fsck?

Most of the documentation I have referenced in the past is not available.

Best Answer

How to run fsck against a LVM filesystem?

It's a good idea to make a snapshot or backup of the drive first.
1. and 2. depending which drive to fix.
Booting to emergency mode by adding systemd.unit=emergency.target to grub line is a good start. / is still mounted.

If fsck is the way, what switches does one pass to it?

You could check the root partition with a dry run (fsck -N) to see if errors are present. You'd need to boot from an external device to actually fix this one. (fsck -y is useful if there is a lot to fix, skips the annoying "Fix (y)?" question on each error found.)

Is there something built in to lvm to automatically check the fs?
(What is the best practice set of commands to make certain that filesystems are checked when they reside on LVM?)

No. AFAIK /etc/fstab - 6th field is setting this. (see man fstab)

The sixth field, (fs_passno), is used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time. The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware. If the sixth field is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked.

If so, which logfile entry actually proves a check was done?

This is stored to the filesystem. For ext2/ext3/ext4 it could look like this (fsck in 13, mount count will be set to 0. tune2fs -C <n> set mount count manually)

sudo tune2fs -l /dev/mapper/vg0-lv0 | grep -i "mount count" 

Mount count:              17
Maximum mount count:      30

(Other filesystems eg. XFS, btrfs work differently but you get the idea)

What lvm commands should be run before running the fsck?

none

Related Question