Update an old Ubuntu: 404 Not Found; Err http://us.archive.ubuntu.com; Failed to fetch

Today I stumbled into a weird problem. My Ubuntu server 9.04 couldn’t update anymore. My /etc/apt/sources.list looked like this:

  deb-src http://archive.ubuntu.com/ubuntu/ jaunty main restricted universe multiverse

Running apt-get update gave all sorts of problems as it couldn’t find repository servers anymore:

  $ sudo apt-get update
  Ign http://us.archive.ubuntu.com jaunty Release.gpg
  Ign http://us.archive.ubuntu.com jaunty Release
  Ign http://us.archive.ubuntu.com jaunty/main Packages
  Ign http://us.archive.ubuntu.com jaunty/universe Packages
  Ign http://us.archive.ubuntu.com jaunty/main Packages
  Ign http://us.archive.ubuntu.com jaunty/universe Packages
  Err http://us.archive.ubuntu.com jaunty/main Packages
    404 Not Found [IP: 91.189.92.180 80]
  Err http://us.archive.ubuntu.com jaunty/universe Packages
    404 Not Found [IP: 91.189.92.180 80]
  W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/jaunty/main/binary-i386/Packages
    404 Not Found [IP: 91.189.92.180 80]

  W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/jaunty/universe/binary-i386/Packages
    404 Not Found [IP: 91.189.92.180 80]

  E: Some index files failed to download, they have been ignored, or old ones used instead.

To upgrade a really old Ubuntu release, we first need to edit our sources.list and change all (xx.)archive.ubuntu.com to old-releases.ubuntu.com.

   $ sudo emacs /etc/apt/sources.list

So your lines should instead of

   deb http://archive.ubuntu.com/ubuntu jaunty main restricted universe

look like

   deb http://old-releases.ubuntu.com/ubuntu jaunty main restricted universe

In this example I use jaunty release. But it works the same on other releases.

Now update the repos

   $ sudo apt-get update

Install update-manager-core if it is not yet installed:

   $ sudo apt-get install update-manager-core

And now upgrade the system.

   $ sudo do-release-upgrade

Note that you can just upgrade to the next release (in my example from 9.04 to 9.10 or from LTS 8.04 to 10.04).

Also note that if upgrading over the ssh session it is advised to run the upgrade in the screen. If the ssh session drops, the upgrade will continue to run. Install screen first (if not yet installed)

   $ sudo apt-get install screen

Now run screen

   $ screen

And upgrade with

   $ sudo do-release-upgrade

How to work with the screen is beyond this post.

EDIT 14. 9. 2014:

As Dmitry has mentioned in the comments, security packages should also be replaced with old-releases. So:

security.ubuntu…. should be changed to old-releases.ubuntu….