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.
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
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.