Using LVM in LXD

Hello, I have a program that I believe was written by golang, but it is a closed source program.

It requires a free block device, such as /dev/sdb

He detects an available block device and creates an available volume group through LVM with a log like this:

Log file created at: 2019/06/23 04:28:36

Running on the machine: anshan

Binary: Built with gc go1.10.3 for Linux /amd64

Log line format: [IWEF] MMDD hh:mm: ss.uuuuuuudid file:line] MSG

I0623 04:28:36. 977294 884 node. Go: 211] pull image success, run it

Onbootcheck.go :14] Check lvm2 installed

I0623 04:28:37.246027 884 onbootcheck. Go :26] Check logrotate rules

I0623 04:28:37. 261279 884 onbootcheck. Go: 42] Check file: / usr/libexec/kubernetes/kubelet - plugins/volume/exec/bonuscloud. IO ~ LVM/LVM

Onbootcheck. Go :18] Check jq installed

Go :375] avail disk /dev/ SDB found, create BonusVolGroup…

Go :55] VG BonusVolGroup remove faild: Volume group “BonusVolGroup” not found

Cannot process volume group BonusVolGroup

W0623 04:28:37.523901 884 disk.go:188] Report VG size faild: bcode not found, device should be bound first

Go :380] Create BonusVolGroup on /dev/ SDB success

Through the VGS command, output:

VG #PV #LV #SN Attr VSize VFree

BonusVolGroup 1 1 0 wz–n- <220.00g <120.00g

But in LXD, when I don’t use the LXC config device add to add block devices, my log looks like this (via cat /var/log/syslog) :

Avail disk /dev/ SDB found, create BonusVolGroup…

Ubuntu2 node[5087]: W0623 12:07:27.572492 5087 disk.go:61] PV on /dev/ SDB remove faild: Device /dev/ SDB not found

Create PV on /dev/ SDB faild: Device /dev/ SDB not found

When I add a block device to the container, I get no output, no volume groups are created through the VGS command, and only one warning:

File descriptor 6 (pipe:[540671]) leaked on VGS invocation. Parent PID 3491: bash

Whether I run lvmetad or not, it bothers me.

Please help me. Thank you

Copying the answer I left in the related Github issue:

You can’t run LVM in a container as the use of device mapper and LVM isn’t namespaced by the kernel. So you can indeed pass one block device through LXD but interactions with the kernel device mapper to create more devices and have those show up in the container won’t work.

To have something like this be possible, we’d likely need a namespaced devtmpfs combined with namespacing logic in device mapper.
So far any attempt at getting close to this done in the kernel has been shut down.

1 Like

Thank you for your reply. Will future versions do this?

Namespaces for devtmpfs

Seems very unlikely, as I said, any attempt at doing this has been shut down for a variety of reasons upstream, so either maintainers need to change their position or someone needs to come up with a different way of handling this.