0

Background

I had a dual-boot Windows 10/Ubuntu 16.04 system. Then I made it triple boot with 18.04. Then I added Lubuntu 16.04 within Vitualbox VM inside Ubuntu 16.04 system.

Somewhere along the way I got lost and deleted /usr instead of usr. Then thinking 18.04 was freshly synced to 16.04 I copied those files over /usr and ended up with a Frankenstein 16.04/18.04.

So I created a live USB 16.04.4 and from that copied over the /usr directory. As luck would have it I ended up with a 16.04.4/16.04.5 hybrid with some 18.04 mixed in.

My apt was broken but dpkg still worked so I used it to reinstall apt but it was yet a different version.

I wiped my 18.04 partition and installed a fresh copy of 16.04.5. I installed some random applications like conky, dialog, gimp, vnstat, yad and maybe a couple of others.

Because I can still mount my old 16.04 partition how can I get a list of packages (without libraries and linux kernels) that still need to be installed on my new 16.04 partition?

1 Answers1

1

The power of dpkg, diff and grep

My answer is based on this Q&A: Set difference of packages installed on 2 machines. The differences are:

  • There are two different partitions not two different servers
  • apt is broken in my old 16.04 partition, so dpkg is used instead

I mounted my old 16.04 partition as /mnt/old and typed the following:

/mnt/old$ dpkg --admindir=var/lib/dpkg --get-selections|sort > ~/installed-old
/mnt/old$ dpkg --admindir=/var/lib/dpkg --get-selections|sort > ~/installed-new
/mnt/old$ diff -u ~/installed-old ~/installed-new > ~/compare-old-new
/mnt/old$ cat ~/compare-old-new | grep '^-' | grep -v -e '^-lib' -e '^-linux' | wc -l
257

So there are potentially 257 packages that need to be reinstalled but many of them will be auto-installed by a package that depends on them.

What the list looks like

Here's a snippet of the list when the command cat ~/compare-old-new | grep '^-' | grep -v -e '^-lib' -e '^-linux' is used:

-mesa-utils                 install
-mesa-vdpau-drivers:amd64   install
-milou                      install
-mkusb-common               install
-mkusb                      install
-mkusb-nox                  install
-module-init-tools          install
-mutter-common              install
-mutter                     install
-mysql-common               install
-nasm                       install
-nautilus-hide              install
-nautilus-image-converter   install
-ntrack-module-libnl-0      deinstall
-nvidia-384                 deinstall
-nvidia-390                 deinstall
-nvidia-opencl-icd-384      deinstall
-nvidia-opencl-icd-390      deinstall
-nvidia-prime               deinstall
-nvidia-settings            deinstall
-nvme-cli                   install
-ocl-icd-libopencl1:amd64   install
-oracle-java8-installer     install
-oracle-java8-set-default   install
-oxideqt-codecs:amd64       install
-oxygen5-icon-theme         deinstall
-pavucontrol                install
-peek                       install

Most of the snipped are packages installed to answer a question in Ask Ubuntu. From this snippet I only need to reinstall: mesa-utils, mutter, nvme-cli, pavucontrol and peek.

Packages branded deinstall can be ignored: dpkg --get-selections shows packages marked "deinstall"