如何检查ext2文件系统上的挂载计数

时间:2013-12-31 12:08:21

标签: linux filesystems ext2

使用tune2fs可以设置最大挂载计数-c(在启动时启动e2fsck之前)以及实际(当前)挂载计数-C。我正在寻找一种读取这两个值的方法。

1 个答案:

答案 0 :(得分:2)

手册页有-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

所以你可以成功

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

现在你可以

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