Table of Contents
Any operating system must be able to access and manage files on storage devices; however, the manner in which the files are organized on a storage device is actually set by the underlying filesystem.With Linux and Unix there are various filesystem types, so in this article I will share multiple commands and methods to check file system type in Linux and Unix.
In my earlier article I had shared the steps to create file system and implement quota on file system for user, group and directories.
Before we try to determine and check file system type, we must be familiar with the term “File System”.
What is a FileSystem?
As you probably know, or at least can guess, hard drives are not monolithic entities with data simply spread haphazardly around the hard drive. Hard drives are organized into sectors and clusters. Data of any type is organized into files. Whether it is a document, image, spreadsheet, or even an executable program, it is a file. That file may be stored in one or more clusters.
Filesystems are responsible to organize, find, and work with those files that are on the hard drive. There are issues that any filesystem must address in order to handle files effectively.
The first issue occurs because many files are larger than a single sector or cluster. So, locating the entirety of a file on a hard drive is an issue that must be addressed. The operating system may need to check several clusters, not necessarily contiguous, to find a file.
Another problem is how to store the files in clusters and sectors. Also, a filesystem must address how to handle space left due to deleted or moved files.
Now since we know what is a File System, Let us start with the actual agenda of this article.
Commands to check file system type in Linux or Unix
blkid can determine the type of content (e.g. filesystem or swap) that a block device holds, and also the attributes (tokens,
NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).
You must execute
blkid as root user without any directives and check “
TYPE” field to check file system type of respective partition or device in Linux or Unix.
[root@centos-8 ~]# blkid /dev/mapper/rhel-root: UUID="0b5322d5-887d-4c03-9933-b75c2a1ca880" TYPE="ext4" /dev/sda2: UUID="pXZ2Iy-hwtF-mFH2-nbej-0Yz9-Py2O-AqLQNH" TYPE="LVM2_member" PARTUUID="fcbab19d-02" /dev/sdb1: UUID="1b3910d9-11a9-4f68-894e-47a51bd077a8" TYPE="crypto_LUKS" PARTUUID="09181a39-01" /dev/sda1: UUID="2b857500-a7cf-4ec4-8453-0ef636943d86" TYPE="ext4" PARTUUID="fcbab19d-01" /dev/sr0: UUID="2019-08-15-21-52-52-00" LABEL="CentOS-8-BaseOS-x86_64" TYPE="iso9660" PTUUID="3e04f576" PTTYPE="dos" /dev/mapper/rhel-swap: UUID="cd18aa4a-e2d3-423c-b120-7fef1b1d9aac" TYPE="swap"
-t, --match-token NAME=value, you can search for block devices with tokens named NAME that have the value value, and display any devices which are found. Common values for
For example to list and check file system type for ext4 FS:
[root@centos-8 ~]# blkid -t TYPE=ext4 /dev/mapper/rhel-root: UUID="0b5322d5-887d-4c03-9933-b75c2a1ca880" TYPE="ext4" /dev/sda1: UUID="2b857500-a7cf-4ec4-8453-0ef636943d86" TYPE="ext4" PARTUUID="fcbab19d-01"
lsblk lists information about all available or the specified block devices.
lsblk command provides more information, better control on output formatting, easy to use in scripts and it does not require root permissions to get actual information.
[root@centos-8 ~]# lsblk --fs NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 ext4 2b857500-a7cf-4ec4-8453-0ef636943d86 /boot └─sda2 LVM2_member pXZ2Iy-hwtF-mFH2-nbej-0Yz9-Py2O-AqLQNH ├─rhel-root ext4 0b5322d5-887d-4c03-9933-b75c2a1ca880 / └─rhel-swap swap cd18aa4a-e2d3-423c-b120-7fef1b1d9aac [SWAP] sdb └─sdb1 crypto_LUKS 1b3910d9-11a9-4f68-894e-47a51bd077a8 sr0 iso9660 CentOS-8-BaseOS-x86_64 2019-08-15-21-52-52-00 sr1
df is another popular and most used command to display the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown.
-T directive with
df command you can print file system type of all the mounted file systems.
[root@centos-8 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 2.4G 0 2.4G 0% /dev tmpfs tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs tmpfs 2.4G 8.6M 2.4G 1% /run tmpfs tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/mapper/rhel-root ext4 14G 9.2G 3.5G 73% / /dev/sda1 ext4 488M 129M 325M 29% /boot tmpfs tmpfs 479M 0 479M 0% /run/user/0
Alternatively you can specify a device with
df command to check file system type of the respective device
# df -Th /boot /dev/sda1 ext4 488M 129M 325M 29% /boot
findmnt will list all mounted filesystems or search for a filesystem. The
findmnt command is able to search in
/proc/self/mountinfo. If device or mountpoint is not given, all filesystems are shown.
findmnt command will search in
/etc/fstab and with
-t it will limit the set of printed filesystems
[root@centos-8 ~]# findmnt --fstab -t ext4 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rhel-root ext4 defaults /boot UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 ext4 defaults
If used without any directive,
findmnt command will give you long list of output with all bind mounts
[root@centos-8 ~]# findmnt -t ext4 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rhel-root ext4 rw,rela ├─/boot /dev/sda1 ext4 rw,rela ├─/var/named/chroot/etc/localtime /dev/mapper/rhel-root[/usr/share/zoneinfo/Asia/Kolkata] │ ext4 rw,rela ├─/var/named/chroot/etc/named.root.key /dev/mapper/rhel-root[/etc/named.root.key] ext4 rw,rela ├─/var/named/chroot/etc/named.conf /dev/mapper/rhel-root[/etc/named.conf] ext4 rw,rela ├─/var/named/chroot/etc/named.rfc1912.zones /dev/mapper/rhel-root[/etc/named.rfc1912.zones] ext4 rw,rela ├─/var/named/chroot/etc/rndc.key /dev/mapper/rhel-root[/etc/rndc.key] ext4 rw,rela ├─/var/named/chroot/etc/crypto-policies/back-ends/bind.config │ /dev/mapper/rhel-root[/usr/share/crypto-policies/DEFAULT/bind.txt] │ ext4 rw,rela ├─/var/named/chroot/etc/protocols /dev/mapper/rhel-root[/etc/protocols] ext4 rw,rela ├─/var/named/chroot/etc/services /dev/mapper/rhel-root[/etc/services] ext4 rw,rela ├─/var/named/chroot/etc/named /dev/mapper/rhel-root[/etc/named] ext4 rw,rela ├─/var/named/chroot/usr/lib64/bind /dev/mapper/rhel-root[/usr/lib64/bind] ext4 rw,rela └─/var/named/chroot/var/named /dev/mapper/rhel-root[/var/named] ext4 rw,rela
file command is normally only attempts to read and determine the type of argument files. Specifying the
-s option causes file to also read argument files which are block or character special files. This is useful for determining and to check file system types of the data in raw disk partitions, which are block special files
# file -s /dev/sda1 /dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 (needs journal recovery) (extents) (64bit) (large files) (huge files)
udevadm command queries the udev database for device information stored in the udev database. It can also query the properties of a device from its sysfs representation to help creating udev rules that match this device.
--query you can query the database for the specified type of device data. The below command gives a long output so we will grep the required data to check file system type for our device
# udevadm info --query=property /dev/sda1 | egrep "DEVNAME|ID_FS_TYPE" DEVNAME=/dev/sda1 ID_FS_TYPE=ext4
Some more commands and methods to determine filesystem type in Linux or Unix
Now above were some of the most used commands to check file system type but there are many other methods using which you can determine filesystem type
7. File /etc/fstab content
Normally all the devices we use are mounted via
/etc/fstab file to make the mounting reboot persistent. So you can always refer
/etc/fstab file to check file system type, for example:
# cat /etc/fstab /dev/mapper/rhel-root / ext4 defaults 1 1 UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 /boot ext4 defaults 1 2 /dev/mapper/rhel-swap swap swap defaults 0 0
Here the first column of the file specifies the partition device path while the third column shows the file system type of the respective device.
8. File /etc/mtab content
/etc/fstab you can also refer
/etc/mtab to get the list of currently mounted file system along with the file system type.
# grep root /etc/mtab /dev/mapper/rhel-root / ext4 rw,relatime 0 0
Here also the first column of the file specifies the partition device path while the third column shows the file system type of the respective device.
9. File /proc/mounts
Now /proc/mounts file refers
/etc/mtab so this is not a new method but just another file which you can look into to check file system type in Linux or Unix.
10. mount command
Again, mount command will also refer
/etc/mtab file to get the list of mounted file systems and can also help you determine file system type of individual devices.
# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,size=2436780k,nr_inodes=609195,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
Lastly I hope the methods and commands from the article to determine and check file system type on Linux and Unix was helpful. So, let me know your suggestions and feedback using the comment section.