Replies: 1 comment
-
This has nothing to do with podman really, I am not sure why you are even be allowed to manipulate disks. The kernel will never allow an unprivileged user namespace to mount "real" file systems. https://man7.org/linux/man-pages/man7/user_namespaces.7.html
So I would say whatever you want to do is not possible. I don't know how loop devices work in general but if it /dev/loop-control talks to the host and then it will create the device nodes there as it doesn't seem to be namespace aware. You likely would need to create your own device node in the container namespace which again is not possible as the kernel will block that. Permission wise this just doesn't sounds like it can ever work. Now you could try to mount all devices with something like |
Beta Was this translation helpful? Give feedback.
-
Issue Description
My ultimate goal is to create a disk image file in a rootless container.
The usual pattern is to create a file (e.g., using
dd
), usesfdisk
orparted
to create a partition table andlosetup
andkpartx
to map the file via loop devices,mkfs
to create the filesystem,grub2-install
or similar for bootable disks, and then finallymount
the loop devices to interact with the filesystem.Anyhow, I'd like to do this in a podman container (one of our build steps is to create a disk/iso image); specifically a rootless container that has the requisite permissions to be able to use loop devices. So far, in order to accomplish this I've had to add my user to the
disk
group and add the following options:If my disk image were a single partition, I think I'd be ok, as in order to mount the "disk", all I'd need to do is mount
/dev/loop0
, which I've already mapped to the container. However, since the disk has multiple partitions, I need to mount/dev/loop0p1
and/dev/loop0p2
.The
losetup
command to create those devnodes works in the container, but the devnodes are only visible in the host environment (i.e.,loop0p1
andloop0p2
are only listed in/dev
in the host environment, NOT in the podman container).I can't simply add
--device /dev/loop0p1
to the podman run command, because at the time of invocation, those devnodes do not exist. They are only created afterlosetup
is run.So finally, the issue is there doesn't seem to be a way to get dynamically created devnodes to show up in the (rootless) container...
Steps to reproduce the issue
Steps to reproduce the issue:
disk
group:sudo usermod -aG disk <user>
--device /dev/loop-control:/dev/loop-control:rwm --security-opt unmask=/sys/dev/block --device /dev/loop0:/dev/loop0:rwm
In the container (assuming the container has the parted and losetup utilities)
dd if=/dev/zero of=disk.img bs=1000 count=0 seek=1000000
set up the loop device(s):
/sbin/losetup -Pf --show disk.img
run
ls /dev/loop*
(The issue is you will only see /dev/loop-control and /dev/loop0. On the Host you will additionally see /dev/loop0p1 and /dev/loop0p2)
Note: to "clean up" all the loop devices, run
losetup -D
Describe the results you received
The result is I only see
/dev/loop-control
and/dev/loop0
in the podman container. On the Host/dev/loop0p1
and/dev/loop0p2
are created, but not visible in the container.Describe the results you expected
I expect to see
/dev/loop-control
,/dev/loop0
,/dev/loop0p1
, and/dev/loop0p2
in the container.podman info output
Podman in a container
No
Privileged Or Rootless
Rootless
Upstream Latest Release
No
Additional environment details
Oracle Linux 9 is the host OS (running in an OCI VM environment) if that matters.
Additional information
No response
Beta Was this translation helpful? Give feedback.
All reactions