开发者

Differentiate between different filesystem with the same name

开发者 https://www.devze.com 2023-04-04 16:11 出处:网络
I have written a code to analyze the file system statistics (say io,total no if files etc.) for RHEL. Now user delete the filesystem and create a new filesystem but with the same name.

I have written a code to analyze the file system statistics (say io,total no if files etc.) for RHEL. Now user delete the filesystem and create a new filesystem but with the same name. Now my code is not able to differentiate between the file system and display data about FS which confuses user like which belongs to new and which belogs to old FS. As my code is reading file system by its name. So if i get a unique id for the file system assi开发者_如何学JAVAgned by OS, it will help. I expect OS will assign unique id every time file system create.

Can someone help me to fix this?


You can inspect the UUID of the filesystem, which should be unique for each filesystem.

Have a look at:

[root@server]# ls -l /dev/disk/by-uuid/

If /dev/disk/by-uuid does not exist by default (e.g. on RHEL4), you can still query the UUID using tune2fs or blkid. For example:

[root@server]# tune2fs -l /dev/sda1 | awk '/Filesystem UUID/{print $3}'

or

[root@server]# blkid /dev/sda1 | awk '{print $3}'

P.S. If you need to do a reverse mapping (find device based that has a specific UUID), you can use findfs UUID=<the-uuid>


Your best bet would probably be to store other identifying information about the filesystem besides it's name, for instance it's metadata, type, uuid of the partition it's on, etc...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号