Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get two loop devices at the same time?

448 views
Skip to first unread message

Chris Green

unread,
Aug 3, 2021, 4:03:04 AM8/3/21
to
I want to mount both partitions of a .img disk image file at the same
time, by default 'mount -o ....' uses the same loop device so on
trying to mount the second partition one sees:-

mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/raspbian/2021-05-07-raspios-buster-armhf-lite.img.

How do I crete a second loop device and get mount to use it?


--
Chris Green
·

Andrzej Adam Filip

unread,
Aug 3, 2021, 4:18:58 AM8/3/21
to
According to "man mount" (on my comp)
'mount -o loop' (no explicit loop device) should try to find/use
unused loop device. Alternatively you may use
'mount -o loop=…' to explicitly name loop device.

--
[Andrew] Andrzej A. Filip

Andy Burns

unread,
Aug 3, 2021, 4:29:26 AM8/3/21
to
or try losetup, long time since I needed it.


Chris Green

unread,
Aug 3, 2021, 5:18:04 AM8/3/21
to
That doesn't seem to work though:-

root@t470# fdisk -l 2021-05-07-raspios-buster-armhf-lite.img
Disk 2021-05-07-raspios-buster-armhf-lite.img: 1.75 GiB, 1874853888 bytes, 3661824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9730496b

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
root@t470# mkdir -p /tmp/boot
root@t470# mkdir -p /tmp/rootfs
root@t470# mount -o loop,offset=$((8192 * 512)) 2021-05-07-raspios-buster-armhf-lite.img /tmp/boot
root@t470# mount -o loop,offset=$((532480 * 512)) 2021-05-07-raspios-buster-armhf-lite.img /tmp/rootfs
mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/pi/2021-05-07-raspios-buster-armhf-lite.img.
root@t470#





--
Chris Green
·

Chris Green

unread,
Aug 3, 2021, 6:33:03 AM8/3/21
to
Chris Green <c...@isbd.net> wrote:
> Andrzej Adam Filip <an...@onet.eu> wrote:
> > Chris Green <c...@isbd.net> wrote:
> > > I want to mount both partitions of a .img disk image file at the same
> > > time, by default 'mount -o ....' uses the same loop device so on
> > > trying to mount the second partition one sees:-
> > >
> > > mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/raspbian/2021-05-07-raspios-buster-armhf-lite.img.
>
> > ^M
> >
> > >
> > > How do I crete a second loop device and get mount to use it?
> >
> > According to "man mount" (on my comp)
> > 'mount -o loop' (no explicit loop device) should try to find/use
> > unused loop device. Alternatively you may use
> > 'mount -o loop=…' to explicitly name loop device.
> >
> That doesn't seem to work though:-
>
> root@t470# fdisk -l 2021-05-07-raspios-buster-armhf-lite.img
> Disk 2021-05-07-raspios-buster-armhf-lite.img: 1.75 GiB, 1874853888 bytes, 3661824 sectors
> Units: sectors of 1 * 512 = 512 bytes
> Sector size (logical/physical): 512 bytes / 512 bytes
> I/O size (minimum/optimal): 512 bytes / 512 bytes
> Disklabel type: dos
> Disk identifier: 0x9730496b
>
> 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
> root@t470# mkdir -p /tmp/boot
> root@t470# mkdir -p /tmp/rootfs
> root@t470# mount -o loop,offset=$((8192 * 512)) 2021-05-07-raspios-buster-armhf-lite.img
> /tmp/boot
> root@t470# mount -o loop,offset=$((532480 * 512)) 2021-05-07-raspios-buster-armhf-lite.img
> /tmp/rootfs
> mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/pi/2021-05-07-raspios-buster-armhf-lite.img.
>
> root@t470#
>
I found the answer (well, an answer), you need to limit the size of
the first mount so (as the error message tells you) it doesn't overlap
the second mount.

The fdisk output shows the size, so the first mount needs to be:-

mount -o loop,offset=$((532480 * 512)),sizelimit=256M 2021-05-07-raspios-buster-armhf-lite.img

then the second one works OK with no error.


Alternatively you can install kpartx and run:-

kpartx -av 2021-05-07-raspios-buster-armhf-lite.img

which does (almost) everything in one go, the partitions then get
automounted.

--
Chris Green
·

Chris Green

unread,
Aug 3, 2021, 7:16:20 AM8/3/21
to
I want to mount both partitions of a .img disk image file at the same
time, by default 'mount -o ....' uses the same loop device so on
trying to mount the second partition one sees:-

mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/raspbian/2021-05-07-raspios-buster-armhf-lite.img.

How do I crete a second loop device and get mount to use it?


--
Chris Green
·

Andrzej Adam Filip

unread,
Aug 3, 2021, 7:16:21 AM8/3/21
to
According to "man mount" (on my comp)
'mount -o loop' (no explicit loop device) should try to find/use
unused loop device. Alternatively you may use
'mount -o loop=…' to explicitly name loop device.

Andy Burns

unread,
Aug 3, 2021, 7:16:21 AM8/3/21
to

Chris Green

unread,
Aug 3, 2021, 7:16:21 AM8/3/21
to
That doesn't seem to work though:-

root@t470# fdisk -l 2021-05-07-raspios-buster-armhf-lite.img
Disk 2021-05-07-raspios-buster-armhf-lite.img: 1.75 GiB, 1874853888 bytes, 3661824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9730496b

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
root@t470# mkdir -p /tmp/boot
root@t470# mkdir -p /tmp/rootfs
root@t470# mount -o loop,offset=$((8192 * 512)) 2021-05-07-raspios-buster-armhf-lite.img /tmp/boot
root@t470# mount -o loop,offset=$((532480 * 512)) 2021-05-07-raspios-buster-armhf-lite.img /tmp/rootfs

Chris Green

unread,
Aug 3, 2021, 7:16:21 AM8/3/21
to
Chris Green <c...@isbd.net> wrote:
> Andrzej Adam Filip <an...@onet.eu> wrote:
> > Chris Green <c...@isbd.net> wrote:
> > > I want to mount both partitions of a .img disk image file at the same
> > > time, by default 'mount -o ....' uses the same loop device so on
> > > trying to mount the second partition one sees:-
> > >
> > > mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/raspbian/2021-05-07-raspios-buster-armhf-lite.img.
>
> > ^M
> >
> > >
> > > How do I crete a second loop device and get mount to use it?
> >
> > According to "man mount" (on my comp)
> > 'mount -o loop' (no explicit loop device) should try to find/use
> > unused loop device. Alternatively you may use
> > 'mount -o loop=…' to explicitly name loop device.
> >
> That doesn't seem to work though:-
>
> root@t470# fdisk -l 2021-05-07-raspios-buster-armhf-lite.img
> Disk 2021-05-07-raspios-buster-armhf-lite.img: 1.75 GiB, 1874853888 bytes, 3661824 sectors
> Units: sectors of 1 * 512 = 512 bytes
> Sector size (logical/physical): 512 bytes / 512 bytes
> I/O size (minimum/optimal): 512 bytes / 512 bytes
> Disklabel type: dos
> Disk identifier: 0x9730496b
>
> 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
> root@t470# mkdir -p /tmp/boot
> root@t470# mkdir -p /tmp/rootfs
> root@t470# mount -o loop,offset=$((8192 * 512)) 2021-05-07-raspios-buster-armhf-lite.img
> /tmp/boot
> root@t470# mount -o loop,offset=$((532480 * 512)) 2021-05-07-raspios-buster-armhf-lite.img
> /tmp/rootfs
> mount: /tmp/rootfs: overlapping loop device exists for /home/chris/dld/pi/2021-05-07-raspios-buster-armhf-lite.img.
>
> root@t470#
>

Andy Burns

unread,
Aug 3, 2021, 7:43:31 AM8/3/21
to
Chris Green wrote:

> Alternatively you can install kpartx

Yes, I used to find that handy when using Xen VMs with LVM for storage.

Andy Burns

unread,
Aug 3, 2021, 1:17:28 PM8/3/21
to
0 new messages