User avatar
Botspot
Posts: 1240
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Tue Jun 02, 2020 9:39 pm

My Pi4 crashed while APT was upgrading 17 core RPi packages. (APT was busy downloading when the crash occurred)
After rebooting, sudo apt update shows nothing.
Attempting to reinstall the packages results in the "it cannot be downloaded error":

Code: Select all

pi@raspberrypi:~ $ sudo apt install --reinstall rpi-eeprom rpi-eeprom-images libraspberrypi-bin rc-gui libraspberrypi-dev libraspberrypi-doc raspi-config raspberrypi-kernel raspberrypi-bootloader libraspberrypi0 x11-xserver-utils rpi-chromium-mods -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Reinstallation of libraspberrypi-bin is not possible, it cannot be downloaded.
Reinstallation of libraspberrypi-dev is not possible, it cannot be downloaded.
Reinstallation of libraspberrypi-doc is not possible, it cannot be downloaded.
Reinstallation of libraspberrypi0 is not possible, it cannot be downloaded.
Reinstallation of raspberrypi-bootloader is not possible, it cannot be downloaded.
Reinstallation of raspberrypi-kernel is not possible, it cannot be downloaded.
Reinstallation of raspi-config is not possible, it cannot be downloaded.
Reinstallation of rc-gui is not possible, it cannot be downloaded.
Reinstallation of rpi-chromium-mods is not possible, it cannot be downloaded.
Reinstallation of rpi-eeprom is not possible, it cannot be downloaded.
Reinstallation of rpi-eeprom-images is not possible, it cannot be downloaded.
Reinstallation of x11-xserver-utils is not possible, it cannot be downloaded.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
...And in Synaptic, it shows 349 local packages (meaning that dpkg thinks they aren't available in the repos anymore)
My /etc/apt/sources.list:

Code: Select all

deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi 
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
# deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-fre$
I'm in a mess right now. How to fix this?
Want to make your own Raspbian image?
  • Hard way: Mess with confusing terminal commands.
  • Easy way: Let Pi-Power-Tools do it all for you!
Boot your image in a VM, Flash from the Internet at top speed, Mount (to drop files in), Edit partitions, Shrink/Expand, Repair, and more. Enjoy! :)
https://github.com/Botspot/Pi-Power-Tools

User avatar
DougieLawson
Posts: 38854
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Tue Jun 02, 2020 10:07 pm

Best solution to a complete mess is a fresh SDCard and a copy of RaspiOS Buster 32-bit. Boot that then move your immportant programs and data from the original system. Then spend time making notes as you re-install the pieces you need (over what comes for free in RaspiOS) so you can avoid making a mess next time.

Trying to pick up a 500 piece jigsaw with 151 pieces missing and without a photo on the box is a futile waste of time.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
Botspot
Posts: 1240
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Tue Jun 02, 2020 10:17 pm

DougieLawson wrote:
Tue Jun 02, 2020 10:07 pm
Best solution to a complete mess is a fresh SDCard and a copy of RaspiOS Buster 32-bit. Boot that then move your immportant programs and data from the original system. Then spend time making notes as you re-install the pieces you need (over what comes for free in RaspiOS) so you can avoid making a mess next time.
Reflashing would make sense if I messed up badly, like uninstalling lxde, corrupting the sd card, deleting /usr/share, but in this case, all that happened was dpkg being unexpectedly killed.
The system still boots fine.

AFAIK, the problem arises from dpkg thinking the packages are corrupted. (since a partially downloaded file doesn't match the checksum.)
How to erase these partially downloaded packages? And is there anything else I can reset?
Want to make your own Raspbian image?
  • Hard way: Mess with confusing terminal commands.
  • Easy way: Let Pi-Power-Tools do it all for you!
Boot your image in a VM, Flash from the Internet at top speed, Mount (to drop files in), Edit partitions, Shrink/Expand, Repair, and more. Enjoy! :)
https://github.com/Botspot/Pi-Power-Tools

User avatar
DougieLawson
Posts: 38854
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Tue Jun 02, 2020 10:46 pm

You can scrap /var/cache/apt/archives/* set a time limit, when you've spent more than a couple of hours trying the jigsaw, then throw in the towel and get a new SDCard built because it's a more cost-effective use of your time.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

trejan
Posts: 1858
Joined: Tue Jul 02, 2019 2:28 pm

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Tue Jun 02, 2020 11:18 pm

I'd recommend what Dougie said about starting again. If you really want to try to salvage the existing install then you should install + run debsums to verify the installed packages.

User avatar
Botspot
Posts: 1240
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Tue Jun 02, 2020 11:31 pm

SOLUTION!

Code: Select all

sudo rm -rf /var/lib/apt
sudo apt update
...And now, finally those 17 packages say they can be upgraded again.

My theory:
When apt upgrade was forcibly killed by a crashing Pi, it recorded incorrect checksums for those 17 partially downloaded packages.
APT assumed the repositories were corrupted.
All the dependencies of those packages (349 to be exact :o ) were also marked as corrupt.
By erasing /var/lib/apt, apt was forced to reconfigure everything, including all the checksums.

While not playing YouTube, run this:

Code: Select all

sudo apt upgrade -y
As soon as it's done, I'm going to update my week-old backup.
Last edited by Botspot on Wed Jun 03, 2020 12:28 am, edited 1 time in total.
Want to make your own Raspbian image?
  • Hard way: Mess with confusing terminal commands.
  • Easy way: Let Pi-Power-Tools do it all for you!
Boot your image in a VM, Flash from the Internet at top speed, Mount (to drop files in), Edit partitions, Shrink/Expand, Repair, and more. Enjoy! :)
https://github.com/Botspot/Pi-Power-Tools

bjtheone
Posts: 765
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Wed Jun 03, 2020 12:24 am

Current times: Just restart over. Honestly it is usually easier unless you are quite comfortable at the command line.

Olden times: Learn about dpkg and its many many switches. It is what is being run when you run apt, apt-get, aptitude, synaptic, etc.

Often you could:

open /var/lib/dpkg/status
Search for the offending package by name or by jacked up status and remove its entry.
Save the file and exit
run sudo dpkg --configure -a.
run sudo apt-get -f install just in case.
Continue on if there are no errors.

ejolson
Posts: 5165
Joined: Tue Mar 18, 2014 11:47 am

Re: 349 packages can't be reinstalled, updates not showing, what did I do? How to fix?

Wed Jun 03, 2020 5:04 am

Botspot wrote:
Tue Jun 02, 2020 11:31 pm
SOLUTION!

Code: Select all

sudo rm -rf /var/lib/apt
sudo apt update
...And now, finally those 17 packages say they can be upgraded again.

My theory:
When apt upgrade was forcibly killed by a crashing Pi, it recorded incorrect checksums for those 17 partially downloaded packages.
APT assumed the repositories were corrupted.
All the dependencies of those packages (349 to be exact :o ) were also marked as corrupt.
By erasing /var/lib/apt, apt was forced to reconfigure everything, including all the checksums.

While not playing YouTube, run this:

Code: Select all

sudo apt upgrade -y
As soon as it's done, I'm going to update my week-old backup.
Thanks for posting. It's been a long time since something similar happened to me but it's good to know a possible solution.

Return to “General discussion”