I have a Buffalo LinkStation, which I installed Debian Stretch on it.
Recently, I was trying to remove obsolete packages by using “apt-get autoremove” command after an update. Usually this process will take a couple of minutes. But this time, unfortunately there was a package (to be more specific, an old kernel) which refused to be removed by apt or dpkg.
When I was trying to completely remove it by dpkg:
$ sudo dpkg --purge linux-image-4.9.0-5-marvell
(Reading database ... 84261 files and directories currently installed.) Removing linux-image-4.9.0-5-marvell (4.9.65-3+deb9u2) ... /etc/kernel/postrm.d/initramfs-tools: update-initramfs: Deleting /boot/initrd.img-4.9.0-5-marvell /etc/kernel/postrm.d/zz-flash-kernel: kirkwood-linkstation: machine: Buffalo Linkstation LS-WVL Couldn't find DTB kirkwood-linkstation-lswvl.dtb in /usr/lib/linux-image-4.9.0-5-marvell or /etc/flash-kernel/dtbs run-parts: /etc/kernel/postrm.d/zz-flash-kernel exited with return code 1 dpkg: error processing package linux-image-4.9.0-5-marvell (--purge): subprocess installed post-removal script returned error exit status 1 Errors were encountered while processing: linux-image-4.9.0-5-marvell
The only thing I got is the error message:
“subprocess installed post-removal script returned error exit status 1” .
There must be something wrong with the post-removal process.
And I can’t just leave it here, because apt-get tries to remove the old kernel first each time I try to install a new package or update the operating system.
After some googling, I finally find a way to remove this stubborn thing from the system. In the
/var/lib/dpkg/info directory, there is a file “linux-image-4.9.0-5-marvell.postrm”. This is the script for post-removal process. I simply added a new line “exit 0” after the first line. Then,
sudo dpkg --purge linux-image-4.9.0-5-marvell (Reading database ... 84261 files and directories currently installed.) Removing linux-image-4.9.0-5-marvell (4.9.65-3+deb9u2) ... Purging configuration files for linux-image-4.9.0-5-marvell (4.9.65-3+deb9u2) ... dpkg: warning: while removing linux-image-4.9.0-5-marvell, directory '/lib/modules/4.9.0-5-marvell' not empty so not removed
Yes, this package is now removed from the system. This workaround is not perfect, but at least this package is removed. Only I need to do is manually remove the directory later.
Disclaimer: The article here is provided “as is” without any warranties. The article may not suit your situation. Use at your own risk.