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.

  1. Your /home partition, either unharmed or restored from backup
  2. A Live DVD to upgrade/reinstall the system
  3. A list of installed programs
  4. Your configuration files from the /etc directory

Advance Preparation
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:

./disasterprep

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,

  1. Boot the installation DVD for your release of Ubuntu.
  2. Start the installation process. When you reach the Prepare disk space stage of installation, choose the Manual option and press Forward.
  3. 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.
  4. Identify your swap partition and set its mount point as ‘swap’.
  5. Identify your /home partition. Set its mount point as ‘/home’ and make sure that Format is not ticked.
  6. 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.
  7. Complete the installation as normal
  8. Reboot into your reinstalled system
  9. .

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:

sudo launchpad-getkeys

Reinstall packages
Use:
dpkg --set-selections < /path-to-your-backup-location/installed-software
deselect

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: