I have a custom Raspbian image (based on Raspbian lite + some additional software installs) and I would like to clone this image and distribute it as part of an opensource project. How can I delete the WiFi credentials or other sensitive information from the cloned image. I know that I can always delete the credentials before cloning but I would like to automate the process so would rather not modify the image on the sd card.

  • What do you want to do? Clone the master SD Card and then modify the cloned image before distributing?
    – Ingo
    Aug 13, 2020 at 9:28
  • Exactly, yes that's what I want to do. Sorry I wasn't clear
    – glamis
    Aug 13, 2020 at 10:07

1 Answer 1


You want to clone the master SD Card and then modify the cloned image before distributing it. I assume you use a raw image file as for example created with dd. Because the image file contains the raw partitions and filesystems of the original SD Card you cannot just edit it.You have to mount the partitions in the image file. Then you are able to modify it.

You can use losetup on the running master SD Card to mount the image. Because you have a modified Raspbian Lite you should find two partitions:

rpi ~$ sudo losetup --find --partscan --show cloned.img
rpi ~$ ls /dev/loop0*
/dev/loop0  /dev/loop0p1  /dev/loop0p2

/dev/loop0p1 represents the first partition, which is the fat32 boot partition and /dev/loop0p2 is the ext4 root partition. Just mount them:

rpi ~$ sudo mount /dev/loop0p2 /mnt
rpi ~$ sudo mount /dev/loop0p1 /mnt/boot

Now you can access and modify the images content. The boot partition with kernel and firmware you find at /mnt/boot.

When finished unmount and detach the image:

rpi ~$ sudo umount /mnt/boot
rpi ~$ sudo umount /mnt
rpi ~$ sudo losetup --detach-all

These are all commands on the commandline, so you should be able to automate the process with a bash script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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