How to set mode (rwx) of virtual block device mounted on container?

I have a container and wish to mount onto it a “virtual block device” i created on the host, so that it will look like I have an external drive on it.

So I do:

# on host, as root:
dd if=/dev/zero of=/opt/disk-01 bs=1M count=5000 # 5GB
mknod /dev/disk-01 b 7 200
losetup /dev/disk-01 /opt/disk-01
mkfs.xfs /dev/disk-01
chmod 666 /dev/disk-01
chmod 666 /dev/loop200
chmod 666 /opt/disk-01
incus config device add my-container disk-01 disk source=/dev/disk-01 path=/mnt/disk-01

# then, inside the container, as root:
ls -ald /mnt/disk-01
# output is: drwxr-xr-x  2 nobody nogroup  6 Jan 23 09:02 disk-01 # ie no one can write to it
chmod 777 /mnt/disk-01
# output is: chmod: changing permissions of '/mnt/disk-01/': Operation not permitted

So my problem now is that no one from the container can write to this mounted dir/device, and can’t find a way to make it writable.

How can I make /mnt/disk-01 writable by someone/anyone inside the container?

Thank you.

You can’t fix that from inside the container, that would be quite the security bug in the Linux kernel if you could.

Instead you’ll need to mount it on the host and fix the ownership there to line up with the uid of root in your container.

You can likely run ps fauxww on your host, check what uid owns the /sbin/init process for your container, then chown the root of the mount to that.