1
I am creating a disk image and copy a mbr on it:
dd if=/dev/zero bs=2M count=256 > ./hd.img
dd if=mbr.bin of=hd.img conv=notrunc
sfdisk --force ./hd.img < partitions.sfdisk
where partitions.sfdisk
looks like this:
2048,,0x83,*
fdisk -lu hd.img
now lists this:
./hd.img1 * 2048 1048575 1046528 511M 83 Linux
with sectors of 512
bytes.
Now I want to format hd.img1
with ext4
without creating a loop device. So I created a second image hd.img1
with the size of 512MB - (2048 x 512)
bytes. I executed
mkfs.ext4 hd.img1
and now I want to copy hd.img1
into hd.img
on the position of the created partition hd1.img
.
Is that even possible? Do I have to dd
hd.img1
with an offset (skip) of 2048 x 512
?
dd if=hd.img1 of=hd.img skip=2048 bs=512
When I do that it seems that I've overwritten my partition table created with sfdisk
so I am obviously doing something wrong.
Instead of
dd if=/dev/zero ...
you can usetruncate
orfallocate
. Check their manuals. – Kamil Maciorowski – 2017-08-14T06:58:07.907