brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tune2fs can schedule a periodic check for ext4 filesystems

Filesystems
~/tips/tip-filesystems-tune2fs-check-interval

sudo tune2fs -l /dev/sdX1 | grep -iE 'mount count|check'

Have a data volume checked after a set time or number of mounts.

A volume that has been mounted for years may never have had a full check. ext4 can remember when one is due.

Look at the current values:

sudo tune2fs -l /dev/sdX1 | grep -iE 'mount count|check'

On many systems both limits are switched off. Set them like this:

sudo tune2fs -c 30 -i 3m /dev/sdX1

-c 30 asks for a check after 30 mounts and -i 3m after three months. A plain number for -i means days, and w means weeks. The listing now shows a date after Next check after.

The check happens when the filesystem is checked before mounting, so it takes effect at a start of the machine, not while the volume is in use. Make sure the last field of its fstab line is not zero, or nothing will run.

To switch it off again:

sudo tune2fs -c 0 -i 0 /dev/sdX1

I would think twice for a server that has to come back fast after a power cut. A surprise check on a big disk can add a long delay to a restart at the worst moment. Check the device name with lsblk first, and remember this is for ext2, ext3 and ext4 only.

Further reading: tune2fs man page

More Filesystems tips sudo fsfreeze -f /srv/data filefrag /var/lib/libvirt/images/vm1.qcow2 sudo btrfs filesystem usage /mnt/pool findmnt --df lsblk -f All Filesystems tips (6) All topics

Link