19

I have been hunting for an answer to this for a long time, and although I've seen proposed solutions, none of them works.

I can see all packages ready for update with this command:

apt list --upgradable

Some of them are held back due to phased updates. I want to know which ones will be upgraded, and which ones held back.

All that I have so far is to issue this command (once for each package):

apt-cache policy [packagename]

If the output contains the string (phased …%) (one, two or three digits before the percentage sign), it means that the package is part of the phased updates. But it doesn't tell whether or not it will be installed on my machine right now.

How do I tell which of the pending packages would be installed right now, and which ones would be held back due to phased updates?

I'm running Ubuntu 22.04, in case that makes a difference.

Thank you

0

3 Answers 3

18

I also cobbled together some commands. I am mostly parsing apt output using awk but it would be great if somebody else knows more native commands.

If you want to find all the packages going through phased updates and their associated phase percentage.

apt-cache dumpavail | awk '/^Package: /{p=$2} /^Phased-Update-Percentage/{print p,$2}'

However, based on the question you probably only care about installed packages that are going through phased updates.

apt-cache dumpavail | awk '/^Package: /{p=$2} /^Phased-Update-Percentage/{cmd="dpkg -l "p" 2>&1 | grep -c ^ii";cmd | getline out;close(cmd); if(out > 0){print p,$2}}'

You can also find the packages that will be held back. In this case, during a full-upgrade.

apt-get --simulate full-upgrade | awk '/^The following packages have been kept back:/{save=1;next} /^[[:graph:]]/{save=0;next} save{kp=kp$0} END{split(kp,kpa);for(kpi in kpa){print kpa[kpi]}}'

But then you want to "tell which of the pending packages would be installed right now, and which ones would be held back due to phased updates". Putting it all together.

apt-cache dumpavail | 
  awk -v OFS="," -v kp="$(
  apt-get --simulate full-upgrade | awk '/^The following packages have been kept back:/{save=1;next} /^[[:graph:]]/{save=0;next} save{kp=kp$0} END{print kp}'
  )" \
  'BEGIN{split(kp,kpa);for(kpi in kpa){kpd[kpa[kpi]]=""}} /^Package: /{p=$2} /^Phased-Update-Percentage/{cmd="dpkg -l "p" 2>&1 | grep -c ^ii";cmd | getline out;close(cmd); if(out > 0){if(p in kpd){print p,"phased "$2,"held back"}else{print p,"phased "$2,"not held back"}}}'

Here is sample output on a fairly recently patched 22.04 server (piping into column).

root@ubuntu:~# apt-cache dumpavail | awk -v OFS="," -v kp="$(apt-get --simulate full-upgrade | awk '/^The following packages have been kept back:/{save=1;next} /^[[:graph:]]/{save=0;next} save{kp=kp$0} END{print kp}')" 'BEGIN{split(kp,kpa);for(kpi in kpa){kpd[kpa[kpi]]=""}} /^Package: /{p=$2} /^Phased-Update-Percentage/{cmd="dpkg -l "p" 2>&1 | grep -c ^ii";cmd | getline out;close(cmd); if(out > 0){if(p in kpd){print p,"phased "$2,"held back"}else{print p,"phased "$2,"not held back"}}}' | column -t -s ,
grub-efi-amd64-bin           phased 0   held back
grub-efi-amd64-signed        phased 0   held back
libmbim-glib4                phased 70  held back
libmbim-proxy                phased 70  held back
libmm-glib0                  phased 70  not held back
libqmi-glib5                 phased 70  held back
libqmi-proxy                 phased 70  held back
libsasl2-2                   phased 70  held back
libsasl2-modules             phased 70  held back
libsasl2-modules-db          phased 70  held back
modemmanager                 phased 70  held back
python3-software-properties  phased 0   held back
shim-signed                  phased 62  held back
software-properties-common   phased 0   held back
tcpdump                      phased 20  not held back
ubuntu-advantage-tools       phased 20  held back

The results match the full-upgrade output

root@ubuntu:~# apt-get --simulate full-upgrade
...
The following packages have been kept back:
  grub-efi-amd64-bin grub-efi-amd64-signed libmbim-glib4 libmbim-proxy libqmi-glib5 libqmi-proxy libsasl2-2 libsasl2-modules libsasl2-modules-db modemmanager python3-software-properties shim-signed software-properties-common ubuntu-advantage-tools
The following packages will be upgraded:
  isc-dhcp-client isc-dhcp-common libmm-glib0 tcpdump

notes

  • I tested these commands on Ubuntu 22.04 with apt 2.4.8.
  • There are likely scenarios these commands will not handle.
  • This is not a fast solution and takes over 10s to run on my minimal spec VM.
  • The way phased updates are handled seems to be changing. Before going down this rabbit-hole I used apt-cache policy to determine whether a package was held back or not. That no longer appears reliable. I found an apt configuration option APT::Get::Phase-Policy=True that helps, but the results are not consistent with actual apt behavior. This was the output I generated when parsing the output of apt-cache policy, but it does not match what apt would do.
root@ubuntu:~# for i in $(apt-cache dumpavail | awk '/^Package: /{p=$2} /^Phased-Update-Percentage/{cmd="dpkg -l "p" 2>&1 | grep -c ^ii";cmd | getline out;close(cmd); if(out > 0){print p}}'); do apt-cache -o=APT::Get::Phase-Policy=True policy $i | awk -v p=$i 'NR==2{iv=$2} NR==3{cv=$2} /phased/{pv=$1;pp=$3" "$4;exit} END{if( cv == pv ) { printf "%s,%s,not held back\n",p,pp }else{printf "%s,%s,held back\n",p,pp}}'; done | column -t -s ,
grub-efi-amd64-bin           (phased 0%)   held back
grub-efi-amd64-signed        (phased 0%)   held back
libmbim-glib4                (phased 70%)  held back
libmbim-proxy                (phased 70%)  held back
libmm-glib0                  (phased 70%)  not held back
libqmi-glib5                 (phased 70%)  not held back
libqmi-proxy                 (phased 70%)  not held back
libsasl2-2                   (phased 70%)  held back
libsasl2-modules             (phased 70%)  held back
libsasl2-modules-db          (phased 70%)  held back
modemmanager                 (phased 70%)  not held back
python3-software-properties  (phased 0%)   held back
shim-signed                  (phased 62%)  held back
software-properties-common   (phased 0%)   held back
tcpdump                      (phased 20%)  not held back
ubuntu-advantage-tools       (phased 20%)  held back
4
  • 3
    This is such a thorough answer, thank you! Mar 4, 2023 at 7:26
  • There's a bit of a bug with the third one. If there are only packages held back, and none to upgrade, the returned list is nonsensical. I don't understand awk, and so I don't know how to fix this! Mar 4, 2023 at 8:42
  • 2
    I tweaked the awk settings to handle when there are none to upgrade. I'm tempted to make other optimizations, but parsing the output will always be a fragile setup. Mar 5, 2023 at 1:48
  • Thank you, @Andrew Lowther Mar 5, 2023 at 7:20
8

Here's one way:

//The list of all upgradeable packages

$ apt list --upgradeable | cut -d'/' -f1
Listing...
tcpdump
ubuntu-advantage-tools

//The list of upgradeable packages that are NOT phased
//...or are phasing, and it's your turn for install

$ apt upgrade --simulate | grep Inst | cut -d' ' -f2
ubuntu-advantage-tools

The list of phasing packages is, of course, the difference between the lists.

2
  • This is great, thank you. I wish that I could give two different answer the green tick, because this also deserves on. Mar 4, 2023 at 7:26
  • +1 "The list of phasing packages is, of course, the difference between the lists." ... i.e. translated to code, it could be e.g.: comm -3 <(apt upgrade --simulate | grep Inst | cut -d' ' -f2 | sort) <(apt list --upgradeable | cut -d'/' -f1 | sort)
    – Raffa
    Mar 5, 2023 at 9:11
7

The output of apt upgrade will tell you exactly which packages are going to be upgraded and which packages will be kept back.

You may also use apt -s upgrade to run a simulation which will give you the same desired information.

$ apt -s upgrade
NOTE: This is only a simulation!
      apt needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  libimage-magick-perl imagemagick libdcmtk16 libopenexr25 libmagick++-6.q16-8
  libmagickcore-6.q16-6-extra libimage-magick-q16-perl libmagickwand-6.q16-6
  imagemagick-6.q16 libeditorconfig0 libmagickcore-6.q16-6
  imagemagick-6-common
Learn more about Ubuntu Pro at https://ubuntu.com/pro
The following packages have been kept back:
  grub-efi-amd64 grub-efi-amd64-bin grub-efi-amd64-signed libsasl2-2 libsasl2-modules libsasl2-modules-db
  libsnmp-base libsnmp40 shim-signed tcpdump
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.

Since apt 2.7.11 the output of apt upgrade has been improved and tells exactly which packages have been kept back due to phased updates:

Calculating upgrade... Done
The following upgrades have been deferred due to phasing:

followed by a list of the affected packages.

Ubuntu 24.04 comes with apt 2.7.14 and is the first Ubuntu version which introduces this behaviour.

2
  • This doesn't tell you why the packages are held back, which is my major beef with this whole situation. For years held-back packages meant your package system was broken. Bizarrely the implementers of phasing give you no easy way to tell which is which. This was 'strike 3' for me as far as using Ubuntu on my desktops. May 4 at 4:33
  • @OrganicMarble True, but also true for tis answer
    – mook765
    May 4 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .