logo

Let’s Work Together

Partner with you to deliver responsive and cost-effective IT & Support solutions
Reponsive
Cost-Effective
Partner with you
Focus
Attitude to Serve
Professional
These are the reasons why AionSolution is your vendor when you are seeking someone to support your IT in your office.
info@aionsolution.com
+852 2636 6177

How to Repair a corrupted filesystem in Ubuntu

You can repair a corrupted filesystem with the program “fsck”.The system utility fsck (for “file system check” or “file system consistency check”) is a tool for checking the consistency of a file system in Unix and Unix-like operating systems such as Linux.


Note:- File systems must be unmounted, you cannot repair them while they are running.So fsck must ALWAYS be run on an UNmounted filesystem. Running fsck on a mounted filesystem can do SEVERE damage.

A quick fsck options overview:

Many options for fsck exist, but the most important are:
-f which performs a FAST check
-p which fixes minor problems without user interaction
-y which gives permission to correct every problem found
-n which indicates to only search (and not correct) problems

The most simple variant to run fsck is to force fsck on restart, and then restart your system:

sudo touch /forcefsck

The other option is to swich the system to runlevel 1 (logs-out any userRunning fsck on a mounted filesystem can do SEVERE damage), unmount all partitions. run fsck & repair, remount all drives, increase the runlevel to 3 and continue.

1) Take system down to runlevel one (make sure you run all command as root user):
# init 1

2)Unmount file system, for example if it is /home (/dev/sda3) file system then type command:

# umount /home

OR

# umount /dev/sda3

3) Now run fsck on the partition:

# fsck /dev/sda3

However be sure to specify the file system type using -t option. Recenly one of our sys admin run the command on ext3 file system w/o specifying file system. Result was more corruption as fsck by default assumes ext2 file system.

# fsck -t ext3 /dev/sda3

OR

# fsck.ext3 /dev/sda3

Tip if you don’t know your file system type then typing mount command will display file system type.

fsck will check the file system and ask which problems should be fixed or corrected. If you don’t wanna type y every time then you can use pass -y option to fsck.

# fsck -y /dev/sda3

Please not if any files are recovered then they are placed in /home/lost+found directory by fsck command.

4) Once fsck finished, remount the file system:

# mount /home

5) Go to multiuser mode

# init 3

Read man page of fsck for more information. Make sure you replace /dev/sda3 with your actual device name.