Ever wondered how to do a Ubuntu release upgrade from command line automatically so that it doesn’t ask any questions during the upgrade process? It really gets quite boring to answer those questions if you’re upgrading multiple machines. In our case the upgrade was from 11.04 to 11.10 (natty to oneiric) and this is how we did it:
1) Change the sources from natty to oneiric in the /etc/apt/sources.list. (We use our configuration package to do it efficiently on multiple machines)
UPDATE: You can use this command to change the sources:
sudo sed -i 's/natty/oneiric/' /etc/apt/sources.list
2) Run these two commands:
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get dist-upgrade -o Dpkg::Options::="--force-confold" --force-yes -y
The –force-confold option is used to keep the old configuration files and not replace them with new ones.
3) Reboot the machine:
Or you can just use this simple script for full automation. The script does all of the above tasks. Works only when upgrading from Ubuntu 11.04 to 11.10.
We are using this with Fabric so that we can remotely upgrade every machine from 11.04 to 11.10, and we do it simultaneously. Takes about 15 minutes total to upgrade all of our 20 machines. Here’s our fabric task for it:
@parallel @roles('workstations') @with_settings(warn_only=True) def auto_dist_upgrade(): if not _is_host_up(env.host): return config('oneiric-sources') sudo("apt-get update") sudo('DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get dist-upgrade -o Dpkg::Options::="--force-confold" --force-yes -y') sudo("reboot")
We haven’t tested this on other Ubuntu releases but in theory it should work on them as well.
UPDATE 29.4.2012: It is recommended to use do-release-upgrade instead of dist-upgrade, see my new guide to try the recommended way.