I recommend truncate
instead of quirky dd
command that creates 3GiB sparse file + 1 byte zeros. truncate
use sparse file as well. With -s 3G
you get a image of precisely 3GiB sparse file with no zeros (or you can use count=0
for dd
too):
I prefer doing it "in-place" with truncate
, since cat
would convert the sparse file to zeros (although that might be what you want), which costs time, space, and excessive write.
The following example does it "in-place" (see the +
prefix between -s
and 3G
in the truncate
command):
As you can see, you need to resize the partition (e.g. with fdisk
) as well. So you need to use losetup -P
instead of just attaching the partition by specifying an offset. This is what you've missed since the solution you linked/quoted applies to a filesystem image only.
When you recreate the partition entry after deleting the original one, make sure it starts at the same LBA as the original (in the example it's 206848
), otherwise the filesystem will be lost.