I do a fair amount of work with SD cards and use dd to create an image
for backup or for burning onto other cards. If I burn an image from an
8GB card onto a 16GB card then I get a card which is only half used.
If I then make an image from that one then I get a 16GB image (of
which only 8GB or less is partitioned) which is larger than it needs
to be and also if I burn that onto another 8GB card then it fails as
the card is not large enough (or at least it says it has failed, the
card will in fact be ok).

The ideal would be a script which uses dd to make the image, but only
copies as much as is necessary of the card.  Before starting on a
script I thought I would bounce the idea of those here in case anyone
can see a flaw in my method, or has a better idea.

Running fdisk -l /dev/sdb gives

$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 14.9 GiB, 15931539456 bytes, 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
Disklabel type: dos
Disk identifier: 0xe5cfcef7

Device     Boot  Start     End Sectors Size Id Type
/dev/sdb1         8192  137215  129024  63M  c W95 FAT32 (LBA)
/dev/sdb2       137216 4233215 4096000   2G 83 Linux

>From which I see that the sector size is 512 bytes and the end sector
of the last partition is 4233215.  From this I deduce that I must tell
dd to copy (4233215+1)*512 bytes.  Am I missing anything here?  If
that is correct then I can see that I could write a script to use
fdisk to get the sector size and the highest value of end sector and
call dd accordingly.

Any better ideas?



Reply via email to