How to Recover a Damaged File System in Ubuntu

Use Ubuntu tools to repair a corrupted file system.
... John Foxx/Stockbyte/Getty Images

When a file system gets corrupted or damaged, your first instinct may be to reinstall a copy of the operating system. However, not only is this inconvenient, it can also mean possibly hours spent reinstalling software on the system. In many cases, you may be able to avoid reinstallation by recovering the damaged file system using tools that are either already part of Ubuntu, or tools you can get via Ubuntu.

1 Obtaining Ubuntu

Whether you are trying to repair an Ubuntu or Windows file system, you need to have a copy of the Ubuntu ISO disc image, available on their website. Once downloaded, you can burn the image to a DVD or create a USB boot drive with UNetbootin (link in Resources). The benefit of using USB is that you can save files to it after making the Ubuntu image, which allows you to download extra tools, if necessary.

2 Creating a USB Boot Drive

Insert a USB drive that is at least 2GB in size. Start UNetbootin, select the “Diskimage” option, and then use the button labeled “...” to locate your Ubuntu ISO. Select the amount of space -- at least 100MB -- to allocate for files that can be saved to the drive after installation. Make sure your USB drive is selected, and then click the “OK” button. Use the drive to boot the affected computer. Many systems have a boot menu that you can access with “F12,” but if yours does not, refer to the owner's manual for instructions on how to change the boot order.

3 Using Fsck or NTFSFix

Before starting the repairs, find out some information about the disk, using the Terminal application. Start it by pressing the button with the Ubuntu logo, typing “terminal,” and then clicking the icon. Follow each command with the “Enter” key. The first command below lists all the internal disks and partitions by device name. For example, in “/device/sda1,” the “/dev/” is the mounting directory, and the first serial-connected hard disk is labeled “sda,” while a second would be “sdb.” The first parallel drive would be “hda.” The number following the disk is the partition number. For Windows machines, the partition that needs to be repaired is generally the largest one with the NTFS system type. For Ubuntu machines, the main file system is typically on the lowest-numbered Linux partition. To find the file system type of a Linux partition, use the second command for the appropriate disk, such as “sda” -- it will list either EXT2, EXT3 or EXT4. The third command prevents damage by unmounting the file system; replace ”sda1” with the correct partition:

sudo fdisk -l sudo parted /dev/sda 'print' “umount /dev/sda1”

To repair the Ubuntu file system, use the first command below; for Windows, use the second, replacing “sda1” and “ext2” with the correct values:

fsck.ext2 -y /dev/sda1 ntfsfix /dev/sda1

4 Repairing the Bootloader or MBR

If the bootloader on an Ubuntu machine is no longer working, reinstall it by using this command:

grub-install /dev/sda1

If the MBR on a Windows machine is corrupted, issue these commands:

sudo apt-get install lilo sudo lilo -M /dev/sda1 mbr

When finished repairing the file system, reboot the machine with the regular operating system, and then double-check everything with the built-in disk-scanning software.

David L. Secor is a computer repairman and writer from west Texas. He has been writing informational articles on a wide variety of subjects since approximately 2005. When not writing, he scours the desert for interesting photos, often ending up with nothing but embedded thorns for his efforts.

×