2

I copied a working raspbian buster installation from one SD card to another (raspberry pi 4). I did so by simply calling dd if=/dev/mmcblk0 of=raspbian bs=1M on my Notebook with the existing SD card plugged in. I then did the opposite to copy the image to the new SD card by doing dd if=raspbian of=/dev/mmcblk0 bs=1M. The system boots fine and expanding the root partition worked perfectly.

However, for some reason, I cannot run apt-get update when using the new SD card. This is what apt-get reports:

Get:1 http://archive.raspberrypi.org/debian buster InRelease [25.2 kB]
Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]               
Err:1 http://archive.raspberrypi.org/debian buster InRelease
  Unknown error executing apt-key
Err:2 http://raspbian.raspberrypi.org/raspbian buster InRelease
  Unknown error executing apt-key
Fetched 40.2 kB in 1s (49.8 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://archive.raspberrypi.org/debian buster InRelease: Unknown error executing apt-key
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://raspbian.raspberrypi.org/raspbian buster InRelease: Unknown error executing apt-key
W: Failed to fetch http://raspbian.raspberrypi.org/raspbian/dists/buster/InRelease  Unknown error executing apt-key
W: Failed to fetch http://archive.raspberrypi.org/debian/dists/buster/InRelease  Unknown error executing apt-key
W: Some index files failed to download. They have been ignored, or old ones used instead.

I tried lots of different things to resolve the issue, but google only shows potential solutions for corrupted gpg key databases. None of those worked and I have the feeling that it's something else.

Do I have to do anything special after creating a copy like that?

Update with info from comment:
apt-get works fine with the previous card. For testing, I copied the image onto the old card, which broke apt-get as well then. So I guess the image is broken in some way?

Update: As I broke the existing SD card with further testing, no amount of dd magic will fix the issue now, I'm afraid. So I need to find a way to fix the issue apt-get and apt-key are having. Resetting the sources did not help.

ifschleife
  • 129
  • 1
  • 4

3 Answers3

1

I would clone the SD Card the same way as you did and all suggested tutorials on the answers here also suggest to do it this way. You copied the image back to the original SD Card and getting the error so I also would guess that the image isn't identical to the original SD Card contents. But the original is lost now :-(

With critical images I take some more effort to verify it. You can use

pc ~$ sudo cmp --print-bytes /dev/sda raspbian.img

But I prefer to create a checksum that you can archive with the image:

pc ~$ sudo sha256sum /dev/sda > raspbian.img.sha256
pc ~$ cat raspbian.img.sha256   # example
1e7d4d4c8a36a0a3a14140f6aac2b5b002196e313168aa58864bbcdea56ab17e  /dev/sda

Now take the image and in raspbian.img.sha256 modify /dev/sda to raspbian.img but don't touch the checksum. Verify the image

pc ~$ sha256sum -c raspbian.img.sha256

But as already said this is no longer possible for you because you destroyed the original image. You only can try to reinitialize the apt cache in the hope that will fix the copy. How to do it you can look at Raspberry Pi sudo apt-get update not working.

Ingo
  • 42,961
  • 20
  • 87
  • 207
1

You shouldn't have copied the non-working image back to the old card for a test. Rather, you should have re-created the backup image from the working card again. There is a good chance that the error would have gone away.

For now, I would try to restore the GPG keys of Raspbian repositories:

sudo apt-key list
sudo apt-key remove XXXXXXX # Get the Raspbian key ID from the list
wget https://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -

Either that will work, or you will get a more meaningful error message instead of "Unknown error executing apt-key".

As a last resort solution, see How do I bypass/ignore the gpg signature checks of apt? Note that while you may want to take the risk of installing unsigned packages one time, doing so on a regular basis may eventually get you hacked, so if you can't get apt to run normally, it's strongly advised to start from scratch.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147
-1

The problem is with your procedure of cloning. Follow the instructions.

Assume the SD-Card mounted on /dev/sda. So, put the SD-Card to the system and fire this command to clone:

sudo dd if=/dev/sda of=/home/rpibackup.img  

Unmount the mounted partitions:

sudo umount /dev/sda1
sudo umount /dev/sda2  

Now, put another SD-Card to the system for writing the cloned image. Assume it mounted on /dev/sdb:

sudo dd bs=4M if=/home/rpibackup.img of=/dev/sdb  

Before ejecting the SD card, make sure the system has completed writing to it using the command:

sudo sync

Done.

Mohi Rostami
  • 4,434
  • 1
  • 20
  • 39