how to change fat partition label on disk image file?

the command:

sudo mlabel -i /dev/sdb1 ::my_external

meant to apply the new label my_external for the /dev/sdb1 drive or partition, if only it's a separate device one. what would be the command for changing one of the partitions label name on the disk image file?

it would be very nice to get automation based solution as to be used for disk image generation recipes, scripts, etc.


You can map the partitions of a disk image through the loop device, as described in this answer.

sudo losetup --partscan --show --find binary.img

Use blkid to see which device name your partition was assigned (typ. /dev/loop0p1) as described in this answer.

sudo blkid