Linux支持的文件系统越来越多,如何区分不同分区上的文件系统类型?有如下方法可以参考(假定要确定文件系统类型的分区为sda1):
- 使用mount命令。mount命令会根据文件系统的超级块(superblock)自动识别分区的文件系统类型;如果无法识别会读取并匹配/etc/filesystems中的条目。
# mount /dev/sda1 /mnt/disk # mount or # cat /proc/mounts
- 手工分析文件系统的超级块(superblock)。如果mount无法自动识别,只能靠我们自己了。粗略查看:
# hexdump -C -n 32 /dev/sdc1 00000000 02 02 02 02 02 02 02 02 74 68 69 73 20 69 73 20 |........this is | 00000010 61 6e 20 6f 63 66 73 32 20 76 6f 6c 75 6d 65 00 |an ocfs2 volume.| 00000020
几乎可以确认sdc1上的文件系统是ocfs2。# hexdump -C -n 16 /dev/sda1 00000000 eb 52 90 4e 54 46 53 20 20 20 20 00 02 08 00 00 |.R.NTFS .....| 00000010
很像NTFS。# hexdump -C -n 256 /dev/sda11 00000000 eb 58 90 6d 6b 64 6f 73 66 73 00 00 02 20 20 00 |.X.mkdosfs... .| 00000010 02 00 00 00 00 f8 00 00 3f 00 ff 00 00 00 00 00 |........?.......| 00000020 02 68 54 02 42 25 00 00 00 00 00 00 02 00 00 00 |.hT.B%..........| 00000030 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000040 00 00 29 ce 8f 7e 44 20 20 20 20 20 20 20 20 20 |..)..~D | 00000050 20 20 46 41 54 33 32 20 20 20 0e 1f be 5b 7c ac | FAT32 ...[|.| 00000060 22 c0 74 0b 56 b4 0e bb 07 00 cd 10 5e eb f0 32 |".t.V.......^..2| 00000070 e4 cd 16 cd 19 eb fe 54 68 69 73 20 69 73 20 6e |.......This is n| 00000080 6f 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 64 69 |ot a bootable di| 00000090 73 6b 2e 20 20 50 6c 65 61 73 65 20 69 6e 73 65 |sk. Please inse| 000000a0 72 74 20 61 20 62 6f 6f 74 61 62 6c 65 20 66 6c |rt a bootable fl| 000000b0 6f 70 70 79 20 61 6e 64 0d 0a 70 72 65 73 73 20 |oppy and..press | 000000c0 61 6e 79 20 6b 65 79 20 74 6f 20 74 72 79 20 61 |any key to try a| 000000d0 67 61 69 6e 20 2e 2e 2e 20 0d 0a 00 00 00 00 00 |gain ... .......| 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000100
FAT32,肯定差不了。如果要精确匹配的话,需要了解每个文件系统的Magic signature以及保存的位置。如EXT2和EXT3的Magic signature是“53 ef”,保存在文件系统开始以后0x0438的位置。