Possible to mount the Pi OS .img file using loopback?

Oct 18, 2023 Last reply: 2 years ago 2 Replies

Hi



I've downloaded 2023-10-10-raspios-bookworm-armhf.img.xz, used unxz to extract the .img file, and I'm trying to mount it so I can have a look at some of the files in it. I was trying to avoid having to write the image to an SD card.



$ file 2023-10-10-raspios-bookworm-armhf.img



2023-10-10-raspios-bookworm-armhf.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x40,0,1), end-CHS (0x3ff,3,32), startsector 8192, 1048576 sectors; partition 2 : ID=0x83, start-CHS (0x3ff,3,32), end-CHS (0x3ff,3,32), startsector 1056768, 9297920 sectors

$ sudo losetup -f --show 2023-10-10-raspios-bookworm-armhf.img /dev/loop0



$ sudo mount -t auto /dev/loop0 /mnt/image/ mount: /mnt/image: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.



I thought these image files were supposed to contain mountable filesystems, and I'm (almost) sure I've done this before with raspbian and Ubuntu images --- am I doing something wrong above?



The image file has multiple partitions, so you need to mount the partitions within the image, not the raw image itself. You either need:

$ sudo losetup -f -P --show 2023-10-10-raspios-bookworm-armhf.img

and you'll get devices per partition: /dev/loop0p1, loop0p2, etc

or, on an existing loopback device,

$ sudo partprobe /dev/loop0

and it'll create the partition devices. Then you can mount them:

$ sudo mkdir -p /mnt/boot /mnt/root $ sudo mount /dev/loop0p1 /mnt/boot $ sudo mount /dev/loop0p2 /mnt/root

Theo

Brilliant, thanks very much!

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required