Troubles with apt upgrade of a container after restoring backup

I restored a container from an rsync backup and I’m experiencing some errors, I think it’s viewing older packages in some way that don’t exist.

apt upgrade output:

Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
12 not fully installed or removed.
Need to get 0 B/231 MB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y

Errors encountered:

dpkg: error processing package linux-image-extra-virtual (–configure):
dependency problems - leaving unconfigured
dpkg: error processing package snap-confine (–configure):
package snap-confine is not ready for configuration
cannot configure (current status ‘half-installed’)
Errors were encountered while processing:
linux-firmware
linux-image-4.4.0-71-generic
linux-image-4.4.0-72-generic
linux-image-4.4.0-75-generic
linux-image-4.4.0-78-generic
linux-image-extra-4.4.0-71-generic
linux-image-extra-4.4.0-72-generic
linux-image-extra-4.4.0-75-generic
linux-image-extra-4.4.0-78-generic
linux-image-generic
linux-image-extra-virtual
snap-confine
E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried doing a dpkg --configure -a and apt autoremove but those don’t appear to help

Looks like partial log output to me, this seems to indicate that one of the maintainer scripts failed but we’re lacking the output of that maintainer script.

Can your run “apt upgrade” again and paste everything that’s shown on the screen?

Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
12 not fully installed or removed.
Need to get 231 MB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-71-generic amd64 4.4.0-71.92 [21.8 MB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-72-generic amd64 4.4.0-72.93 [21.8 MB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-75-generic amd64 4.4.0-75.96 [21.9 MB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-4.4.0-78-generic amd64 4.4.0-78.99 [21.9 MB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-extra-4.4.0-71-generic amd64 4.4.0-71.92 [36.0 MB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-extra-4.4.0-72-generic amd64 4.4.0-72.93 [35.9 MB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-extra-4.4.0-75-generic amd64 4.4.0-75.96 [35.9 MB]
Get:8 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 linux-image-extra-4.4.0-78-generic amd64 4.4.0-78.99 [35.9 MB]
Get:9 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 snap-confine amd64 2.25 [1712 B]
Fetched 231 MB in 1min 1s (3761 kB/s)
Setting up linux-firmware (1.157.11) …
update-initramfs: Generating /boot/initrd.img-4.4.0-81-generic
W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
update-initramfs: Generating /boot/initrd.img-4.4.0-79-generic
W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
update-initramfs: Generating /boot/initrd.img-4.4.0-78-generic
W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
/usr/sbin/update-initramfs: 206: /usr/sbin/update-initramfs: cannot create /var/lib/initramfs-tools/4.4.0-78-generic: Permission denied
dpkg: error processing package linux-firmware (–configure):
subprocess installed post-installation script returned error exit status 2
dpkg: error processing package linux-image-4.4.0-71-generic (–configure):
package linux-image-4.4.0-71-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error processing package linux-image-4.4.0-72-generic (–configure):
package linux-image-4.4.0-72-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error processing package linux-image-4.4.0-75-generic (–configure):
package linux-image-4.4.0-75-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error processing package linux-image-4.4.0-78-generic (–configure):
package linux-image-4.4.0-78-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error processing package linux-image-extra-4.4.0-71-generic (–configure):
package linux-image-extra-4.4.0-71-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error proceNo apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
ssing package linux-image-extra-4.4.0-72-generic (–configure):
package linux-image-extra-4.4.0-72-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error processing package linux-image-extra-4.4.0-75-generic (–configure):
package linux-image-extra-4.4.0-75-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
dpkg: error processing package linux-image-extra-4.4.0-78-generic (–configure):
package linux-image-extra-4.4.0-78-generic is not ready for configuration
cannot configure (current status ‘half-installed’)
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
dpkg: dependency problems prevent configuration of linux-image-generic:
linux-image-generic depends on linux-firmware; however:
Package linux-firmware is not configured yet.

dpkg: error processing package linux-image-generic (–configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
dpkg: dependency problems prevent configuration of linux-image-extra-virtual:
linux-image-extra-virtual depends on linux-image-generic (= 4.4.0.81.87); however:
Package linux-image-generic is not configured yet.

dpkg: error processing package linux-image-extra-virtual (–configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
dpkg: error processing package snap-confine (–configure):
package snap-confine is not ready for configuration
cannot configure (current status ‘half-installed’)
Errors were encountered while processing:
linux-firmware
linux-image-4.4.0-71-generic
linux-image-4.4.0-72-generic
linux-image-4.4.0-75-generic
linux-image-4.4.0-78-generic
linux-image-extra-4.4.0-71-generic
linux-image-extra-4.4.0-72-generic
linux-image-extra-4.4.0-75-generic
linux-image-extra-4.4.0-78-generic
linux-image-generic
linux-image-extra-virtual
snap-confine
E: Sub-process /usr/bin/dpkg returned an error code (1)

If you need more information let me know. I thought perhaps I could attempt going to /lib/modules and removing the culprit linux images but apparently not. I also tried an apt-get clean which didn’t help anything. apt autoremove produces the same errors as apt upgrade

Aha! So it turns out the solution is to reinstall dpkg:

sudo apt-get install --reinstall dpkg

So turns out this isn’t really a LXD/LXC issue, but it makes me wonder if this may happen again if I recover a container in the future. I may test this again and try to reproduce it