Trying to copy Raspberry Pi OS to image using dd.

$diskutil list /dev/disk2
/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.9 GB    disk2
   1:             Windows_FAT_32 boot                    268.4 MB   disk2s1
   2:                      Linux                         2.7 GB     disk2s2

Running sudo dd bs=1m if=/dev/rdisk2 of=/Users/sunknudsen/tmp/pi-clean.img works but includes unallocated space which is inefficient.

  • You'll have to shrink the image first, or create one that fits.
    – goldilocks
    May 15 '21 at 15:52
  • Thanks for helping out... I removed init=/usr/lib/raspi-config/init_resize.sh from /boot/cmdline.txt so I believe I don’t need to shrink image first.
    – sunknudsen
    May 15 '21 at 15:57
  • 1
    So to clarify, the "unallocated space" you are referring to is the rest of the SD card? Ie., you do want the entire 2.7 GB partition but not the rest of the ~16 GB card. You could either copy the two partitions individually and concatenate them, or else create an image and copy in the content. I haven't tried the first method, but it should work if done properly.
    – goldilocks
    May 15 '21 at 16:37

dd by default copies the physical data - even if the data is zeros SD clone from menu in Raspberry OS uses "cp" command - I checked this while doing the clone ;-) But SD clone does much more than copying only the data (prepares partition table, modifies the /etc/fstat etc.) - it is binary file, not a script - so kind of difficult to see how it does step by step I did not manage to get anything better and efficient than SD clone yet - neither on Linux nor on MacOS - I would like to know it as well.


dd copies blocks (regardless of their contents).

macOS will not read the ext4 filesystem and is thus incapable of determining contents or shrinking the image.

You need a Linux system (which can be the Pi). There are many answers explaining how to do this.

You CAN determine the size of MBR plus boot plus root and instruct dd to copy just that, but this seems rather pointless as an unexpanded image is unusable.

I have written scripts using fdisk on the Mac to manipulate Pi image partitions but this is error prone and tedious and ultimately not particularly useful.

If you want to do this on a one off it is probably easier to manually calculate the size (using the output of fdisk list).


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.