Photo of SD card using <code>diskutil list</code>

Do you know how I could easily and portably (ie: work in windows and mac) take a raspbian disk image from an sd card and create an image that I could send to my colleague via dropbox? I need just the boot partition and the linux partition. It needs to be no more than 2gb if possible.

I would prefer to not use a crazy work around. Just a simple shell script would be nice. Or even an rsync workflow that is understandable lol!

Please help me with this problem so I can go to sleep! lol.


  • The question is a duplicate because what you really want to do is mount the partitions in the image, recreate them (using a smaller second partition) and rsync the contents from the original into the new smaller version. You'll need to use dd and fdisk to create the new versions, see here. Beware that Milliway's scripted version is likely to loose data if the system has been used much since it does not copy the contents, it just copies raw blocks.
    – goldilocks
    Mar 26, 2016 at 16:03
  • WRT caveats and details about rsync'ing the contents, see: raspberrypi.stackexchange.com/a/5492/5538
    – goldilocks
    Mar 26, 2016 at 16:07
  • @goldilocks I cannot agree that this " is likely to loose data". Yes dd copies/moves blocks but the mapping of these blocks to physical storage is a function of the SD Card firmware (as I am sure you pointed out to me in the past when I raised the issue of data loss with another questioner)
    – Milliways
    Mar 26, 2016 at 22:43
  • It doesn't matter. The SD card firmware has no concept of what the content of the blocks is, and neither does dd. However, the filesystem is structured using them, and does assign them specific content. Whether they are real or virtual on the device is irrelevant. So if you have a filesystem 20 blocks in size and you've only used 7, those 7 may be dispersed. They are not necessarily 1-7.
    – goldilocks
    Mar 26, 2016 at 22:51
  • ...However, when you use dd and copy half the blocks, you copy 1-10. Again, it does not matter whether those are "real" or "virtual" numbers with respect to the physical device. They are real to filesystem. So if 13, 14, and 19 were 3 of the 7 blocks used, you just lost 3/7 of the data in the filesystem.
    – goldilocks
    Mar 26, 2016 at 22:51

2 Answers 2


you can create a new 2GB ext4 image, mount it, and copy all the linux partition files over. The boot partition probably is as small as it should be. Or if you put the sd card into a ubuntu computer for example, then use gparted, and see if you can resize the linux partition.

  • Im trying to avoid running a vm, I feel thats too much for something that should be so simple. How do i create a ext4 image? Are you able to point me towards a shell script I could use? Thanks!
    – danielbh
    Mar 25, 2016 at 13:14
  • @danielbh what distro/os are you on?
    – el3ien
    Mar 25, 2016 at 13:15
  • I use mac or windows. The pi has raspbian. Not sure which os you mean lol
    – danielbh
    Mar 25, 2016 at 13:16
  • @danielbh you could do it on the raspberry if you have a usb-sdcard adapter, and an extra raspbian sd card. I suppose you can do it on mac too. But I have not tried mac yet.
    – el3ien
    Mar 25, 2016 at 13:18
  • @danielbh Actually you can do it on raspberry without an extra sdcard. Do you have 2GB+ free space on the linuxpartition?
    – el3ien
    Mar 25, 2016 at 13:21

I just realised that provided you don't need to resize any partitions you can actually do it on the Mac.

WARNING Make doubly sure that you don't accidentally write in the wrong place.

The following script I wrote to rearrange Ubuntu MATE partitions and you should be able to adapt this to copy your data.

NOTE All care BUT no responsibility, and you really need to understand partitioning!

# script to create a Ubunutu MATE image with properly aligned partitions
# 2015-11-06


# Partition details of input image


# Partition details of output image

# End of user configuration
#let IMG_END=$P2NEW+$P2SIZE+140000
echo -e $P1START - $P1NEW $P1SIZE
echo -e $P2START - $P2NEW $P2SIZE
echo -e $IMG_END

# Create an empty image file
dd if=/dev/zero of=$OUTPUT_IMG count=$IMG_END

# Create partitions
echo -e "
e 1
e 2
quit" | fdisk -e  $OUTPUT_IMG

echo "Finished Create partitions"
# Copy partitions
dd if=$INPUT_IMG skip=$P1START of=$OUTPUT_IMG seek=$P1NEW count=$P1SIZE
dd if=$INPUT_IMG skip=$P2START of=$OUTPUT_IMG seek=$P2NEW count=$P2SIZE

#fdisk $OUTPUT_IMG
  • Ok thanks. It's late here. I'll try this tomorrow. Your help is much appreciated!
    – danielbh
    Mar 26, 2016 at 0:25
  • I ended up caving and just installing ubuntu. It seems like the smarter choice when working with the raspbi. Thanks for your help though!
    – danielbh
    Mar 26, 2016 at 14:59

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