Filesystem Maintenance

Good day my dear Linux Yogi’s,

today I am going to illustrate how to adjust the filesystem maintenance schedule and how to enforce a filesystem check upon next boot cycle. In the Linux Server world you usually not rebooting the server very often and the default schedule can take a long time to come up for the filesystem scan. Usually it is either disable with the value of -1 or it is somewhere near the count of 30.

I like my systems clean and usually lower the max count down to 5. That way it is more likely that I get my systems filesystem scanned at least once or twice in a year. Lets run the tool tune2fs and see what it is returning and how we get the information we are looking for.

Run the following command:

sudo tune2fs -l /dev/sda1

The command will list all information on the given partition.

tune2fs 1.42.13 (17-May-2015)
Filesystem volume name: <none>
Last mounted on: /home/msj/Data
Filesystem UUID: 62176ef1-4e98-4240-ac92-4b59c1b00d01
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash 
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 61054976
Block count: 244190390
Reserved block count: 12209519
Free blocks: 222262137
Free inodes: 61054947
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 965
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Mon Feb 13 08:19:46 2017
Last mount time: Tue Feb 14 09:48:56 2017
Last write time: Tue Feb 14 09:48:56 2017
Mount count: 3
Maximum mount count: -1
Last checked: Mon Feb 13 08:19:46 2017
Check interval: 0 (<none>)
Lifetime writes: 84 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 40d4af5b-8b54-43b9-a958-3856d035ad1f
Journal backup: inode blocks

This is a lot information. Lets break it down to the last time the filesystem was checked, what the current mount count is and what the maximum mount is set until next filesystem scan.

The first one will show us the last time it was checked:

sudo tune2fs -l /dev/sda1 |grep Last \ c

and it should return something like this:

Last checked: Mon Feb 13 08:19:46 2017

Great now we know when the last filesystem check occured now lets see what the current mount count is:

sudo tune2fs -l /dev/sda1 |grep Mount

it should return something similar like this:

Mount count:              3

Awesome and lastly lets have a look at what the maximum mount count is set before the next filesystem scan will be initiated with the following command:

sudo tune2fs -l /dev/sda1 |grep Max

and it should return something like the following:

Maximum mount count: -1

Wow, what is that? Well this means the that the filesystem scans have been deaktivated. This is not good if you are running a Server System in my humble opinion. So lets adjust this to 5.

sudo tune2fs -c 5 /dev/sda1

it should return something like the following

tune2fs 1.42.13 (17-May-2015)
Setting maximal mount count to 5

and now lets double check that it took our requested change.

sudo tune2fs -l /dev/sda1 |grep Max

and as you can see here it is:

Maximum mount count: 5

so in my case the next system scan should occur in two more reboots. So lets say you are in a situation where really want the system to scan the filesystem at the next time the server will be rebooted. This is very simple you just have to create a empty file by the name forcefsck into the root partition. You can do this with the following command:

sudo touch /forcefsck

and this concludes this illustration. I hope it was informative and useful to you. Don’t forget to register and share this article.

Thank you my dear linux Yogi’s until next time. Namaste! 😉