Friday, February 14, 2025

How to Manual Ubuntu Upgrade via APT

While the standard do-release-upgrade path might be broken for EOL releases, a manual upgrade via APT is your professional lifeline.

This guide provides a step-by-step walkthrough to manually upgrade your End-of-Life Ubuntu system using APT, ensuring a smooth transition, even when official repositories are no longer available. We'll focus on upgrading to the latest Long-Term Support (LTS) release, Ubuntu 24.04 LTS "Noble Numbat," but these principles apply to any version upgrade.

Understanding Ubuntu Releases and End-of-Life

Ubuntu's release cycle is structured to provide both cutting-edge innovation and long-term stability.

  • Interim Releases: Versions like Ubuntu 23.04 receive 9 months of support, ideal for users who want the newest features and software.
  • Long-Term Support (LTS) Releases: LTS versions, such as Ubuntu 22.04 LTS and the latest 24.04 LTS, are the workhorses, maintained for a rock-solid 5 years.

LTS releases are easily identifiable: they are major releases divisible by 2, with a minor release number of .04. Think 10.04, 16.04, 20.04, 22.04, and now 24.04.

Once an Ubuntu release reaches EOL, the standard repositories you rely on become archived and inaccessible. This is where do-release-upgrade often falters. But don't worry, we can take matters into our own hands!

Manual Ubuntu Upgrade via APT: The EOL Rescue Mission

When do-release-upgrade gives up due to missing repositories, a manual APT upgrade is your best bet. We'll essentially guide APT to use the old-releases repositories and then step-by-step, move your system to a supported version.

Here's the plan:

  1. Point APT to the Old Release Repositories: We'll modify your APT sources list to use old-releases.ubuntu.com, where EOL packages are archived.
  2. Update and Upgrade with Old Repositories: We'll use apt update and apt upgrade to bring your system packages up-to-date within the EOL release.
  3. Change Codename to the Next Ubuntu Release: We'll then modify the sources list again, pointing it to the repositories of the next Ubuntu version you want to upgrade to.
  4. Repeat Update and Upgrade for Each Release (If Necessary): If you're significantly behind, you'll repeat steps 3 and 4 incrementally until you reach your desired version, like Ubuntu 24.04 LTS "Noble Numbat."

Let's dive into the steps:

Step 1: Repointing APT Sources to old-releases.ubuntu.com

First, we need to tell APT to look at the archive of old releases. Execute these commands in your terminal:

Bash
sudo sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo sed -i 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

These commands use sed to replace all instances of archive.ubuntu.com and security.ubuntu.com in your /etc/apt/sources.list file with old-releases.ubuntu.com.

To verify the changes, you can use:

Bash
cat /etc/apt/sources.list

This will display the contents of your sources.list file, and you should see the old-releases.ubuntu.com URLs.

Step 2: Update and Upgrade with the Old Repositories

Now, update your package lists and upgrade your system using the archived repositories:

Bash
sudo apt update && sudo apt upgrade -y
sudo apt dist-upgrade -y
sudo apt autoremove -y

These commands will:

  • sudo apt update: Refresh the package lists from the old-releases.ubuntu.com repositories.
  • sudo apt upgrade -y: Upgrade all upgradable packages to their latest versions within the EOL release. The -y flag automatically answers "yes" to prompts.
  • sudo apt dist-upgrade -y: Perform a full distribution upgrade, handling dependency changes across packages.
  • sudo apt autoremove -y: Remove obsolete packages that are no longer needed.

Step 3: Changing the Ubuntu Codename to the Next Release (e.g., to 24.04 LTS "Noble Numbat")

To move to a newer Ubuntu version, we need to edit the sources.list file again, this time replacing the old release codename with the codename of your target release.

For example, if you are upgrading to Ubuntu 24.04 LTS "Noble Numbat" and your current codename (from the EOL release) is, for example, "mantic", you would use:

Bash
sudo sed -i 's/mantic/noble/g' /etc/apt/sources.list

Important: Replace mantic with the actual codename of your current EOL Ubuntu release and noble with the codename of your target release (in this case, noble for 24.04 LTS). You can find your current codename in /etc/os-release (look for VERSION_CODENAME). For 24.04 LTS, the codename is "noble".

If you are upgrading from a very old EOL release, you might need to upgrade incrementally. For example, if you're on 18.04 LTS (Bionic Beaver) and want to get to 24.04 LTS (Noble Numbat), you'd likely need to upgrade to 20.04 LTS (Focal Fossa) first, then to 22.04 LTS (Jammy Jellyfish), and finally to 24.04 LTS.

For each step, you'd adjust the sed command accordingly. For instance, to upgrade from 22.04 "jammy" to 24.04 "noble":

Bash
sudo sed -i 's/jammy/noble/g' /etc/apt/sources.list

Step 4: Update and Upgrade to the New Release

After changing the codename in your sources.list, run the update and upgrade commands again:

Bash
sudo apt update && sudo apt upgrade -y
sudo apt dist-upgrade -y
sudo apt autoremove -y

Step 5: Reboot

Once the upgrade process is complete, reboot your system to finalize the changes:

Bash
sudo reboot

Repeat for Incremental Upgrades (If Needed)

If you are upgrading across multiple Ubuntu versions (e.g., from a very old EOL release to 24.04 LTS), repeat steps 3 and 4 for each intermediary release. For example, to go from 18.04 LTS to 24.04 LTS, you might upgrade in this sequence:

  1. 18.04 LTS (EOL) -> 20.04 LTS (Focal)
  2. 20.04 LTS (Focal) -> 22.04 LTS (Jammy)
  3. 22.04 LTS (Jammy) -> 24.04 LTS (Noble)

Troubleshooting: Fixing Broken Dependencies

During the upgrade process, you might encounter broken dependencies. APT is usually good at resolving these, but if you run into issues, try these commands:

Bash
sudo apt --fix-broken install

This command attempts to fix broken packages by correcting dependencies.

If that doesn't work, you can try reinstalling essential system packages:

Bash
sudo apt install ubuntu-minimal ubuntu-standard -y

Conclusion

The best practice is always to upgrade your Ubuntu systems before they reach EOL. This avoids the complexities of manual upgrades and ensures continuous security updates and support. However, life happens, and sometimes systems get overlooked.

Manual APT upgrades are a powerful technique for rescuing EOL Ubuntu systems, especially when:

  • do-release-upgrade fails due to missing repositories.
  • You need to upgrade incrementally across multiple versions.
  • A fresh install is not feasible or desirable.

By following these steps carefully, you can bring your EOL Ubuntu system back to a supported state, ensuring continued operation and security. Remember to always back up critical data before undertaking major system upgrades! Good luck, and happy upgrading to Ubuntu 24.04 LTS "Noble Numbat!"

0 comments:

Post a Comment