Quick and easy upgrade/reinstall of Ubuntu

By | May 1, 2010

This post explains how to reinstall Linux without using a cd/dvd, usb disk/pen drive, network boot or install partition. It requires internet-access from the machine you’re reinstalling and it requires the Grub boot loader to be installed, which most new Linux-systems installs (Ubuntu, Debian and Suse uses Grub) . If you have a dedicated partition to /home, you’ll likely not need to take backup first.

I don’t particularly like burning CDs, DVDd or writing special installer images to usb pen drives to install/reinstall Ubuntu. The pen drive boot option can be quick and easy, but you have to get a pen drive first, or find the one(s) you have laying about somewhere.

Backing up your files if necessary

If you don’t have all your user files at a dedicated /home partition, you’ll have to backup the files you want to keep to another drive or to some network location.
If this is a server, you’ll likely want to take a backup of /etc and /var, to keep logs and configuration files, for example your ssh host keys in /etc.

If you have important files on your system I advise you to make regular backups in any case, reinstalling or not 🙂

A neat trick I use, to save time reinstalling packages after reinstall, is to save the list of the currently installed packages and just automatically install all those packages after the OS-installation is complete.

To save the package list:
dpkg -l|awk 'NR > 5 {print $2}' > $HOME/mypackages.list

To restore packages from the list:
sudo aptitude install $(cat foo.list)

I often like to manually prune the list, just open mypackages.list in your favorite editor, and delete package names you don’t want.
If you want to install package-collections like ‘kubuntu-desktop’ or so after install, it’s best to do that before restoring your package list.

Preparing for reinstall

Get the initrd.gz file and the linux file from the netboot directory of the Ubuntu installer location. In my case I got the one for amd64 (x86-64) because I want a 64-bit system:
http://archive.ubuntu.com/ubuntu/dists/
For example: http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/

Copy the files to your grub boot directory. Assuming you downloaded the files to $HOME/tmp, this is done as follows:
sudo mkdir /boot/reinstall
sudo cp $HOME/tmp/linux /boot/reinstall/
sudo cp $HOME/tmp/initrd.gz /boot/reinstall/

Also make a note of your partition layout, so that you’ll know which partitions to choose during installation. To do so, just execute mount on the command line of your current Linux system to see which partitions are used for what. Of special interest are the partitions for /home and /. Example: /home is at /dev/sda8 and / is at /dev/sda5.

Actual reinstall

There is an excellent guide on how to boot the installer using Grub (easy) at
http://help.ubuntu.com/community/Installation/NetbootInstallFromInternet
which I won’t repeat.

This will launch the text-based installer. Choose manual partitioning, and to format your old / partition and preserve your /home partition. If you don’t have a /home partition, this is your chance to create one. In that case you split the / partition into two, using most of the space for /home and 15-20 GB for /, and reformat both of them.

Leave a Reply

Your email address will not be published. Required fields are marked *