- 7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
- 1. Using df Command
- 2. Using fsck Command
- 3. Using lsblk Command
- 4. Using mount Command
- 5. Using blkid Command
- 6. Using file Command
- 7. Using fstab File
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- 10 basic & powerful commands to check file system type in Linux/Unix
- What is a FileSystem?
- Commands to check file system type in Linux or Unix
- 1. blkid
- 2. lsblk
- 4. findmnt
- 5. file
- 6. udevadm
- 7. File /etc/fstab content
- 8. File /etc/mtab content
- 9. File /proc/mounts
- 10. mount command
- Related Posts
- Ubuntu Documentation
- Introduction
- Basic filesystem checks and repairs
- e2fsprogs — ext2, ext3, ext4 filesystems
- case 1
- case 2
- case 3
- case 4
- e2fsck cheatsheet
- dosfstools — FAT12, FAT16 and FAT32 (vfat) filesystem
- dosfsck cheatsheet
- ntfs-3g (previously also ntfsprogs) — NTFS filesystem
- reiserfstools — reiserfs
- xfsprogs — xfs
- Missing superblock
- Bad blocks
- Sources and further reading
7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
A file system is the way in which files are named, stored, retrieved as well as updated on a storage disk or partition; the way files are organized on the disk.
A file system is divided in two segments called: User Data and Metadata (file name, time it was created, modified time, it’s size and location in the directory hierarchy etc).
In this guide, we will explain seven ways to identify your Linux file system type such as Ext2, Ext3, Ext4, BtrFS, GlusterFS plus many more.
1. Using df Command
df command reports file system disk space usage, to include the file system type on a particular disk partition, use the -T flag as below:
df Command – Find Filesystem Type
For a comprehensive guide for df command usage go through our articles:
2. Using fsck Command
fsck is used to check and optionally repair Linux file systems, it can also print the file system type on specified disk partitions.
The flag -N disables checking of file system for errors, it just shows what would be done (but all we need is the file system type):
fsck – Print Linux Filesystem Type
3. Using lsblk Command
lsblk displays block devices, when used with the -f option, it prints file system type on partitions as well:
lsblk – Shows Linux Filesystem Type
4. Using mount Command
mount command is used to mount a file system in Linux, it can also be used to mount an ISO image, mount remote Linux filesystem and so much more.
When run without any arguments, it prints info about disk partitions including the file system type as below:
Mount – Show Filesystem Type in Linux
5. Using blkid Command
blkid command is used to find or print block device properties, simply specify the disk partition as an argument like so:
blkid – Find Filesystem Type
6. Using file Command
file command identifies file type, the -s flag enables reading of block or character files and -L enables following of symlinks:
file – Identifies Filesystem Type
7. Using fstab File
The /etc/fstab is a static file system info (such as mount point, file system type, mount options etc) file:
Fstab – Shows Linux Filesystem Type
That’s it! In this guide, we explained seven ways to identify your Linux file system type. Do you know of any method not mentioned here? Share it with us in the comments.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
10 basic & powerful commands to check file system type in Linux/Unix
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.
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
1. blkid
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.
With -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 NAME include TYPE , LABEL , and UUID
For example to list and check file system type for ext4 FS:
2. lsblk
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.
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.
Using -T directive with df command you can print file system type of all the mounted file systems.
Alternatively you can specify a device with df command to check file system type of the respective device
4. findmnt
findmnt will list all mounted filesystems or search for a filesystem. The findmnt command is able to search in /etc/fstab , /etc/mtab or /proc/self/mountinfo . If device or mountpoint is not given, all filesystems are shown.
Using —fstab directive, findmnt command will search in /etc/fstab and with -t it will limit the set of printed filesystems
If used without any directive, findmnt command will give you long list of output with all bind mounts
5. file
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
6. udevadm
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.
Using —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 /dev/sda1
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:
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
Similar to /etc/fstab you can also refer /etc/mtab to get the list of currently mounted file system along with the file system type.
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.
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.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
Источник
Ubuntu Documentation
Duplicate Article
This article covers the same material as another article. More info.
Introduction
This guide will help diagnose filesystem problems one may come across on a GNU/Linux system. New sections are still being added to this howto.
Basic filesystem checks and repairs
The most common method of checking filesystem’s health is by running what’s commonly known as the fsck utility. This tool should only be run against an unmounted filesystem to check for possible issues. Nearly all well established filesystem types have their fsck tool. e.g.: ext2/3/4 filesystems have the e2fsck tool. Most notable exception until very recently was btrfs. There are also filesystems that do not need a filesystem check tool i.e.: read-only filesystems like iso9660 and udf.
e2fsprogs — ext2, ext3, ext4 filesystems
Ext2/3/4 have the previously mentioned e2fsck tool for checking and repairing filesystem. This is a part of e2fsprogs package — the package needs to be installed to have the fsck tool available. Unless one removes it in aptitude during installation, it should already be installed.
There are 4 ways the fsck tool usually gets run (listed in order of frequency of occurrence):
- it runs automatically during computer bootup every X days or Y mounts (whichever comes first). This is determined during the creation of the filesystem and can later be adjusted using tune2fs.
- it runs automatically if a filesystem has not been cleanly unmounted (e.g.: powercut)
- user runs it against an unmounted filesystem
user makes it run at next bootup
case 1
When filesystem check is run automatically X days after the last check or after Y mounts, Ubuntu gives user the option to interrupt the check and continue bootup normally. It is recommended that user lets it finish the check.
case 2
If a filesystem has not been cleanly unmounted, the system detects a dirty bit on the filesystem during the next bootup and starts a check. It is strongly recommended that one lets it finish. It is almost certain there are errors on the filesystem that fsck will detect and attempt to fix. Nevertheless, one can still interrupt the check and let the system boot up on a possibly corrupted filesystem.
2 things can go wrong
fsck dies — If fsck dies for whatever reason, you have the option to press ^D (Ctrl + D) to continue with an unchecked filesystem or run fsck manually. See e2fsck cheatsheet for details how.
fsck fails to fix all errors with default settings — If fsck fails to fix all errors with default settings, it will ask to be run manually by the user. See e2fsck cheatsheet for details how.
case 3
User may run fsck against any filesystem that can be unmounted on a running system. e.g. if you can issue umount /dev/sda3 without an error, you can run fsck against /dev/sda3.
case 4
You can make your system run fsck by creating an empty ‘forcefsck’ file in the root of your root filesystem. i.e.: touch /forcefsck Filesystems that have 0 or nothing specified in the sixth column of your /etc/fstab, will not be checked
Till Ubuntu 6.06 you can also issue shutdown -rF now to reboot your filesystem and check all partitions with non-zero value in sixth column of your /etc/fstab. Later versions of Ubuntu use Upstart version of shutdown which does not support the -F option any more.
Refer to man fstab for what values are allowed.
e2fsck cheatsheet
e2fsck has softlinks in /sbin that one can use to keep the names of fsck tools more uniform. i.e. fsck.ext2, fsck.ext3 and fsck.ext4 (similarly, other filesystem types have e.g.: fsck.ntfs) This cheatsheet will make use of these softlinks and will use ext4 and /dev/sda1 as an example.
fsck.ext4 -p /dev/sda1 — will check filesystem on /dev/sda1 partition. It will also automatically fix all problems that can be fixed without human intervention. It will do nothing, if the partition is deemed clean (no dirty bit set).
fsck.ext4 -p -f /dev/sda1 — same as before, but fsck will ignore the fact that the filesystem is clean and check+fix it nevertheless.
fsck.ext4 -p -f -C0 /dev/sda1 — same as before, but with a progress bar.
fsck.ext4 -f -y /dev/sda1 — whereas previously fsck would ask for user input before fixing any nontrivial problems, -y means that it will simply assume you want to answer «YES» to all its suggestions, thus making the check completely non-interactive. This is potentially dangerous but sometimes unavoidable; especially when one has to go through thousands of errors. It is recommended that (if you can) you back up your partition before you have to run this kind of check. (see dd command for backing up filesystems/partitions/volumes)
fsck.ext4 -f -c -C0 /dev/sda1 — will attempt to find bad blocks on the device and make those blocks unusable by new files and directories.
fsck.ext4 -f -cc -C0 /dev/sda1 — a more thorough version of the bad blocks check.
fsck.ext4 -n -f -C0 /dev/sda1 — the -n option allows you to run fsck against a mounted filesystem in a read-only mode. This is almost completely pointless and will often result in false alarms. Do not use.
dosfstools — FAT12, FAT16 and FAT32 (vfat) filesystem
In order to create and check/repair these Microsoft(TM)’s filesystems, dosfstools package needs to be installed. Similarly to ext filesystems’ tools, dosfsck has softlinks too — fsck.msdos and fsck.vfat. Options, however, vary slightly.
dosfsck cheatsheet
These examples will use FAT32 and /dev/sdc1
fsck.vfat -n /dev/sdc1 — a simple non-interactive read-only check
fsck.vfat -a /dev/sdc1 — checks the file system and fixes non-interactively. Least destructive approach is always used.
fsck.vfat -r /dev/sdc1 — interactive repair. User is always prompted when there is more than a single approach to fixing a problem.
fsck.vfat -l -v -a -t /dev/sdc1 — a very verbose way of checking and repairing the filesystem non-interactively. The -t parameter will mark unreadable clusters as bad, thus making them unavailable to newly created files and directories.
Recovered data will be dumped in the root of the filesystem as fsck0000.rec, fsck0001.rec, etc. This is similar to CHK files created by scandisk and chkdisk on MS Windows.
ntfs-3g (previously also ntfsprogs) — NTFS filesystem
Due to the closed sourced nature of this filesystem and its complexity, there is no fsck.ntfs available on GNU/Linux (ntfsck isn’t being developed anymore). There is a simple tool called ntfsfix included in ntfs-3g package. Its focus isn’t on fixing NTFS volumes that have been seriously corrupted; its sole purpose seems to be making an NTFS volume mountable under GNU/Linux.
Normally, NTFS volumes are non-mountable if their dirty bit is set. ntfsfix can help with that by clearing trying to fix the most basic NTFS problems:
ntfsfix /dev/sda1 — will attempt to fix basic NTFS problems. e.g.: detects and fixes a Windows XP bug, leading to a corrupt MFT; clears bad cluster marks; fixes boot sector problems
ntfsfix -d /dev/sda1 — will clear the dirty bit on an NTFS volume.
ntfsfix -b /dev/sda1 — clears the list of bad sectors. This is useful after cloning an old disk with bad sectors to a new disk.
Windows 8 and GNU/Linux cohabitation problems This segment is taken from http://www.tuxera.com/community/ntfs-3g-advanced/ When Windows 8 is restarted using its fast restarting feature, part of the metadata of all mounted partitions are restored to the state they were at the previous closing down. As a consequence, changes made on Linux may be lost. This can happen on any partition of an internal disk when leaving Windows 8 by selecting “Shut down” or “Hibernate”. Leaving Windows 8 by selecting “Restart” is apparently safe.
To avoid any loss of data, be sure the fast restarting of Windows 8 is disabled. This can be achieved by issuing as an administrator the command : powercfg /h off
reiserfstools — reiserfs
Install reiserfstools package to have reiserfsck and a softlink fsck.reiserfs available. Reiserfsck is a very talkative tool that will let you know what to do should it find errors.
fsck.reiserfs /dev/sda1 — a readonly check of the filesystem, no changes made (same as running with —check). This is what you should run before you include any other options.
fsck.reiserfs —fix-fixable /dev/sda1 — does basic fixes but will not rebuild filesystem tree
fsck.reiserfs —scan-whole-partition —rebuild-tree /dev/sda1 — if basic check recommends running with —rebuild-tree, run it with —scan-whole-partition and do NOT interrupt it! This will take a long time. On a non-empty 1TB partition, expect something in the range of 10-24 hours.
xfsprogs — xfs
If a check is necessary, it is performed automatically at mount time. Because of this, fsck.xfs is just a dummy shell script that does absolutely nothing. If you want to check the filesystem consistency and/or repair it, you can do so using the xfs_repair tool.
xfs_repair -n /dev/sda — will only scan the volume and report what fixes are needed. This is the no modify mode and you should run this first.
xfs_repair will exit with exit status 0 if it found no errors and with exit status 1 if it found some. (You can check exit status with echo $?)
xfs_repair /dev/sda — will scan the volume and perform all fixes necessary. Large volumes take long to process.
XFS filesystem has a feature called allocation groups (AG) that enable it to use more parallelism when allocating blocks and inodes. AGs are more or less self contained parts of the filesystem (separate free space and inode management). mkfs.xfs creates only a single AG by default.
xfs_repair checks and fixes your filesystems by going through 7 phases. Phase 3 (inode discovery and checks) and Phase 4 (extent discovery and checking) work sequentially through filesystem’s allocation groups (AG). With multiple AGs, this can be heavily parallelised. xfs_repair is clever enough to not process multiple AGs on same disks.
Do NOT bother with this if any of these is true for your system:
- you created your XFS filesystem with only a single AG.
your xfs_repair is older than version 2.9.4 or you will make the checks even slower on GNU/Linux. You can check your version with xfs_repair -V
xfs_repair -o ag_stride=8 -t 5 -v /dev/sda — same as previous example but reduces the check/fix time by utilising multiple threads, reports back on its progress every 5 minutes (default is 15) and its output is more verbose.
if your filesystem had 32 AGs, the -o ag_stride=8 would start 4 threads, one to process AGs 0-7, another for 8-15, etc. If ag_stride is not specified, it defaults to the number of AGs in the filesystem.
xfs_repair -o ag_stride=8 -t 5 -v -m 2048 /dev/sda — same as above but limits xfs_repair’s memory usage to a maximum of 2048 megabytes. By default, it would use up to 75% of available ram. Please note, -o bhash=xxx has been superseded by the -m option
== jfsutils — jfs == == btrfs ==
Missing superblock
Bad blocks
Sources and further reading
— more details about XFS filesystem
Источник