我们在Linux系统中如何找到文件系统的挂载时间呢,下面实验测试环境为RHEL 6.6,其它Linux版本没有验证测试。这个简单测试了一下常用的ext3/4、xfs、nfs文件系统。
ext文件系统
如果文件系统类型为ext3、ext4(ext2没有测试,这么老的文件系统也没有多少意义了),那么可以使用命令tune2fs查看文件系统最后一次挂载时间。如下所示:
[root@DB-Server ~]# tune2fs -l /dev/sda1
tune2fs 1.39 (29-May-2006)
Filesystem volume name: /boot
Last mounted on: <not available>
Filesystem UUID: 582b189c-396c-4da8-a7a3-1effaa3e4000
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 26104
Block count: 104388
Reserved block count: 5219
Free blocks: 88252
Free inodes: 26070
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 2008
Inode blocks per group: 251
Filesystem created: Thu Aug 11 14:28:18 2016
Last mount time: Tue Feb 12 15:36:22 2019
Last write time: Tue Feb 12 15:36:22 2019
Mount count: 62
Maximum mount count: -1
Last checked: Thu Aug 11 14:28:18 2016
Check interval: 0 (<none>)
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
Default directory hash: tea
Directory Hash Seed: b532c8d4-49b6-4d8a-a2e7-96a415daee37
Journal backup: inode blocks
如上所示,命令会输出Last mount time这些信息。
xfs文件系统
如果文件类型是xfs的话,可以在日志/var/log/messages 中搜索XFS关键字。当然也可以搜索Mounting关键字,具体测试如下所示:
[root@DB-Server ~]# grep XFS /var/log/messages
Jul 19 15:03:29 DB-Server kernel: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
Jul 19 15:03:29 DB-Server kernel: SGI XFS Quota Management subsystem
Jul 19 15:03:29 DB-Server kernel: XFS (sdb): Mounting Filesystem
Jul 19 15:03:29 DB-Server kernel: XFS (sdb): Ending clean mount
Jul 19 15:17:39 DB-Server kernel: XFS (sdb): Mounting Filesystem
Jul 19 15:17:40 DB-Server kernel: XFS (sdb): Ending clean mount
[root@DB-Server ~]# umount /u04
[root@DB-Server ~]# date
Fri Jul 19 15:40:52 CST 2019
[root@DB-Server ~]# mount -t xfs /dev/sdb /u04
[root@DB-Server ~]# grep XFS /var/log/messages
Jul 19 15:03:29 DB-Server kernel: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
Jul 19 15:03:29 DB-Server kernel: SGI XFS Quota Management subsystem
Jul 19 15:03:29 DB-Server kernel: XFS (sdb): Mounting Filesystem
Jul 19 15:03:29 DB-Server kernel: XFS (sdb): Ending clean mount
Jul 19 15:17:39 DB-Server kernel: XFS (sdb): Mounting Filesystem
Jul 19 15:17:40 DB-Server kernel: XFS (sdb): Ending clean mount
Jul 19 15:40:55 DB-Server kernel: XFS (sdb): Mounting Filesystem
Jul 19 15:40:56 DB-Server kernel: XFS (sdb): Ending clean mount
或者搜索Mounting关键字,grep -ri Mounting /var/log/* | more
[root@DB-Server ~]# grep -ri Mounting /var/log/* | more
/var/log/anaconda.log:02:10:34,361 INFO : umounting loopback /tmp/product-disk /dev/loop7
/var/log/boot.log:Remounting root filesystem in read-write mode: [ OK ]
/var/log/boot.log:Mounting local filesystems: [ OK ]
/var/log/boot.log:Mounting filesystems: [ OK ]
/var/log/messages:Jul 19 15:03:29 DB-Server kernel: XFS (sdb): Mounting Filesystem
/var/log/messages:Jul 19 15:17:39 DB-Server kernel: XFS (sdb): Mounting Filesystem
/var/log/messages:Jul 19 15:40:55 DB-Server kernel: XFS (sdb): Mounting Filesystem
[root@DB-Server ~]#
其实,ext3、ext4 也可以搜索/var/log/messages, 例如可以使用下面命令(不同版本的Linux可能有所不同,以实际情况为准)
grep EXT4 /var/log/messages
nfs文件系统
如果文件格式是nfs的话,可以用命令 cat /proc/self/mountstats,通过age来判断,这个表示nfs挂载后的时间,单位为秒。
"age" that specified the time in seconds since the nfs volume was mounted.
cat /proc/self/mountstats命令会输出age信息,如下所示:
device xxx.xxx.xxx.xxx:/docker mounted on /docker with fstype nfs4 statvers=1.1
opts: rw,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,acregmin=3,acregmax=60,acdirmin=30,acdirmax=60,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.10.5.53,local_lock=none
age: 23049075
caps: caps=0xffdf,wtmult=512,dtsize=32768,bsize=0,namlen=255
nfsv4: bm0=0xfdffbfff,bm1=0xf9be3e,bm2=0x0,acl=0x3,pnfs=not configured
sec: flavor=1,pseudoflavor=1
events: 933485 16418086 98 204 247406 29 32837386 50 0 303 0 32337916 494048 30 8084851 56 0 8084831 0 2 46 0 0 0 0 0 0
bytes: 6359097360 190907 0 0 233464 182715 303 48
RPC iostats version: 1.0 p/v: 100003/4 (nfs)
xprt: tcp 839 0 1 0 19 1983681 1983681 0 4743991 0 37 2150 2760316
但是个人测试发现,有些版本的nfs,输出信息是没有age。如下截图所示(Client nfs v3:)