Upgrade Debian based system

We want to upgrade Linux Mint 18.2 to version 20, and we don’t want to go through 3 upgrades to get it done. Instead we will make a proper inventory of the current system, back up all the stuff we want to keep and install Mint 20 from scratch. This approach should work fine for all Debian based systems.

If you want the possibility to get back to your previous system, make sure to make a full backup and keep it safe somewhere, but in most cases it’s best to move to current affairs and deal with possible trouble by fixing the issues in the new system.

  1. Back up your software selection
    ~$ mkdir software
    ~$ cd software
    ~$ dpkg --get-selections > ./package.list
    ~$ sudo cp -R /etc/apt/sources.list* ./
    ~$ sudo apt-key exportall > ./repo.keys
  2. Take a look at /opt to see what additional software you added (outside the apt infrastructure so to say). Decide what you need to keep. I’d suggest you check if you can still find the sources and reinstall them in your new system, but always make sure you keep a backup of /opt.
  3. Backup your
    • /home
    • /etc
    • /opt
    • /usr/local/
    • /usr/share/
    • /var/lib/
    • /var/mail/
    • /var/www/
    • /var/games/
    • /var/backups/
    • /var/local/
    • /var/opt/
    ~$ sudo tar -cvzpf /media/data/backup.tar.gz /etc/ /home/ /opt/ /usr/local/ /usr/share/ /var/lib/ /var/mail/ /var/www/ /var/games/ /var/backups/ /var/local/ /var/opt/
    where you substitute /media/data/ with the destination of your choice. Obviously the destination should be on a partition or drive that you’re not going to overwrite.
  4. Now that you’re sure about your backup, have a look at the partitions you used when you planned your previous install. Are these still valid for the way you work? Personally I have two internal drives, one with systems, one with data. I use external drives for backups and archives. Now my data drive is not my /home partition! Because I have more than one system, I need separate homes for each of them, otherwise my configuration files get compromised. So I symlink shared data folders like this:
    ~$ ln -s /media/data/Documents ./Documents
    That way, every system I run has its own settings, but data is shared through symbolic links to a separate partition. Make sure the data partition is initialised in fstab. Run the following in the shell: blkid /dev/sdXx (e.g. sda5) to find the UUID, then run
    ~$ sudo nano /etc/fstab
    and add
    UUID=what-you-just-found /media/data auto defaults,errors=remount-ro 0 1
  5. If you want to make any changes to your partition plan, do it in a live session with gparted.
  6. Now install the upgraded version via usb stick or whichever means you use. Always make sure the user name is the same to avoid a lot of hassle with rights afterwards.
  7. Make sure the systems runs correctly, check for updates and make sure your system is fully up to date.
  8. Restore your software choice
    ~$ sudo apt-key add ./repo.keys
    ~$ sudo cp -R ./sources.list* /etc/apt/
    ~$ sudo apt-get update
    ~$ sudo apt-get install dselect
    ~$ sudo dselect update
    ~$ sudo dpkg --set-selections < ./package.list
    ~$ sudo apt-get dselect-upgrade -y
  9. Reinstall the software you found in /opt/
  10. Personally, I would avoid copying your old /home into your new one, but if you do, be aware of hidden files you want to reinstate versus those you want to avoid. The hidden files and folders are the ones that start with a dot. Some are very useful to reinstate, like ~/.config/filezilla or ~/.config/vlc, but others might contaminate your new system, for instance ~/.config/libreoffice, ~/.gnome or /.mozilla. It’s up to you, but think it through and be careful. The data files can be copied back, or you can make symbolic links to them as described in item 4.
  11. Test your system to see if everything is working and if you’re not missing anything. You will find you have to tweak many things (like document types or dictionaries in libreoffice to name but one), but you can usually find everything you need in your backup or through an online search.