Ubuntu Release Upgrade – Fully automatic non-interactive upgrade
April 29, 2012Posted by on
Ubuntu 12.04 LTS has been released and it’s time to upgrade! The do-release-upgrade is the recommended way and don’t worry! I will use it. The problem is this: do-release-upgrade asks a lot of questions during the install but I have to upgrade multiple machines and I don’t feel like answering those same questions on each machine. So how to automate this?
There’s a way to answer those questions in advance and in a single command. You can pipe some of the answers with echo and then use DEBIAN_FRONTEND=noninteractice for the rest of them. No preseeding needed at all. With this command you can automate a release upgrade completely.
Remember to take backups in case something goes wrong.
Release Upgrade from Ubuntu 11.10 (Oneiric Ocelot) to Ubuntu 12.04 LTS (Precise Pangolin)
So here’s the command:
sudo sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive /usr/bin/do-release-upgrade'
Just run the command and it will answer yes to all questions. The amount of echoed y\n (y=yes \n=newline) you need depends on the amount of configuration changes you have done as it will ask if you want to keep the old configurations or install new ones. Answering yes/y will install the new configs. Keep at least the first three yes answers as it asks if you want to perform the upgrade or not. Rest of the questions are about your configs. You can of course just copy your old configs from your backups after the release upgrade if you need the old ones.
This command actually has way more of those y/yes answers than I needed but better safe than sorry.
If you need to answer no to keep all old configs and with no reboot in the end:
sudo sh -c 'echo "y\n\ny\nN\nN\nN\nN\nN\nN\nN\nN\nN\nN\nN\n" | DEBIAN_FRONTEND=noninteractive /usr/bin/do-release-upgrade'
UPDATE 18.5.2012: As Nikolay pointed out in the comments, there is another way of running do-release-upgrade non-interactively:
do-release-upgrade -d -f DistUpgradeViewNonInteractive
I have tested this with two upgrades. From Ubuntu 11.04 to 11.10 and from 11.10 to 12.04. I’m not so familiar with this method so I’m not sure how it handles the interactions but I didn’t notice any problems. It’s up to you to choose which method to use.
I did the upgrade remotely with Fabric from Ubuntu 11.04 Natty to 12.04 by running the command twice. You need a timer to wait during the first reboot before running the command again. Two release upgrades completely automated. I guess even more than two upgrades are possible using the same way. And obviously with Fabric you can also do the upgrade on all of your machines simultaniously.
Here’s my fabfile:
from fabric.api import * env.hosts=["host1.local","host2.local"] env.user="hng" env.warn_only=True env.parallel=True def r_upgrade(): sudo('echo "y\n\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive /usr/bin/do-release-upgrade')
Fabric uses “sudo sh -c” automatically with sudo so you don’t need to type it here.
So then you just need to run:
Or if you want to run it twice to upgrade from 11.04 to 12.04:
fab r_upgrade ; sleep 120 ; fab r_upgrade
The sleep 120 is there to wait 120 seconds during the reboot.
The two upgrades took about 200 minutes total to complete.
11.04 -> 11.10 = 90 min.
11.10 -> 12.04 = 110 min.
DISCLAIMER: Use at your own will. I’m not responsible for any damages the upgrade might cause to your system.