You mention in a comment to RooTer that A) you have reduced the initial partition size with gparted
, but dd
still copies the whole card, and B) that you want to include both partitions in the image.
Issue "A" is easy to explain: you are still copying the whole card because that's what /dev/mmcblk0
refers to. The individual partitions are of course /dev/mmcblk0p1
and /dev/mmcblk0p2
. This is the complication in issue
"B", but you cannot simply dd
each partition and concatenate the two files together, because of the partition table at the beginning of /dev/mmcblk0
which indexes the beginning and length of each partition. Without that, the image will be unusable.
However, you can get the length of each partition from fdisk -l
, and use that to determine some parameters for dd
. For example:
> fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 16.1 GB, 16138633216 bytes
4 heads, 16 sectors/track, 492512 cylinders, total 31520768 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00017b69
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 26746879 13312000 83 Linux
The "Start" and "End" units are sectors, and notice the sector size is given, 512 bytes. For /dev/mmcblk0p2
, 26746879 (the last sector) - 122880 (the first sector) = 26623999 / 2 (for 2 sectors per kB) / 1024 (kB per MB) / 1024 (MB per GB) = 12.69, which I grew the partition using gparted to 12 GB, so this looks correct (really I should be using 1000 and not 1024 as the divisor with storage, which works out to 13.31 GB, but I suspect gparted and some other tools also use 1024).
So the first thing you want to check is that your second partition is really the smaller size that you set it to. Next, just use those numbers with dd
; for me it would be:
dd if=/dev/mmcblk0 of=rpi.img bs=512 count=26746880
I've got an extra sector there to avoid any kind of off by one misunderstanding of how dd
works. There's a simple way to check if this worked:
> fdisk -l rpi.img
Disk rpi.img: 102 MB, 102400000 bytes
255 heads, 63 sectors/track, 12 cylinders, total 200000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00017b69
Device Boot Start End Blocks Id System
rpi.img1 8192 122879 57344 c W95 FAT32 (LBA)
rpi.img2 122880 26746879 13312000 83 Linux
Notice there is a bit of a discrepancy here: the "Start" and "End" sectors match the original partition table, but the total size in the stats up top is only 102 MB! This is because I actually used count=200000
as the param to dd
because I did not really want to bother with a 12 GB copy (notice also "total 200000 sectors"). The reason the table at the bottom does not reflect this is because fdisk is getting its information from the partition data copied verbatim at the beginning of the image from the beginning of the SD card, which, as I mentioned in the second paragraph, is vital to maintain. If I had (properly) copied the rest, the numbers would be copacetic and the image would be viable.
Give that a try. :)