Suppose we made a Raspberry Pi image in a SD card and want to copy the image to hundreds of SD cards. How to do it fast?
First, let's have a look at the contents of the SD card.
There are two solutions in my mind:
Solution A
Shrink the rootfs partition of the SD card. We can use GParted or Gnome Disks to resize the rootfs partition and get some free space at the end of the SD card.
Use dd to copy the front part (with the boot partition and the rootfs partition, without the free space at the end) to a image file. For example, copy 6G data to pi.img image file.
Use dd or Gnome Disks (open the image file with Gnome Disks) to write the image file to other SD cards.
Extend the rootfs partition.
Solution B
If the writing speed of the SD card is very slow, shrink the rootfs of the SD card can be very slow. Then we can copy the whole contents to a image file and resize the image file. (Another case is that we already get a image file, skip step 1).
Use dd or Gnome Disks to copy the contents of the SD card to a image file.
sudo losetup --find --partscan pi.img
lsblk # find the loop device, the rootfs partition will be like loop0p2
sudo e2fsck -f /dev/loop0p2
sudo resize2fs -M xxx.img # or use Gnome Disks or GParted to resize the rootfs partition
Use dd to copy the front part of the image file (without the free space at the end) to other SD cards. For examples:
Suppose we made a Raspberry Pi image in a SD card and want to copy the image to hundreds of SD cards. How to do it fast?
First, let's have a look at the contents of the SD card.
There are two solutions in my mind:
Solution A
Shrink the rootfs partition of the SD card. We can use
GParted
orGnome Disks
to resize the rootfs partition and get some free space at the end of the SD card.Use
dd
to copy the front part (with the boot partition and the rootfs partition, without the free space at the end) to a image file. For example, copy 6G data topi.img
image file.Use
dd
orGnome Disks
(open the image file withGnome Disks
) to write the image file to other SD cards.Extend the rootfs partition.
Solution B
If the writing speed of the SD card is very slow, shrink the rootfs of the SD card can be very slow. Then we can copy the whole contents to a image file and resize the image file. (Another case is that we already get a image file, skip step 1).
Use
dd
orGnome Disks
to copy the contents of the SD card to a image file.Setup the image file as a loop device.
Use
dd
to copy the front part of the image file (without the free space at the end) to other SD cards. For examples: