No matter how well you adopt care of your personal machine, sometimes, it is going to just crash so you often have to drag off the plug to restart the pc. When such crashes happen, there exists a chance that your filesystem are certain to get corrupted or damage. It is advisable to execute a filesystem check regularly to be sure that it is running properly and clear of error.

In Linux (and Mac), there is certainly this powerful command “fsck” that you can use to check and repair your filesystem. “Fsck” means “File System Consistency checK”.

The usage is incredibly easy. Open a terminal and type:

fsck /dev/sda1

This will check the sda1 partition. An important thing to make note of is that fsck is not used on a mounted partition. If you do so, there exists a high chance that it'll damage the filesystem. To look at the Home folder that resides on another partition, say sda2, make use of the following commands:

umount /home fsck /dev/sda2

Note: you will need root/superuser permission to own the “fsck” command.

You also can use “fsck” to check external drive, like your thumb drive or SD card. For example:

umount /dev/sdb1 #thumb drive sudo fsck /dev/sdb1

If you aren't sure in the partition number, you can use the command

sudo fdisk -l

to list out all the partitions inside the system.

Advanced Usage

There are a few parameters that you can add to “fsck” to really make it more powerful.

Auto repair filesystem when errors are detected

During the filesystem check, if errors are detected, you will get “fsck” to auto repair the filesystem using the -a flag. For example:

fsck -a /dev/sda1

Similarly, using the -y flag could get the job done also:

fsck -y /dev/sda1

Check all filesystems a single run

If there are lots of filesystems in your personal machine, you may get fsck to check on all of them at the same time using the -A flag.

fsck -A

What it will do would be 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 in order to avoid it from scanning the root filesystem and fasten all errors, if there's any.

fsck -AR -y

Exclude review mounted filesystem

As mentioned earlier, fsck can't be run on a mounted filesystem. If you are with all the -A flag to scan each of the filesystems, and several of them are mounted, you may damage those filesystems. A way to overcome this can be to utilize -M flag to stop it from checking mounted system.

For example, running the command

fsck -M /dev/sdc1

returns nothing plus a return code 0 (which suggests “no error”). No scan was done at all since every one of 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 occasions when you just want to test filesystems of an specific type, say ext2. You can make technique -t flag to specify the filesystem type to evaluate. For example, the command

fsck -t ext4 /dev/sdc1

will scan the external drive only if it can be in the ext4 format. Alternatively, it is possible to combine with the -A flag to scan all filesystems from the specific type:

fsck -A -t ext4 -y

Force fsck to perform everytime during bootup

By default, Ubuntu will run fsck after every 30 bootups, however, if you want the machine to to perform “fsck” check everytime it boots up, all you have to do would be to create jail file call “forcefsck” and place it inside root folder. This will notify it to execute a “fsck” check everytime during boot up.

sudo touch /forcefsck

To alter the checking frequency, you'll be able to make standby time with the command “tune2fs“.

The following command instructs the system to perform “fsck” after every 30 boot up.

tune2fs -c 30 /dev/sdaX

You may also specify number of days as opposed to boot up:

sudo tune2fs -i 10d /dev/sdaX

Using fsck which has a GUI

As you can see, fsck is mainly a command line tool. If you need a GUI for your, GParted comes which has a feature that allows you to check your filesystem.

First, install GParted:

sudo apt-get install gparted

Next, open GParted and select the filesystem you want to test. Right click on it and select “Check”.

Conclusion

fsck is really a useful command that can look at your filesystem for errors and fix them automatically. Most of the time, you won’t need to bother with becoming your system in most cases run it regularly during boot around make sure everything is working fine. However, once your filesystem get corrupted, this is the easiest method to find out what happen and connect it.

Recent Posts

Latest From

About Us

Sharedtutor - Tutorials For Everyone

SharedTutor.com as site that provide collection of a lot of tutorials from around the world. SharedTutor.com is under Wins Co. company that build in 2010. All of materials in this site is a collections from Admin that shared to everyone that visit this site. So Enjoy surfing this site!!!