Whether you are an experienced Linux administrator or an elite Linux user, dealing with Linux file system errors can be a headache for anyone. However, this headache has a valid prescription if you can pinpoint or identify the filesystem partition that is causing your Linux OS to have performance issues.
Most Linux operating systems come preconfigured with the fsck (file system check) terminal-based utility. This file repair tool requires that the immediate Linux user be familiar with the basic understanding and usage of the Linux command line environment and its associated commands.
FSCK Usage
The standard syntax for fsck command-line utility is as follows:
# fsck [COMMAND_OPTIONS] [TARGETED_FILESYSTEM]
To comfortably use fsck utility without running into any issues, you need to be a root or Sudoer user on your Ubuntu system. Sudo privileges are necessary for the correct execution of the fsck command.
There are a number of important rules to follow before attempting file system repair using the fsck command.
- Use the fdisk -l command to identify the existing OS system partition labels associated with the filesystem you are interested in repairing.
- Unmount the filesystem partition you identified from the above step (umount /dev/sdx) to give fsck full diagnosis and repair power on any identifiable OS file system issues.
- Execute the fsck command (fsck -p) on the unmounted filesystem partition.
- Remount the filesystem partition and reboot your machine if necessary.
How to Use FSCK to Repair Ubuntu File System Errors
There are two approaches to fixing file system errors on a Ubuntu partition using the fsck utility.
Repairing Ubuntu Non-Root File System Partitions
Non-root file systems do not require you to reboot your Ubuntu OS to attempt file system repair from the Grub menu’s Advanced Options. It can be an OS file system existing on an external USB drive.
1. From your terminal environment, identify the device name with the corrupted file system you wish to repair using the following command:
$ sudo fdisk -l
From my end, I have identified the file system partition I am interested in as /dev/sdb3.
2. Make sure that this file system partition is unmounted.
$ sudo umount /dev/sdb3
3. Attempt file system partition repair using the fsck utility command. The -p
option will automatically attempt file system repair on any identifiable broken OS files.
$ sudo fsck -p /dev/sdb3
As expected, the command was executed successfully as per the above fsck command output.
4. Now that the fsck command is through with fixing the file system partition, it is time to remount it.
$ sudo mount /dev/sdb3
Repairing Ubuntu Root File System Partition
Since you cannot unmount an active file system, it is impossible to attempt filesystem repair using fsck on a running OS. However, this step is achievable when the operating system is booting. We just need to instruct the OS to run an FSCK check and attempt file repair when the system restarts.
1. Force fsck to run once during system restart by creating the following file on your root (/forcefsck) OS file system will achieve this objective.
$ sudo touch /forcefsck
FSCK is forced to run once your system restarts. However, this file is deleted by the OS once fsck finishes executing. You will need to create it each time you want to attempt file system repair during reboot.
2. Force fsck to run after specified system reboots, this option is a more permanent solution.
$ sudo tune2fs -c 2 /dev/sda2
From the above command, the filesystem partition /dev/sda2
will be scanned and repaired after every 2 system boots. You can set this value to any positive integer value like 9 or 15.
File system errors can be a nightmare for any OS user and might even force you to reinstall your operating system. Learning how to deal with them saves you precious time and improves your OS productivity and experience.