Ubuntu Release Upgrade – Fully automatic non-interactive upgrade

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)

Tested with:
Ubuntu 11.10
Ubuntu 11.04

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.

With Fabric

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 *


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:
fab r_upgrade
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.

7 responses to “Ubuntu Release Upgrade – Fully automatic non-interactive upgrade

  1. Pingback: Automated Ubuntu Release Upgrade « AwaseConfigurations

  2. anthonyvenable110 April 29, 2012 at 9:07 pm

    Sounds like a great idea! Thanks for this. I can see this being useful when one is upgrading over several or many machines.

  3. Nikolay Bryskin May 17, 2012 at 8:01 pm

    there is more straightforward way:
    do-release-upgrade -d -f DistUpgradeViewNonInteractive

    • Henri Siponen May 17, 2012 at 8:08 pm

      Thanks Nikolay! I will have to test this tomorrow myself but how can I have missed this… 🙂

      • Henri Siponen May 18, 2012 at 11:38 am

        I have now tested it and seems to work perfectly. I’ll edit the blog post to include this as well. My method can still be useful as you can define the answers in the command if you need to.

  4. Pingback: Non-interactive remote distribution upgrades of Ubuntu | Oligofren

  5. Pingback: Can I do a Silent or Unattended Release Upgrade? - Popular Ubuntu Questions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: