Using dd to create an image of an only partially filled SD-card
When using dd to create an image of a 16GB SD card that is only partially partitioned with 4GB the resulting file will be 16GB in size. The command to do this is simple:dd if=/dev/sdb of=image.img
Despite of this "limitation" (the source of the command above is the whole device) dd can be used yet to create an image of the relevant 4GB.
The first step is to check the current partitioning scheme:
root@NC10SA:~# fdisk -l /dev/sdb
Disk /dev/sdb: 15.9 GB, 15931539456 bytes
64 heads, 32 sectors/track, 15193 cylinders, total 31116288 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: 0x000981cb
Device Boot Start End Blocks Id System
/dev/sdb1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/sdb2 122880 8511487 4194304 83 Linux
The important values in this output are the end of the last partition on the drive (8511487) and the size of a sector (512 bytes).
To compensate all possibilities in the implementation of dd 1 is added to the end. The result is the following command which reads 8511488 512 byte sectors and dumps them to the image.
To compensate all possibilities in the implementation of dd 1 is added to the end. The result is the following command which reads 8511488 512 byte sectors and dumps them to the image.
root@NC10SA:~# dd if=/dev/sdb of=infodisplay-4g.img bs=512 count=8511488
8511488+0 records in
8511488+0 records out
4357881856 bytes (4.4 GB) copied, 257.445 s, 16.9 MB/s
The partitioning scheme of the image created shows that all partitions are contained in there and that the size corresponds the size of the source.
root@NC10SA:~# fdisk -l infodisplay-4g.img
Disk infodisplay-4g.img: 4357 MB, 4357881856 bytes
255 heads, 63 sectors/track, 529 cylinders, total 8511488 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: 0x000981cb
Device Boot Start End Blocks Id System
infodisplay-4g.img1 8192 122879 57344 c W95 FAT32 (LBA)
infodisplay-4g.img2 122880 8511487 4194304 83 Linux