0

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.

THANK YOU!!!

6
  • 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. Commented Mar 26, 2016 at 16:03
  • WRT caveats and details about rsync'ing the contents, see: raspberrypi.stackexchange.com/a/5492/5538 Commented 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) Commented 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. Commented 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. Commented Mar 26, 2016 at 22:51

2 Answers 2

0

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.

8
  • 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! Commented Mar 25, 2016 at 13:14
  • @danielbh what distro/os are you on? Commented Mar 25, 2016 at 13:15
  • I use mac or windows. The pi has raspbian. Not sure which os you mean lol Commented 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. Commented 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? Commented Mar 25, 2016 at 13:21
-1

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!

#!/bin/bash # script to create a Ubunutu MATE image with properly aligned partitions # 2015-11-06 echo #INPUT_IMG="ubuntu-mate-15.10-desktop-armhf-raspberry-pi-2.img" INPUT_IMG="PiMate1510back20151106_small.img" OUTPUT_IMG="ubuntu-mate-15.10.img" # Partition details of input image P1START=2048 P1SIZE=131072 P2START=133120 P2SIZE=7546880 # Partition details of output image P1NEW=8192 P2NEW=139264 # End of user configuration #let IMG_END=$P2NEW+$P2SIZE+140000 let IMG_END=$P2NEW+$P2SIZE 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 0C n $P1NEW $P1SIZE e 2 83 n $P2NEW $P2SIZE 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 
2
  • Ok thanks. It's late here. I'll try this tomorrow. Your help is much appreciated! Commented 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! Commented Mar 26, 2016 at 14:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.