Pages
▼
How to Manually run file system checks [fsck] in Linux?
The ability to manually check for file system errors is an important function in any operating system, especially these days where the widespread use of external hard disk drivers is quite common.
The basic knowledge of knowing how to manually run a file system check in Linux, for instance, is very useful, because sometimes users physically remove USB storage devices just after the file manager has finished copying something. That can sometimes result in data loss. There's no need to dive into the complex details, but, operating systems do take a slight delay before they actually finish coping the data, even if your file manager says otherwise.
Such accidents are rare with non-removable storage devices, but with removable devices it can occur. Running the file system check does not guarantee the recovery of such data (because that's not its job), however, it'll at least give you a cleaned up file system, one that is less prone to file system corruptions that could occur in the future. Unlike in Microsoft Windows, Linux does not let you manually run file system checks from the file manager. Therefore, you either have to have installed an application manually (they do not usually come preinstalled) or you can always use the command-line to run the file system command that comes Linux.
Even if you are a new user, the procedure is quite simple and it is threefold. First you have to identify the partition(s). Make sure they are unmounted. In the third and final step, execute the command.
1. Identifying the partitions:
Whether they are mounted or unmounted, as long as the devices that hold these partitions are attached to the computer, you can use the fdisk command in Linux to get a list of all the available partitions. For this operation however, you will need administrative ('sudo') privileges. So you simply execute the fdisk command with administrative privileges in the terminal.
Open your terminal and enter the below command:
sudo fdisk -l
The l option guides the fdisk to print you a list of all the available partitions. So have a close look at the output you get and identify the hardware & the partition(s) that you want to manually check for errors. Here I'm trying to figure out the partition path|name of my USB disk drive which contains a single ext4 file system and it is labelled as 'My Passport...' and the path of its single partition is in this instance is /dev/sdc1 which is actually the information we're after.
Once you identify yours, then again with administrative privileges, execute the Linux's file system command (called 'fsck'). Here, below is the appropriate command for me:
sudo fsck /dev/sdc1
2. Making sure they are unmounted
If your partition is already mounted, then the fsck command will simply abort its operation for safety reasons (you do not want to check for errors inside an active|mounted file system).
In such instances, first you'll have to unmount the partition(s). For that, you can use the below command. Make sure to replace /dev/sdc1 accordingly:
sudo umount /dev/sdc1
3. A successful run
If it is already unmounted it'll run and let you know what it finds. As you can see below, it actually did find few minor errors (totally unintentional) and fixed them.
If you want a detailed output of its operation, then you should use the -v option which stands for verbose. Below is the same command as above, however, this time, it'll print out more details:
sudo fsck -v /dev/sdc1
Once it's finished its operation, you can either remove or mount the file system and carry on with your work. fcsk is however, not a magical tool. There are things it can fix and things it simply cannot and as mentioned, it is not a data recovery tool. Its function is to try to fix the file system by looking at it as a 'whole' rather than recover files by treating them individually, keep that in mind.
No comments:
Post a Comment