Linux查看文件系统的挂载时间浅析
我们在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:)