2

I have a raspberry pi compute module with me and I have installed a number of programs into it. I have to reinstall the same programs on a number of such modules. Is there any way that I can create an image of all the programs together that is whatever is installed in my compute module so that I just have to burn that image into the remaining other modules. can someone pls help me out with this.

1 Answer 1

2

Put out the SD Card from the compute module and plug it into a card reader attached to another linux computer. Assuming the SD Card is seen as /dev/sdb on the computer you create a complete image of the SD Card with:

rpi ~$ sudo dd if=/dev/sdb of=sdcard.img bs=4M conv=fsync

Then replace the SD Card in the card reader with an empty one and flash it with the image:

rpi ~$ sudo dd if=sdcard.img of=/dev/sdb bs=4M conv=fsync

You should ensure to use exact the same SD Card as the master card or a greater one otherwise the flashing will fail because the image doesn't fit. There are ways to shrink the image but that's not part of this question.

If you want to take an image from the running system itself without unplug the SD Card then there is a general problem. A running system changes many files dynamically even if you don't do anything. If you take an image of the system during changing files you do not have a consistent system if you restore it. To ensure that no files are changed you must boot your system in read only mode. This is done by editing /etc/fstab and append ro to the options of the root partition (ext4) and of the boot partition (vfat), for example:

rpi ~$ cat /etc/fstab
proc                  /proc   proc    defaults             0   0
PARTUUID=7ee80803-01  /boot   vfat    ro,defaults          0   2
PARTUUID=7ee80803-02  /       ext4    ro,defaults,noatime  0   1

If you reboot into this, then you will get some error messages because the system cannot write its dynamic files but the dd program should work. Check if the root and boot partitions are ro with:

rpi ~$ findmnt /
TARGET SOURCE         FSTYPE OPTIONS
/      /dev/mmcblk0p2 ext4   ro,noatime,data=ordered
rpi ~$ findmnt -n /boot
/boot  /dev/mmcblk0p1 vfat   ro,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro

rpi ~$ touch test.tmp
touch: cannot touch 'test.tmp': Read-only file system

I assume you have attached an external storage at /dev/sda, e.g. an USB stick with partition /dev/sda1, then you can take an image with:

rpi ~$ sudo mount /dev/sda1 /mnt
rpi ~$ sudo dd if=/dev/mmcblk0 of=/mnt/sdcard.img bs=4M conv=fsync
rpi ~$ sudo umount /dev/sda1

If you have attached the new SD Card with a card reader to the RasPi and it is mapped to /dev/sda then you can clone it direct:

rpi ~$ sudo dd if=/dev/mmcblk0 of=/sda bs=4M conv=fsync

If finished then remove the ro options from within /etc/fstab and reboot.

6
  • Thank you so much for your response. Can I do this without plugging out the sd card from my compute module.. like I have an raspberry pi IO board with me using which I had flashed my compute module. Is there any way to do with that. Thank you so much once again.
    – roshini
    Commented Jan 28, 2019 at 5:09
  • @roshini I have updated my answer.
    – Ingo
    Commented Jan 28, 2019 at 22:52
  • 1
    You should probably also generate a new SSH host key for each image, as well as any other magic numbers that are intended to be unique-per-machine.
    – mlp
    Commented Jan 28, 2019 at 23:03
  • @mlp Do you do it also with the default downloaded Raspbian Image? Or is it done on first boot of that image? I don't know.
    – Ingo
    Commented Jan 28, 2019 at 23:08
  • As of 2015, host keys are regenerated on first run of raspi-config. See raspberrypi.org/forums/viewtopic.php?t=125345
    – mlp
    Commented Jan 30, 2019 at 1:17

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.