56

How do I upgrade to a new Ubuntu version without having to react to prompts?

I'm on 12.04 now and would like to install 12.10. When I start the update, it usually downloads stuff, then asks a question, installs a bit, asks a question, etc.. I leave it overnight and sometimes find that it made almost no progress updating. I'd like to just kick of the process, go away and have it finished after a couple of hours. I'm fine with it automatically updating configuration files in /etc and so on. So how to start an unattended upgrade?

Braiam
  • 67,791
  • 32
  • 179
  • 269
jdm
  • 2,327

5 Answers5

70

The following command upgrades to the new stable release without prompts:

do-release-upgrade -f DistUpgradeViewNonInteractive

The following command upgrades to the current development release without prompts:

do-release-upgrade -d -f DistUpgradeViewNonInteractive

I haven't tested it, but it seems it just performs the default action when a question arises. It also times out any scripts if they hang for too long.

You might have to do use dpkg-reconfigure afterwards if you are unhappy with the configuration of certain packages, but most of the time you should be ok.

Source: http://awaseroot.wordpress.com/2012/04/29/ubuntu-release-upgrade-fully-automatic-non-interactive-upgrade/ . In the link there are also other ways to do this.

Robie Basak
  • 15,670
jdm
  • 2,327
  • I did this and everything seemed to work, but after a reboot I only got a grub error, so you seem to have to add some more grub configuration after this unattended upgrade. maybe with sudo apt-get install grub-emu? – rubo77 Oct 15 '15 at 12:05
  • 9
    This doesn't work for Trusty => Xenial. Still get questions about modified /etc files. – Willem Jan 27 '17 at 09:27
  • Shouldn't this be run with sudo? – Cerin Feb 04 '17 at 07:40
  • 1
    Regarding questions about modified /etc files, there is a cool solution here: https://awaseroot.wordpress.com/2012/04/29/ubuntu-release-upgrade-fully-automatic-non-interactive-upgrade/#more-91. Run the command with 'echo "y\n\ny\ny\ny\n" | ' in front of do-release-upgrade. It seeds the answers to the questions. Add lots of answers in case there are lots of modified files in /etc. – nmgeek Apr 20 '18 at 00:41
  • I up able to upgrade trusty to xenial this way. Before I issue this command, I do: sudo mv /etc/apt/sources.list.d /etc/apt/sources.list.d-NO as that fixes 99% of the issues I have had with interactive upgrades. I repopulate that directory afterwards with Ansible. – dannyman Mar 26 '19 at 18:08
  • This solution officially doesn't work. I tried running this to upgrade an Ubuntu 16 server to 18, and it still prompted me to see if I wanted to override some custom modifications I had made to /etc/logrotate.d/apache2'. – Cerin Apr 18 '19 at 20:45
12

To confirm what Thomas Ward states in his answer and contradict the accepted answer, do-release-upgrade -d -f DistUpgradeViewNonInteractive DOES NOT WORK.

In fact at the very first prompt it broke my 16.04 to 18.04 test partition broken and I had to reclone it. This is where the script freezes:

Setting up mount (2.31.1-0.4ubuntu3) ...
Setting up systemd (237-3ubuntu10) ...
Installing new version of config file /etc/pam.d/systemd-user ...
Installing new version of config file /etc/systemd/journald.conf ...

Configuration file '/etc/systemd/logind.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** logind.conf (Y/I/N/O/D/Z) [default=N] ? y

Y
CRASHED... NOTHING HAPPENS NOW... WILL KILL AND RESTART WITHOUT -f OPTION...

Due to Input Inhibitors neither reboot nor shutdown will work after killing the script. You have to do a cold shutdown (hold power button ~ 10 seconds).

Thank goodness this was a 16.04 clone upgrade and not on the real 16.04 partition.


To make life even more interesting a new 898 MB partition was added to my NVMe SSD and my regular partitions shifted:

$ lsdrv
NAME        FSTYPE  LABEL                  MOUNTPOINT          SIZE MODEL

nvme0n1                                                        477G Samsung SSD 960 PRO 512G
├─nvme0n1p5 ntfs                                               858M 
├─nvme0n1p3                                                     16M 
├─nvme0n1p1 ntfs                                               450M 
├─nvme0n1p8 ntfs    Shared_WSL+Linux       /mnt/e                9G 
├─nvme0n1p6 ext4    Ubuntu18.04                               23.7G 
├─nvme0n1p4 ntfs    NVMe_Win10             /mnt/c            390.4G 
├─nvme0n1p2 vfat                           /boot/efi            99M 
├─nvme0n1p9 swap    Linux Swap             [SWAP]              7.9G 
└─nvme0n1p7 ext4    NVMe_Ubuntu_16.0       /                  44.6G 
  • nvme0n1p5 used to be where my Ubuntu 16.04 partition resided but now it is on nvme0n1p7
  • nvme0n1p8 used to be where my 18.04 test partition resided but now it is on nvme0n1p8

NOTE: I also upgraded Windows 10 from Build 1709 to Build 1803 this afternoon so it is possible that it created the new 898 MB nvme0n1p5 partition in ntfs format.

  • 1
    That's a big, though, so you should report it at Launchpad. Used the non interactive way through several distribution upgrades earlier – oligofren May 14 '18 at 07:05
  • 1
    upgraded both ubuntu and windows on the same box on the same day? you must enjoy pain – JDS Jun 25 '18 at 22:31
  • @JDS Windows got borked. 1700 upgrades missing, all kinds of broken dependencies Python 2 vs Python 3. I have to erase and reinstall Ubuntu 16.04 from Windows Store sigh. – WinEunuuchs2Unix Jun 25 '18 at 22:59
6

Just to expand on previous answers, here is how to remotely do the same as the accepted answer, using a passwordless upgrade over ssh that will get your box upgraded to the latest version. It is copied off my own blog entry.

All of these steps assume your package repository is working. Meaning if you execute apt-get update you are not presented with lots of 404s due to having an outdated version. You need to fix that first, so see this answer for that.

0. Update all existing packages

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

1. Set up passwordless execution

Add your self to the list of users that can execute do-release-upgrade using sudo without entering a password is achieved by executing

sudo visudo -f /etc/sudoers.d/do-release-upgrade.

and adding the following line, substituting my-username for your own of course:

my-username ALL=NOPASSWD: /usr/bin/do-release-upgrade

2. Start incremental upgrades

Log out and execute the following command from your computer. It will do an upgrade without prompting you for input (accepting all default answers), wait for the computer to reboot, and then try upgrading again. It runs until you are upgraded to the latest version.

while true; do 
    ssh my-user@my-server sudo do-release-upgrade -f DistUpgradeViewNonInteractive;
    sleep 120; 
done

3. Fix configuration files to their previous state

Afterwards you will have to move the backed up config files to their previous location as the upgrade process has put default configurations in their place.

Not satisfied with the default answers?

This guy has a way to pre-prepare answers for each prompt, but the downside is that you must know how many prompts there are …

oligofren
  • 630
  • 1
  • 9
  • 22
1

You can do this via the terminal, using sudo apt-get -y upgrade. This will answer "yes" to all prompts. It will not run automatically, though, so you have to run it. It should work. AFAIK there's no way to use the GUI update manager to do unattended upgrades to software (this is NOT the same as a release upgrade!)

If you're trying to upgrade to a different Ubuntu version (aka a release upgrade, and usually the next release in the line of releases relative to your version of Ubuntu), you have to activate that manually. sudo do-release-upgrade may work. There is no way to skip past prompts though. This is why you initiate upgrades when you are going to be around for such prompts - there will be prompts.

Thomas Ward
  • 74,764
  • 1
    "There is no way to skip past prompts though". What about the DistUpgradeViewNonInteractive flag? That skips the prompts. – oligofren Jun 06 '13 at 17:52
  • 1
    @oligofren Thomas is right because -f DistUpgradeViewNonInteractive flag causes script to lock up at the first (Y/I/N/O/D/Z) prompt. See my answer I just posted. – WinEunuuchs2Unix May 14 '18 at 00:21
-4

Try adding -y option to apt-get but know that it will answer y all queries.

Seth
  • 58,122
  • 1
    I'm using the graphical update manager, not apt-get. I could do the update in the console, but I've heard 'apt-get dist-upgrade' didn't work in years (to upgrade between releases), so the command wouldn't be 'apt-get'. – jdm Feb 02 '13 at 22:52
  • @jdm apt-get dist-upgrade should work fine. Where did you here is doesn't work anymore? – Seth Feb 02 '13 at 23:43
  • 4
    @Seth apt-get dist-upgrade does not now and has not ever, in any operating system, performed a release upgrade on its own. See man apt-get. upgrade only upgrades packages that can be upgraded without any packages being newly installed, or uninstalled. dist-upgrade upgrades packages even when it means packages are removed or added. This is mainly useful for performing ordinary updates--for example, upgrade will not upgrade kernels. – Eliah Kagan Feb 03 '13 at 03:41
  • 4
    Changing sources.list to point to the next release's archives and then running apt-get dist-upgrade will, if it succeeds, perform a release upgrade. This is supported in Debian though it's recommended to use aptitude dist-upgrade instead because of its more advanced dependency resolution. In Ubuntu, nothing like this is supported at all, though it might succeed. Instead, to upgrade to a later release in the command line, do-release-upgrade is used. That utility doesn't take a -y flag, so this answer doesn't apply to the situation of upgrading to a new release. – Eliah Kagan Feb 03 '13 at 03:43
  • Huh, interesting. I must have been reading about Debian then. – Seth Feb 03 '13 at 05:44