24

Sometimes, when I upgrade a system via do-release-upgrade, the update process fails and the script tells me to finish the process manually via dpkg --configure -a. This is a not serious problem - after manually solving the dependencies problem and the finishing upgrade process all works well.

But the do-release-upgrade script has a cleanup process after finishing the upgrade:

Remove obsolete packages?  
XXX packages are going to be removed.  
Continue [yN]  Details [d]y

which removes some obsolete packages from old version of system.

Seems that this process doesn't execute when the automatic upgrade fails and I finish upgrade manually, so obsolete packages from old version remain installed in the system.

How I can run the "Remove obsolete packages" process manually after finishing the upgrade by hand?

Zanna
  • 72,312
Murz
  • 1,161
  • 1
  • 9
  • 9

5 Answers5

32

Test this:

Open a terminal (press Ctrl+Alt+T).

Run this:

sudo -i

apt-get update apt-get autoremove apt-get clean

UNUSCONF=$(dpkg -l|grep "^rc" | awk '{print $2}') apt-get remove --purge $UNUSCONF

NEWKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')

ADDKERNEL="linux-(image|headers|ubuntu-modules|restricted-modules)"

METAKERNEL="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"

UNUSKERNELS=$(dpkg -l | awk '{print $2}' | grep -E $ADDKERNEL | grep -vE $METAKERNEL | grep -v $NEWKERNEL)

apt-get remove --purge $UNUSKERNELS

update-grub

Pablo Bianchi
  • 17,371
kyodake
  • 17,808
4

Looking in the upgrade logs in /var/log/dist-upgrade, there is a line in main.log:

main.log:2020-12-23 21:01:53,154 DEBUG Obsolete: linux-headers-5.4.0-56-generic linux-hwe-5.4-headers-5.4.0-56 linux-image-5.4.0-56-generic linux-modules-5.4.0-56-generic linux-modules-extra-5.4.0-56-generic msgpack-tools slirp4netns

I think uninstalling these combined with the apt-get autoremove should do the same the upgrade would have done if it had run to completion.

Steve Dee
  • 837
2

I believe the "Remove obsolete packages" actually just runs a sudo apt-get autoremove. Try it, see if it helps.

2

I find that this answer of an unrelated question might provide a utility and command that seems to remove more of the unused stuff:

  1. Install the "deborphan" package.
  2. sudo deborphan | xargs sudo apt-get -y remove --purge
DustWolf
  • 439
1

How to see all obsolete packages:

apt list '?obsolete'

How to remove all obsolete packages:

sudo apt -V remove '?obsolete'