How to use DD to clone a partition off a disk image?

# losetup --find --show --partscan --read-only 2013-02-09-wheezy-raspbian.img
/dev/loop7
# dd if=/dev/loop7p2 of=/dev/narnia bs=1M

If --partscan doesn't work, you can also use one of:

# partx -a /dev/loop7
# kpartx /dev/loop7

or similar partition mapping solutions.

You should probably mount it first just to see if it's the right thing or what.

Of course you can also read the fdisk output and give dd the skip=131072 or whatever directly, i.e. make it skip that many blocks of input so it starts reading at where the partition is located; but it's nicer to see actual partitions with a loop device.

Tags:

Disk

Dd

Partition