Manual Fsck

Active Oldest Votes. Running fsck /dev/sda6 should fix it. What most likely happened was that your unclean shutdown left the filesystem in a inconsistent state, and to avoid further damaging it, Ubuntu doesn't want to boot until it's fixed. A mates computer is bringing up a message upon boot (The root file system on /dev/sda1 requires a manual fsck.) How does one do this given that Mint hasn't started so there is no Terminal even if I knew the commands. Mint 18.3 Thanks. Press a key to modify the boot options. Then, type a space and add the word single. This will boot the server in single user mode. Further, to do a complete file system check, we use the following command. Similarly, we use e2fsck command to do file system check on a single partition. The fsck command is a wrapper for the various Linux filesystem checkers (fsck.) and accepts different options depending on the file system’s type. Check the manual pages for more information about a specific checker. For example, to view the options available for fsck.ext4, type: man fsck.ext4 Repair Corrupted File System #.

Linux fsck utility is used to check and repair Linux filesystems (ext2, ext3, ext4, etc.).

Depending on when was the last time a file system was checked, the system runs the fsck during boot time to check whether the filesystem is in consistent state. System administrator could also run it manually when there is a problem with the filesystems.

Make sure to execute the fsck on an unmounted file systems to avoid any data corruption issues.
This article explains 10 practical examples on how to execute fsck command to troubleshoot and fix any filesystem errors.

1. Filesystem Check on a Disk Partition

First, view all the available partitions on your system using parted command as shown below.

You can check a specific filesystem (for example: /dev/sda6) as shown below.

The following are the possible exit codes for fsck command.

  • 0 – No errors
  • 1 – Filesystem errors corrected
  • 2 – System should be rebooted
  • 4 – Filesystem errors left uncorrected
  • 8 – Operational error
  • 16 – Usage or syntax error
  • 32 – Fsck canceled by user request
  • 128 – Shared-library error

Manual Fsck

2. Fsck Command Specific to a Filesystem Type

fsck internally uses the respective filesystem checker command for a filesystem check operation. These fsck checker commands are typically located under /sbin.

The following example show the various possible fsck checker commands (for example: fsck.ext2, fsck.ext3, fsck.ext4, etc.)

fsck command will give you an error when it doesn’t find a filesystem checker for the filesystem that is being checked.

For example, if you execute fsck over a ntfs partition, you’ll get the following error message. There is no fsck.ntfs under /sbin. So, this gives the following error message.

3. Check All Filesystems in One Run using Option -A

You can check all the filesystems in a single run of fsck using this option. This checks the file system in the order given by the fs_passno mentioned for each filesystem in /etc/fstab.

Please note that the filesystem with a fs_passno value of 0 are skipped, and greater than 0 are checked in the order.

The /etc/fstab contains the entries as listed below,

Here, the filesystem with the same fs_passno are checked in parallel in your system.

It is recommended that you exclude the root filesystem during this global check by adding -R option as shown below.

Note: Option -y is explained in one of the examples below.

4. Check Only a Specific Filesystem Type using Option -t

Using fsck -t option, you can specify the list of filesystem to be checked. When you are using with option -A, the fsck will check only the filesystem mentioned with this option -t. Note that fslist is a comma separated values.

Manual fsck ubuntu

Now, pass ext2 as the fslist value to -t option as shown below:

In this example, /dev/sda6 is the only partition created with the filesystem ext2, thus it get checked accordingly.

Using the keyword ‘no’ in front of filesystem, you can check all other filesystem types except a particular filesystem.

In the following example, ext2 filesystem is excluded from the check.

5. Don’t execute Fsck on Mounted Filesystem using Option -M

It is a good idea to use this option as default with all your fsck operation. This prevents you from running fsck accidentally on a filesystem that is mounted.

As shown above, /dev/sda7 is mounted. If you try to execute fsck on this /dev/sda7 mounted filesystem (along with the -M option), fsck will simply exit with the exit code 0 as shown below.

6. Skip the Display Title using Option -T

Using option -T, you can skip the title get displayed in the beginning of fsck command output.

Note that the title is something like “fsck from util-linux 2.20.1”.

7. Force a Filesystem Check Even if it’s Clean using Option -f

By default fsck tries to skip the clean file system to do a quicker job.

You can force it to check the file system using -f as shown below.

8. Attempt to Fix Detected Problems Automatically using Option -y

In the following example, /dev/sda6 partition is corrupted as shown below.

As seen above, the directory Movies and a file test attributes are invalid.

In the following example, -y will pass “yes” to all the questions to fix the detected corruption automatically.

9. Avoid Repair, but Report Problems to Stdout using Option -n

It is possible to print such detected problems into stdout without repairing the filesystem using fsck -n option.

First, you could notice/see the problem in partition /dev/sda6 that the Movies directory (and fwh file) doesn’t have valid attribute details.

The above problem in the specific partition displayed in stdout without doing any fix on it as follows,

The following fsck example displays the problem in the stdout without fixing it. (partial output is shown below).

10. Automatically Repair the Damaged Portions using Option -a

Manual Fsck

Manual fsck linux mint

In order to repair the damaged portion automatically ( without any user interaction ), use the option -a as shown below.

The option -a is same as -p in e2fsck utility. It cause e2fsck to fix any detected problems that has to be safely fixed without user interaction.

In case when fsck requires administrator’s attention, it simply exits with error code 4 before printing the description of the problem.

As you remember, fsck -y option can be used here to fix the above issue automatically.

Two days ago I corrupted my file system during a failed resume from standby on Fedora 19. This feature has never quite worked correctly and randomly makes the kernel panic. Usually, I hard reboot my laptop and everything is fine but that time, something went wrong and when it came back up:

Manual Fsck Check

In this case /dev/sda2 is my root partition and since it was mounted even in maintenance mode, attempting to run fsck on it would output:

Which makes sense as common knowledge tells us that running fsck on a mounted file system will most likely do more damage to it.

The best option

Your best option is simply to boot into another Linux, be it on a different partition, a USB drive or a CD and run fsck manually on the faulty partition, which can easily be unmounted if necessary because no OS is using it. Easy. Normally yes, but my stupid Macbook Pro 2008 cannot boot though USB into anything else other than Mac OS X, my cd drive has been dead for years and recently, I got rid of my OS X partition. To make things more complicated, I’m in Thailand at the moment and obviously not able to take apart my computer to grab the hard drive and stick into a working system.

The other option (if you cannot boot into another Linux)

Manual fsck required

In order to assess the damage, I ran fsck in dry-run mode and piped the output to more to make reading more practical:

From there, I could ensure that no critical files had been damaged and while keeping in mind that it’s always a gamble to use a corrupted file system, I proceeded to boot into the system to make some backups. That out of the way, I did some research on the web on how to fix a root file system that I had to boot into and sadly, not many things turned up for its not an ideal solution. Forcing the system to do it a boot time by creating a file named forcefsck and writing y in it (echo y > /forcefsck) at root no longer works and adding fsck.mode=force on the kernel command line did not fix the problem as fsck will not fix errors on its own without authorization, ie: someone to enter yes on the keyboard. Tried a few other tricks but none worked. I had no choice but keep my fingers crossed and use the system as is.

A few days later, I decided to get back to the issue and while researching alternative solutions, I read that it was possible to fix errors on a read-only file system, which it turns out can also be used to boot into. And it worked, so for posterity here is the technique:

The Root File System Requires A Manual Fsck

  1. Put your root partition into read-only mode by modifying the faulty partition’s line on /etc/fstab (but remember your old settings):

    Note: If you’re already in maintenance mode at this point, you may be able to remount your file system in read only mode by running “mount -o remount,ro /” and skipping the reboot (thanks Jay).

  2. Reboot
  3. Switch to runlevel 1 just to minimize the amount of interfering processes (skip this step if you are running the session over SSH [thanks Josh]):
  4. Fix your file system (replace /dev/sda2 with your partition’s device), which should now work because the root partition is in read only:
  5. Reboot
  6. Make your root file system readable/writable:
  7. Restore your /etc/fstab to its original state.
  8. Reboot

Manual Fsck Linux

Fsck

Voilà, your system is safe to use again. Hopefully this will have gotten you out of a sticky situation like it did for me. If errors keep coming up, it’s probably a sign that your hard-drive is failing and before you loose it completely, you should mirror your data to a new one.