Qemu Chroot Into an Img File
Preface
Full disk images contain the bootloader and partition table. To mount an image file, view the contents of the file, then specify a byte offset that points to the beginning of our linux root partition. We're essentially telling our mount command start reading the IMG file from somanybytes from the start.
Mounting the image
Run fdisk -l file.img.
Here, you want to make note of the value under the "START" column. Basing it off the size of the paritions, I can assume my root partition is the one that starts at 532480 bytes in.
[...]
Units: sectors of 1 * 512 = 512 bytes
[...]
Device Boot Start End Sectors Size Id Type
2021-05-07-raspios-buster-armhf-lite.img1 8192 532479 524288 256M c W95 FAT32 (LBA)
2021-05-07-raspios-buster-armhf-lite.img2 532480 3661823 3129344 1.5G 83 Linux
Now I have to multiple the start sector (532480) by the sector size (512). I'm using the bash to do the multiplication from within my mount command.
mount -o loop,offset=$((512*532480)),rw ~/2021-05-07-raspios-buster-armhf-lite.img /mnt
-o Pass options to mount
loop Creates a psuedo block device to mount the image file to
offset=$((512*532480)) Sets the offset to the sum of 512*startSector
rw Enables reading and writing to the mountpoint
Conclusion
The drive should be mounted. If your root partition isn't the last partition, you'll want to google how to specify the start/end byte offset for mount.