Search code examples
linuxfilesystemsext2

how can I check the mount count on a ext2 filesystem


With tune2fs one can set the maximum mount count -c (before e2fsck kicks in on boot) and also the actual (current) mount count -C. I'm looking for a way to read these two values.


Solution

  • the man page has -l:

    sehe@desktop:~$ sudo tune2fs -l /dev/mapper/debian-uburoot  | grep count
    Inode count:              1310720
    Block count:              5241856
    Reserved block count:     262092
    Mount count:              12
    Maximum mount count:      -1
    

    So you could make it

    function mount_count() 
    { 
        tune2fs -l "$1" | 
          grep '^Mount count:' | 
          grep -oP '\d+'
    }
    

    Now you can

    mounted=$(mount_count /dev/sda1)
    echo "Volume sda1 has already been mounted $mounted times since last check"