I’m trying to mount partitions from a raw disk image using kpartx
. This doesn’t seem to work even when using a privileged LXD container.
$ lxc launch ubuntu:22.04 -c security.privileged=true -c security.nesting=true c1
$ lxc shell c1
# (Inside LXD container)
root@c1:~# truncate -s 100MiB image.raw
root@c1:~# echo -e "o\nn\np\n1\n\n\nw" | /sbin/fdisk image.raw
root@c1:~# kpartx -a -s -v image.raw
/dev/mapper/control: open failed: Operation not permitted
Failure to communicate with kernel device-mapper driver.
Check that device-mapper is available in the kernel.
Incompatible libdevmapper 1.02.175 (2021-01-08) and kernel driver (unknown version).
device mapper prerequisites not met
kpartx fails to mount the partitions.
However the same set of commands work within a privileged docker container as shown below.
$ docker run -it --privileged ubuntu:22.04
root@359365e759dd:/# apt update && apt install fdisk kpartx
root@359365e759dd:/# truncate -s 100MiB image.raw
root@359365e759dd:/# echo -e "o\nn\np\n1\n\n\nw" | /sbin/fdisk image.raw
root@359365e759dd:/# kpartx -a -s -v image.raw
add map loop2p1 (253:0): 0 202752 linear 7:2 2048
My question is how to configure the privileged LXD container so that it allows kpartx to run just like Docker?