0

I was trying to install docker and accidentally ran a script I wasn't meant to (yeah I know) and now I have lost all my apt-get binaries.

I have tried looking through http://raspbian.raspberrypi.org/raspbian/pool/main/a/apt/ but none of those debian packages seem to work. Is there a way I can get my apt binaries back without having to reimage?

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
Milliways
  • 54,718
  • 26
  • 92
  • 182

2 Answers2

1

Welcome. On the bright side, this may be a good opportunity to upgrade to bullseye ;)

Here's a weird thing: I tried an apt install --reinstall --download-only apt to see where it gets the package from, and it's http://ftp.debian.org/debian/pool/main/a/apt/apt_1.8.2.3_arm64.deb That's the 64-bit version, the 32-bit one would be http://ftp.debian.org/debian/pool/main/a/apt/apt_1.8.2.3_armhf.deb.

However, I then pulled the apt binary out (.deb packages are .cpio files in disguise), and there's a problem with the things it depends on:

    > ldd ./apt                                                                                                                                                                                                         
    linux-vdso.so.1 (0x0000007fb84aa000)                                                                                                                                                                                          
    libapt-private.so.0.0 => /usr/lib/aarch64-linux-gnu/libapt-private.so.0.0 (0x0000007fb83e5000)                                                                                                                                
    libapt-pkg.so.6.0 => not found  
    [...]

There's more, but the issue here is the "not found"; compare to the actual apt on the system:

    > ldd $(which apt)  
    linux-vdso.so.1 (0x0000007f97f9c000)
    libapt-private.so.0.0 => /usr/lib/aarch64-linux-gnu/libapt-private.so.0.0 (0x0000007f97ed7000)
    libapt-pkg.so.5.0 => /usr/lib/aarch64-linux-gnu/libapt-pkg.so.5.0 (0x0000007f97d15000)  

It is linked against an earlier version of libapt-pkg. Note that if I run apt install apt without --reinstall I get told it is already up to the latest version, which makes sense since both binaries are 1.8.2.3.

I think you can see here how doing this kind of repair can quickly blossom into one task after another. Bases on your question, you have lost at least your apt-get binaries; even if you get them back there may be more problems waiting for you.

The truth is, you've partially trashed the system by accident. There's a couple of things to learn from that:

  • Be careful when using root/sudo powers.
  • KEEP BACK_UPS and perhaps notes so you can easily re-install. You could also learn to use an automated system like puppet, or simply keep notes and try to write scripts to do the same, and keep those backed up.
goldilocks
  • 56,430
  • 17
  • 109
  • 217
1

How can I reinstall without re-imaging?

Unless you're ascetic, don't waste your time. It's too late for a backup (more on that shortly), but you need not lose anything of value:

  1. Remove the SD card (yes - the one you've trashed) from your RPi, and set it aside in a safe place.

  2. Flash a new card & re-start your RPi

  3. Put your trashed SD card in a USB-SD adapter, insert that into a USB port on your newly-flashed system, and mount it.

You can now copy any file from your trashed system to your new system.

For backups, I use the image-utils scripts. A "how-to" was posted about a year ago that will help you get underway quickly. FWIW, I create a "base" image once a month, and incrementally update it every night in a cron job so I'll never lose more than 24 hours of changes.

Seamus
  • 18,728
  • 2
  • 27
  • 57