I have 8GB USB drive attached to my system which looks like this:
[root@host]# fdisk -l /dev/sdb
Disk /dev/sdb: 8462 MB, 8462008320 bytes
255 heads, 63 sectors/track, 1028 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5c0894d9
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 9 72261 e W95 FAT16 (LBA)
/dev/sdb2 10 103 755055 83 Linux
[root@host]#
So basically my FAT partition is around 70 MB, ext2 partition is around 740MB and rest of the space (~ 7 GB) is unallocated . Now when I dd my USB hard drive via:
dd if=/dev/sdb of=myimage.img bs=1M
the output file (myimage.img) is around 8GB which is the normal operation of dd.
Question: What I am looking for is a way to directly clone my USB hard drive without the unallocated space so that my result file is around 1 GB uncompressed instead of 8 GB. The reason I am asking is because the output file (myimage.img) is being used by a simulator program to boot the image. The simulator can handle 8 GB files but I don't want to waste my disk space.