- 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
- Check and Repair Your Filesystem With fsck [Linux]
- Advanced Usage
- Auto repair filesystem when errors are detected
- Check all filesystems in one run
- Exclude check on mounted filesystem
- Specifying the filesystem type
- Force fsck to run everytime during bootup
- Using fsck with a GUI
- Conclusion
- Join the elite circle of Linux Power Users with this bundle
- 5 comments
- Popular Posts
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!!
Источник
Check and Repair Your Filesystem With fsck [Linux]
No matter how well you take care of your computer, sometimes, it will just crash and you often have to pull off the plug to restart the computer. When such crashes happen, there is a chance that your filesystem will get corrupted or damage. It is advisable to do a filesystem check regularly to make sure that it is running properly and free of error.
In Linux (and Mac), there is this powerful command “ fsck ” that you can use to check and repair your filesystem. “Fsck” stands for “File System Consistency checK”.
The usage is very easy. Open a terminal and type:
This will check the sda1 partition.
Note: fsck cannot be used on a mounted partition. If you do so, there is a high chance that it will damage the filesystem.
To check your Home folder that resides on another partition, say sda2, use the following commands:
Note: you will need root/superuser permission to run the “fsck” command.
You can also use “fsck” to check external drive, such as your thumb drive or SD card. For example:
If you are not sure of the partition number, you can use the command
to list out all the partitions in the system.
Advanced Usage
There are a few parameters that you can add to “fsck” to make it more powerful.
Auto repair filesystem when errors are detected
During the filesystem check, if errors are detected, you can get “fsck” to auto repair the filesystem with the -a flag. For example:
Similarly, using the -y flag can get the job done as well:
Check all filesystems in one run
If there are several filesystems in your computer, you can get fsck to check all of them at the same time with the -A flag.
What it will do is to grab all the filesystem entries from /etc/fstab and scan them for errors. You can use it together with the -R and -y flag to prevent it from scanning the root filesystem and fix all errors, if there is any.
Exclude check on mounted filesystem
As mentioned earlier, fsck cannot be run on a mounted filesystem. If you are using the -A flag to scan all the filesystems, and some of them are mounted, you might damage those filesystems. A way to overcome this is to use the -M flag to prevent it from checking mounted system.
For example, running the command
returns nothing and a return code 0 (which means “no error”). No scan was done at all since all the filesystems are mounted.
However, if I unmount the external thumb drive and run the command again, it will then perform the scan and return the output:
Specifying the filesystem type
There are times when you just want to check filesystems of a specific type, say ext2. You can make use of the -t flag to specify the filesystem type to check. For example, the command
will scan the external drive only if it is in the ext4 format. Alternatively, you can combine with the -A flag to scan all filesystems of the specific type:
Force fsck to run everytime during bootup
By default, Ubuntu will run fsck after every 30 bootups, but if you want the system to to do a “fsck” check everytime it boots up, all you need to do is to create an empty file call “forcefsck” and place it in the root folder. This will notify the system to do a “fsck” check everytime during boot up.
To change the checking frequency, you can make use of the command “ tune2fs “.
The following command instructs the system to run “fsck” after every 30 boot up.
You can also specify number of days instead of boot up:
Using fsck with a GUI
As you can see, fsck is mainly a command line tool. If you need a GUI for that, GParted comes with a feature that allows you to check your filesystem.
First, install GParted:
Next, open GParted and select the filesystem you want to check. Right click on it and select “Check”.
Conclusion
fsck is a useful command that can check your filesystem for errors and fix them automatically. Most of the time, you won’t have to bother with it as your system will usually run it regularly during boot up to make sure everything is working fine. However, when your filesystem get corrupted, this is the easiest way to find out what happen and fix it.
Note: fsck is also available in Mac.
Join the elite circle of Linux Power Users with this bundle
Do you have a burning desire to learn how to use Linux? If so, you have to check out the Linux Power User Bundle. Don’t worry about prior experience because these courses will show you how to install Linux servers and utilize proper command line technique like a pro. Open up a world of opportunity by learning Linux in this bundle, available now for just $19.
Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.
5 comments
A couple of notes:
To check a root fs that can not be unmounted “online” one can use LVM snapshot of it to check for errors while the system is running and without unmounting.
man fsck does not recommend using -a option but -p instead:
-a Automatically repair the file system without any questions (use this option with caution). Note that e2fsck(8) supports -a for backwards compatibility only. This option is mapped to
e2fsck’s -p option which is safe to use, unlike the -a option that some file system checkers support.
Kind of lame that fsck will allow you to run a command that could damage the filesystem it’s supposed to be diagnosing!
Anybody know if the Mac’s Disk Utility uses fsck for its disk repair operations?
Disk Utility works almost the same way as fsck except that it comes with a GUI that makes it easier to work with.
Ok…i think I`ve just kind of destroyed my external HDD.
I was pretty sure that it wasn`t mounted…but it seems that i was wrong. Now I`m stuck with an external HDD which is not accessible neither from Ubuntu nor from Windows…!
Well is there anything that i can do in order to save it or it is to late?
To make sure you have no problems with using fsck with mounted partitions, run it only after rebooting from a LiveCD.
Comments are closed.
Popular Posts
RedMagic 6S Pro Review: Gaming Is Serious Business.
How to Boot to Recovery Mode (Safe Mode) in Ubuntu
Ubuntu Software Center Not Working? Here Are the Fixes
How to Stress Test a Graphics Card on Linux
How to Mount a Windows Share Folder on Linux
How to Mount Your iPhone as an External Drive in Ubuntu
How to Fix Ubuntu Freezing in VirtualBox
How to Fix «Repository Does Not Have Release File» Error
How to Reset the Root Password in Linux
How to Combine PDF Files on Windows and Linux
8 Reasons to Switch from Windows to Linux
Affiliate Disclosure: Make Tech Easier may earn commission on products purchased through our links, which supports the work we do for our readers.
Источник