Ubuntu System Rescue
When your Ubuntu system refuses to boot or experiences critical issues, knowing how to rescue it becomes an essential skill. This guide will walk you through the various methods and tools available for Ubuntu system rescue operations.
Introduction
System rescue in Ubuntu refers to the process of recovering your operating system when it encounters serious problems that prevent normal operation. These issues might include:
- Failed boot process
- Corrupted file systems
- Broken package installations
- Misconfigured system files
- Hardware detection problems
- Kernel panic situations
Learning rescue techniques not only helps you recover from disasters but also provides deeper understanding of how Ubuntu works under the hood.
Rescue Tools and Methods
Ubuntu Recovery Mode
The recovery mode is your first line of defense when Ubuntu won't boot normally.
Accessing Recovery Mode
- Restart your computer
- When the GRUB menu appears, select "Advanced options for Ubuntu"
- Choose the kernel version with "(recovery mode)" appended to it
- You'll see the Recovery Menu with several options
Recovery Menu Options
- Resume: Continue normal boot process
- Clean: Free up disk space
- dpkg: Repair broken packages
- fsck: Check and repair filesystem
- grub: Update GRUB bootloader
- network: Enable networking
- root: Drop to root shell prompt
- system-summary: Display system information
Using Root Shell for Repairs
The root shell option is particularly useful for advanced repairs:
# Check and repair file system
fsck /dev/sda1
# Remount root filesystem with write permissions
mount -o remount,rw /
# Fix broken package issues
apt update
apt --fix-broken install
# Reconfigure packages
dpkg-reconfigure package-name
Ubuntu Live USB
When recovery mode isn't accessible or sufficient, a Live USB becomes your next best option.
Creating a Live USB
- Download the Ubuntu ISO from the official website
- Create a bootable USB using tools like:
- Etcher (cross-platform)
- Rufus (Windows)
- Startup Disk Creator (Ubuntu)
- dd command (Linux)
# Example using dd on Linux
sudo dd bs=4M if=path/to/ubuntu.iso of=/dev/sdX status=progress oflag=sync
Booting from Live USB
- Insert the USB drive into the affected computer
- Restart and access your BIOS/UEFI boot menu (usually F12, F2, or Del key)
- Select your USB device to boot from
- Choose "Try Ubuntu without installing"
Rescue Operations from Live USB
File Recovery
Mount your system drives to recover important files:
# Create mount point
sudo mkdir /mnt/system
# Mount the root partition
sudo mount /dev/sdXY /mnt/system
# For separate home partition
sudo mount /dev/sdXZ /mnt/system/home
# Access your files
cd /mnt/system/home/username
Repair GRUB Bootloader
# Mount necessary filesystems
sudo mount /dev/sdXY /mnt/system
sudo mount --bind /dev /mnt/system/dev
sudo mount --bind /proc /mnt/system/proc
sudo mount --bind /sys /mnt/system/sys
# Chroot into your system
sudo chroot /mnt/system
# Update and reinstall GRUB
update-grub
grub-install /dev/sdX
# Exit chroot and reboot
exit
sudo reboot
Fix Package Management
# Inside chroot environment
apt update
apt --fix-broken install
dpkg --configure -a
apt clean
apt autoremove
Boot-Repair Tool
Boot-Repair is a specialized tool for fixing boot issues in Ubuntu and other Linux distributions.
Installing Boot-Repair on Live USB
sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt update
sudo apt install boot-repair
Using Boot-Repair
- Launch Boot-Repair:
boot-repair
- Choose "Recommended repair" for automatic fixes
- Follow the on-screen instructions
- Boot-Repair will generate a URL with diagnostic information if needed
SystemRescue Live Environment
For advanced users, SystemRescue (formerly SystemRescueCd) provides specialized tools beyond what Ubuntu Live offers.
Key Features
- Lightweight environment focused on system repair
- Advanced partitioning tools
- File recovery utilities
- Network diagnostics
- Password reset capabilities
Common Rescue Scenarios
Scenario 1: Ubuntu Won't Boot After Updates
Step-by-Step Solution:
- Boot to GRUB menu and select an older kernel version
- If successful, open terminal and run:
sudo apt update
sudo apt install --reinstall linux-generic
sudo update-grub
- If older kernel doesn't work, use Live USB to chroot and fix:
# From Live USB after mounting and chrooting
apt update
apt install --reinstall linux-generic
update-grub
Scenario 2: Fixing a Corrupted File System
- Boot to recovery mode or Live USB
- Run file system check:
# From recovery mode
fsck -f /dev/sdXY
# From Live USB (don't run fsck on mounted partitions)
sudo umount /dev/sdXY
sudo fsck -f /dev/sdXY
- If bad blocks are suspected:
sudo badblocks -v /dev/sdXY > bad-blocks
sudo fsck -l bad-blocks /dev/sdXY
Scenario 3: Resetting a Forgotten Password
- Boot to recovery mode
- Select root shell
- Remount filesystem with write permissions:
mount -o remount,rw /
- Change the user's password:
passwd username
- Reboot:
reboot
Scenario 4: Recovering from a "No Space Left" Error
When your system crashes due to filled disk space:
- Boot to recovery mode
- Select "Clean" option or use root shell
- Identify large files:
du -h --max-depth=1 /var
du -h --max-depth=1 /var/log
- Clean up old logs and cache:
apt clean
journalctl --vacuum-time=3d
find /var/log -type f -name "*.gz" -delete
Advanced Rescue Techniques
Using Chroot for System Repair
Chroot ("change root") is a powerful technique that allows you to operate inside your installed system from a Live environment.
# Mount your system
sudo mount /dev/sdXY /mnt
# For UEFI systems, mount the EFI partition
sudo mount /dev/sdXZ /mnt/boot/efi # if needed
# Bind essential directories
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
# Enter chroot environment
sudo chroot /mnt
# Now you can run commands as if booted into your system
# For example, to reinstall the desktop environment:
apt install --reinstall ubuntu-desktop
# Exit chroot when done
exit
# Unmount everything before rebooting
sudo umount -R /mnt
Repairing Disk with SMART Tools
When hardware issues are suspected:
# Install smartmontools from Live USB
sudo apt install smartmontools
# Check disk health
sudo smartctl -H /dev/sda
# Run short test
sudo smartctl -t short /dev/sda
# View test results
sudo smartctl -l selftest /dev/sda
Emergency File Recovery with TestDisk and PhotoRec
For recovering deleted files or damaged partitions:
# Install tools
sudo apt install testdisk
# Launch TestDisk for partition recovery
sudo testdisk
# Launch PhotoRec for file recovery
sudo photorec
Preventive Measures
Creating System Backups
# Using Timeshift
sudo apt install timeshift
sudo timeshift --create --comments "Before system update"
# Using rsync for manual backup
sudo rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup
Setting Up Boot Log Analysis
# View boot logs
journalctl -b
# Previous boot logs
journalctl -b -1
# Export boot logs for analysis
journalctl -b > ~/boot-log.txt
Automated System Checks
Create a weekly system check script:
#!/bin/bash
# Save as /etc/cron.weekly/system-check.sh
# Check disk space
df -h > /var/log/system-check/disk-space.log
# Check for broken packages
dpkg --audit > /var/log/system-check/dpkg-audit.log
# Run filesystem check on next boot for root partition
touch /forcefsck
# Make executable
chmod +x /etc/cron.weekly/system-check.sh
Summary
Ubuntu system rescue is a critical skill for any Linux user or administrator. By understanding the various recovery tools and techniques, you can confidently address system failures when they occur. Remember these key points:
- Always start with the least invasive method (Recovery Mode)
- Keep a Live USB ready for emergencies
- Learn basic command-line tools for system repair
- Implement regular backups to minimize data loss
- Document your system configuration for reference
With practice, you'll develop the skills to diagnose and resolve even complex system failures, turning potential disasters into manageable challenges.
Additional Resources
- Ubuntu Community Help Wiki: Recovery Mode
- Ubuntu Forums (Troubleshooting section)
- Manual pages:
man fsck
,man mount
,man chroot
Practice Exercises
- Create a Ubuntu Live USB and practice booting into it
- Simulate a GRUB failure and repair it using Live USB
- Practice using chroot to modify system files from a Live environment
- Set up an automated backup strategy for your important files
- Create a personal rescue checklist based on this guide
If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)