1

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.

1

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

  • I had totally forgotten about those last two fields in fstab. Dont believe my system allows tune2fs to manipulate /dev/mapper/vg0-lv0, but will look at it again. – rjt Jan 5 at 7:28
  • The boot-time filesystem check is triggered by either /etc/rc.d/rc.sysinit(RHEL/CentOS 6.x and older) or a per-filesystem instance of systemd-fsck@.service (7.x or newer). Before that happens, either rc.sysinit or udev rules will normally run a vgchange -ay to automatically activate any LVM logical volumes. If recovering a corrupted disk with LVM volumes, you might need to use vgchange -ay --activationmode partial manually to activate even LVs that are missing some of their PVs. The activation of LV is a necessary step before accessing it, both for fsck and for mounting. – telcoM Jan 5 at 9:50
  • tune2fs will definitely allow you to manipulate any block device that contains an ext2/3/4 filesystem, whether it is a whole disk, partition, LVM logical volume, software RAID logical disk, encrypted volume, multipathed disk or any combination of these. As far as it's concerned, any block device is as good as any other, as long as it has a filesystem of appropriate type inside. Also note that in CentOS 7 and above, the default filesystem type used by the OS installer is no longer ext4 but XFS. – telcoM Jan 5 at 10:00
0

fsck is a filesystem checker. LVM is a storage volume manager, not a filesystem. You’d use fsck on LVM logical volumes that have a filesystem just the same way you’d run it on a disk partition with a filesystem on it.

LVM metadata can be corrupted, but in general, LVM does a good job automatically fixing itself from backup stored in multiple places, and also a copy in /etc/lvm/backup/ (which you’d back up externally) can be used in case of major catastrophes.

  • Edited question to make it clear actual root user commandline commands are needed in the answer and that “on block” methods do not work when attempted against fs on lvm. – rjt Jan 5 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.