Simplify the Process of Restoring Your System from Scratch
If you have a recent offline backup of your system, use that. I make offline backups but I don’t like taking my system down for long periods. That means my backups are often old enough I’d rather just restore from scratch. I also use this process to migrate my system from one LTS version to another. To facilitate this process I’ve built system with a separate /home partition.
Therefore the process assumes your /home partition is available either from a backup or still okay.
To rebuild your system from scratch you’ll need four things.
- Your /home partition, either unharmed or restored from backup
- A Live DVD to upgrade/reinstall the system
- A list of installed programs
- Your configuration files from the /etc directory
Start by making and setting aside a Live DVD, the same release as you are running.
Open gedit or nano to create a script containing:
sudo dpkg --get-selections > /path-to-your-backup-location/installed-software sudo rsync -rvz /etc path-to-your-backup-location rsync -avz /home/your-username path-to-your-backup-location
where your-backup-location is on a separate disk or a networkshare.
Save the file in your home directory as disasterprep. Then open nautilus, right click on the file disasterprep, select properties and tick executable to make the script executable.
To complete preparations, open terminal and type:
You can rerun this command periodically to keep your backups reasonably up to date.
IF/WHEN DISASTER STRIKES:
If you are rebuilding because of a drive crash you will also need a new hard disk. But assuming your old disk is usable,
- Boot the installation DVD for your release of Ubuntu.
- Start the installation process. When you reach the Prepare disk space stage of installation, choose the Manual option and press Forward.
- Identify your current ‘/’ (root) partition. Select ‘/’ as the mount point and ensure that Format is ticked. You will lose all data on this partition and the new version of Ubuntu will be installed there instead. This shouldn’t be a problem because you wouldn’t be doing this step unless your system was hosed.
- Identify your swap partition and set its mount point as ‘swap’.
- Identify your /home partition. Set its mount point as ‘/home’ and make sure that Format is not ticked.
- Continue installation as normal until you reach the Who are you? stage, enter a username and password which exactly matchs your old username and password.
- Complete the installation as normal
- Reboot into your reinstalled system
At this point you should be running a stock Ubuntu install plus your original home directory. All that remains is to reinstall your packages and recover any configuration files.
Reinstall any Custom Repositories
If you had any custom repositories on your old system they were in /etc/apt/sources.list.d, you will need to copy them to your new system before you reinstall packages. But first you need to install a program to restore the required GPG keys once you copy over your repositories:
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install launchpad-getkeys
Then restore your repositories:
sudo rsync /path-to-your-backup-location/etc/apt/sources.list.d/ /etc/apt/sources.list.d
and update your GPG keys:
dpkg --set-selections < /path-to-your-backup-location/installed-software
Then recover any needed configuration files from your saved copy of /etc
Examples might include:
/etc/fstab /etc/resolv.conf /etc/network/interfaces /etc/samba/smb.conf /etc/apt/sources.list