When mkimg(1) is asked to output a partition of a given size with a given absolute offset into a raw image, it does not size the output file properly.
When no offset is given, the file is sized correctly:
$ mkimg -f raw -o temp.img -s mbr -p freebsd::512000
creates a file that is 1001 blocks long.
Relative offsets work well:
$ mkimg -f raw -o temp.img -s mbr -p freebsd::512000:+512
creates a file that is 1002 blocks long.
$ mkimg -f raw -o temp.img -s mbr -p freebsd::512000:512
creates a file that is only 1 block long, instead of 1001.
Looking at the code, in file mkimg.c the problem seems to be that the "block" variable is not updated with the partition size. But I could not understand the code well enough to propose a patch, unfortunately.
$ uname -a
FreeBSD myhost 11.4-STABLE FreeBSD 11.4-STABLE #1 r369279: Tue Feb 16 10:16:53 CET 2021 root@myhost:/usr/obj/usr/src/sys/GENERIC amd64
$ svn info /usr/src/usr.bin/mkimg | grep Revision
This was recently fixed (i.e., today) in commit by manu:
(In reply to Robert Wing from comment #1)
closed out by commit:
Thank you, Robert.
I see the commit was not merged into stable/11.
I trust this will happen soon.
Thank you and best regards.