Certainly this is a most basic task, but I am a most basic Linux user. There will come a time when you want to find out what filesystem a partition has on it. There are two types of partitions. Those that are mounted and those that are not. I’ll deal with those two main categories and the different ways you can handle them.
Mounted Filesystems and the ‘df’ Command
To find the filesystem type of a mounted partition, use the GNU df command with the -T option. Why did I specifically mention that the command has to be the GNU variety? Because the granddaddy UNIX version doesn’t have the -T option which outputs the filesystem of the partitions. If you’re running HP-UX you’re most likely out of luck with the df command. Here’s the output on a CentOS VPS I tinker with:
root@myserver [/]: df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext3 30963708 6571772 22819072 23% / none tmpfs 393216 0 393216 0% /dev/shm /usr/tmpDSK ext3 495844 13065 457179 3% /tmp
Mounted Filesystems and the ‘mount’ Command
You can also simply run the “mount” command without any options (which is in reality running the -l option to list all mounted filesystems). Here’s the output of the “mount” command from the same VPS as above:
root@myserver [/]: mount /dev/sda1 on / type ext3 (rw,usrquota) proc on /proc type proc (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) none on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0) /tmp on /var/tmp type none (rw,noexec,nosuid,bind)
Furthermore you can choose to list out only those mounted filesystems of a certain filesystem type using the -t option. For example:
root@myserver [/]: mount -t ext3,tmpfs /dev/sda1 on / type ext3 (rw,usrquota) none on /dev/shm type tmpfs (rw) /usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)
The above is the same as performing mount | egrep “ext3|tmpfs”
Mounted Filesystems and the fdisk Command
fdisk is a scary thing to wield when you realize the power that lies within. However, the -l option puts a ring in its nose so you can lead it around harmlessly. The -l option lists out a ton of informatoin about the partitions that are mounted. So much so that it can become a bit overwhelming to parse through. You’ll be happy if you know a bit about how to use grep. Fortunately, the server I’m using in this example doesn’t have many partitions:
Disk /dev/sda1: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sda1 doesnt contain a valid partition table Disk /dev/sda2: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sda2 doesnt contain a valid partition table
Mounted Filesystems and the ‘mtab’ File
You could cat out the contents of the mtab file to see the status of currently mounted filesystems including their filesystem.
root@myserver [/]: cat /etc/mtab /dev/sda1 / ext3 rw,usrquota 0 0 proc /proc proc rw 0 0 none /dev/pts devpts rw,gid=5,mode=620 0 0 none /dev/shm tmpfs rw 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 /usr/tmpDSK /tmp ext3 rw,noexec,nosuid,loop=/dev/loop0 0 0 /tmp /var/tmp none rw,noexec,nosuid,bind 0 0
Mounted Filesystems and the ‘/proc/mounts’ file
The /proc/mounts file is very similar to the ‘mtab’ file, but is supposedly more up to date. In fact, some people symlink /etc/mtab to /proc/mounts. Cat it out and compare it to the mtab file if you’d like.
Unmounted Filesystems and the ‘mount’ Command
If you have a drive that is not mounted, and want to know what the filesystem is, short of using some forensic analysis tools, you’ll need to actually mount the device. When given a block device and not passed any filesystem types, mount is run in ‘auto’ mode and will attempt to discern what filesystem is on the device. Apparently it will first try to mount it as one of the filesystems in /etc/filesystems. If that fails, it then tries all filesystems that are located in /proc/filesystems (quite an array!). The /proc/filesystems file is all of the filesystems that the kernel knows about including any modules that are loaded.
Once the drive is mounted, you can then run any of the above commands to find its exact filesystem. If mount wasn’t able to discern what filesystem was on the drive, you’ll need to perform some kind of offline analysis of the drive which that is beyond the scope of this post.
Unmounted Filesystems and the ‘fstab’ file
If you have a disk that usually auto-mounts but is not currently connected, you can still check to see what the filesystem is at least expected to be when it is available to mount. Look in the fstab file:
root@myserver [/]# cat /etc/fstab /dev/sda1 / ext3 defaults,usrquota 1 1 /dev/sda2 swap swap defaults 0 0 none /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0 proc /proc proc defaults 0 0 /usr/tmpDSK /tmp ext3 defaults,noauto 0 0 /tmp /var/tmp ext3 defaults,usrquota,bind,noauto 0 0
Notice that this only works if the disk that you are interested in is set to auto-mount when your Linux machine boots. If you look above at my example, my sda2 partition is in the fstab file but not the mtab file. Sda2 is not connected but I can still tell what the filesystem is expected to be when it is available to mount; the swap filesystem.
Fin!
That’s all of the ways that I’ve been using to find out a partition’s filesystem type. I’m still a bit skittish about using fdisk and cfdisk to check filesystems, but I tend to shy away from using potentially destructive commands for information gathering. =) I also heard it was possible to use ‘blkid’ to find a block device’s filesystem, but was not able to get that to work. What other ways do you know? Add your preferred methods in the comments below and I’ll periodically update the blog post with the information.








About the Author
I am a self employed Systems Administrator in sunny Phoenix, Arizona. I like origami and lemons. I do not like hangnails or snow. Interested in hiring me? Check the blog sidebar to the right for a contact form or email me at [email protected]