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.

  • And if you put previous SD-Card, there is no problem with apt-get?
    – M. Rostami
    Jan 7 '20 at 22:29
  • 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? Any idea of how to fix this? I don't want to have to do a re-install.
    – ifschleife
    Jan 7 '20 at 22:31
  • I realized that the problem happened because of a mistake with cloning. Follow instructions by this link. (Linux part) thepihut.com/blogs/raspberry-pi-tutorials/…
    – M. Rostami
    Jan 7 '20 at 22:44

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.

  • Thanks for the tip on how to fix apt but I tried that myself and it did not help. The error remains the same after re-enabling the sources.
    – ifschleife
    Jan 12 '20 at 15:29

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.

  • 1
    Well, of course I shouldn't have copied the non-working image back. But I was (not so) young, lazy and out of disk space ;) Anyway, refreshing the key had no effect, bypassing the signature check also does not work. Everything results in the exact same error that I posted in my original question. I fear a re-install will be necessary :|
    – ifschleife
    Jan 13 '20 at 22:40
  • Do you mean that the apt-key commands succeed, but apt-get fails nevertheless? Are you able to install packages using dpkg? In any case, the complexity of recovering a failed apt installation is usually significant, so I would just reinstall the system if I were you. Jan 14 '20 at 8:09
  • Yes, that's the weird part. apt-key seems to behave fine. In fact the entire system works just fine. the only thing that I know that does not work is apt-get update and hence the system can't be updated. I have the feeling that the error about apt-key is a red herring and there is something else wrong with apt. But yeah, doing a fresh install seems like the only option. Serves me right for being lazy.
    – ifschleife
    Jan 14 '20 at 21:02

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


  • 2
    Are you suggesting to use dd on a mounted filesystem? That seems to be the only difference to what I did, or am I misunderstanding something? I indeed forgot to do the sync, so maybe that is the issue.
    – ifschleife
    Jan 8 '20 at 22:47
  • Yes. I hope it solve your problem.
    – M. Rostami
    Jan 8 '20 at 22:48
  • 2
    @ifschleife You can also append conv=fsync to the dd command. This will flush the write buffers authomaticaly by dd.
    – Ingo
    Jan 9 '20 at 8:26
  • 1
    @M.Rostami I asked because I think it's usually a bad idea to use dd on a mounted filesystem, is it not? I think dd even warns about trying that. Either way it's too late for me, as I don't have the original SD card anymore, so I need to find a way to fix the broken system.
    – ifschleife
    Jan 12 '20 at 15:32
  • @ifschleife Did you tried these commands? sudo apt-get clean, sudo apt-get autoremove, sudo apt-get update.
    – M. Rostami
    Jan 13 '20 at 8:03

As others have pointed out the problem is your cloning procedure.

The suggested solutions DO work, but there are limitations on SD Card size and EXTREME care is required.

https://raspberrypi.stackexchange.com/a/104644/8697 discusses the merits of different methods, but SD Card copier works. (I use method 4 and Etcher to clone cards).

  • 2
    What EXTREME care should be taken? if the destination card is larger then nothing happens. You only waste the not used space. If the destination card is smaller then dd will exit with error message "no space left over". Of course you should not ignore this error.
    – Ingo
    Jan 9 '20 at 8:36
  • @Ingo I can assure you if the wrong /dev is selected the results are catastrophic. I NEVER use these raw commands - only in scripts which check EVERYTHING first. Of cause those who are perfect don't need to worry about human frailties but many people have overwritten other partitions.
    – Milliways
    Jan 9 '20 at 11:28
  • @Milliways OK :-)
    – Ingo
    Jan 9 '20 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.