zaro

How to recover corrupted Ubuntu?

Published in Ubuntu Recovery 5 mins read

Recovering a corrupted Ubuntu system involves diagnosing the underlying issue and applying specific repair techniques, from file system checks to bootloader repairs.

Common Signs of a Corrupted Ubuntu System

Recognizing the symptoms of corruption can help narrow down the recovery approach:

Symptom Possible Cause
System won't boot Corrupted bootloader (GRUB), file system errors
Applications crash frequently Corrupted system files, disk errors
Slow performance File system issues, fragmented files
Errors during boot-up Missing system files, kernel issues
Missing or inaccessible files File system corruption, disk failure

Step-by-Step Recovery Methods

Here are the primary methods to recover your corrupted Ubuntu installation.

Method 1: Checking and Repairing the File System (fsck)

File system corruption is a common cause of Ubuntu boot failures and instability. The fsck (file system check) utility can scan for and repair errors on your disk partitions.

To perform a file system check:

  1. Boot to the GRUB menu: As your computer starts, press and hold the Shift key (or repeatedly tap Esc or F12, depending on your system) to access the GRUB boot menu.
  2. Choose Advanced Options: Navigate to "Advanced Options for Ubuntu" using the arrow keys and press Enter.
  3. Select Recovery Mode: From the next menu, choose the entry that ends with "(recovery mode)" and press Enter.
  4. Gain Root Access: In the recovery menu, select "root - Drop to root shell prompt" and press Enter. You will be at a root@your-system:~# prompt.
  5. Run fsck: At the prompt, type the following command and press Enter:
    sudo fsck -f /
    • sudo: Grants administrative privileges.
    • fsck: The file system consistency check and repair utility.
    • -f: Forces fsck to check, even if the file system appears clean.
    • /: Specifies the root file system for checking.
  6. Repeat if necessary: If fsck reports errors, repeat the command (sudo fsck -f /) until no more errors are reported.
  7. Reboot your system: Once the file system is clean, type reboot and press Enter to restart your computer.

Method 2: Repairing the GRUB Bootloader

If Ubuntu fails to boot and you see a GRUB prompt or an error message about "No such device," your GRUB bootloader might be corrupted. This often happens after installing another operating system or due to disk changes. The easiest way to fix GRUB is by using a Live USB of Ubuntu.

  1. Create a Live Ubuntu USB:
    • Download the Ubuntu ISO image from the official Ubuntu website (ubuntu.com).
    • Use a tool like Rufus (for Windows), Etcher (cross-platform), or dd (for Linux) to create a bootable USB drive.
  2. Boot from the Live USB:
    • Insert the USB drive and restart your computer.
    • Access your BIOS/UEFI settings (usually by pressing F2, F10, F12, or Del during startup) and set the USB drive as the first boot device.
    • Choose "Try Ubuntu" when the Live USB boots.
  3. Install and Use Boot-Repair:
    • Once in the Live Ubuntu environment, open a terminal (Ctrl+Alt+T).
    • Add the Boot-Repair PPA and install it:
      sudo add-apt-repository ppa:yannubuntu/boot-repair
      sudo apt update
      sudo apt install -y boot-repair
    • Launch Boot-Repair from the applications menu.
    • Click on "Recommended repair." Boot-Repair will automatically detect and fix most bootloader issues.
    • Follow any on-screen prompts and then reboot your system after it completes.

Method 3: Accessing and Backing Up Data from a Live USB

If your Ubuntu system is so corrupted that it won't boot at all, you can still recover your important files by using a Live Ubuntu USB.

  1. Boot from a Live Ubuntu USB: Follow steps 1 and 2 from "Method 2" to boot into the "Try Ubuntu" environment.
  2. Mount your Ubuntu partition:
    • Open the file manager (usually represented by a folder icon).
    • On the left sidebar, you should see your hard drive partitions listed. Click on your main Ubuntu partition (it's usually the largest one and might show a size like 100GB, 200GB, etc.). This will mount it, making its contents accessible.
    • If you're unsure which partition it is, open a terminal (Ctrl+Alt+T) and type lsblk to list your disk partitions and their sizes.
  3. Copy your data:
    • Navigate to your home directory within the mounted Ubuntu partition (e.g., /media/ubuntu/YourUbuntuPartition/home/yourusername).
    • Copy all your essential files, documents, pictures, and other data to an external hard drive, another USB stick, or a cloud storage service.

Method 4: Reinstalling Ubuntu (Last Resort)

If all else fails, a fresh installation of Ubuntu might be necessary. This can resolve deep-seated corruption but should be considered a last resort as it may overwrite your existing data.

  1. Back up your data: Crucially, perform a data backup using Method 3 before proceeding.
  2. Boot from a Live Ubuntu USB: Follow steps 1 and 2 from "Method 2."
  3. Choose "Install Ubuntu":
    • When the Live USB boots, select "Install Ubuntu" instead of "Try Ubuntu."
    • Follow the installation wizard.
    • Crucial Step: When you reach the "Installation type" screen, choose "Something else." This option allows you to manage partitions manually.
    • Select your existing Ubuntu partition (usually formatted as ext4) and choose to reformat it and mount it as /.
    • Be extremely careful not to erase other partitions if you have Windows or other operating systems installed.
    • Alternatively, for a complete wipe and fresh start, you can choose "Erase disk and install Ubuntu."

Prevention is Key

To minimize the risk of future corruption:

  • Regular Backups: Implement a routine backup strategy for your critical data. Tools like Timeshift can create system snapshots.
  • Safe Shutdowns: Always shut down your system properly. Avoid forced shutdowns unless absolutely necessary.
  • Monitor Disk Health: Use tools like gnome-disks or smartctl to monitor your hard drive's health.
  • Keep System Updated: Regularly apply system updates to benefit from bug fixes and security patches.