Device nodes and symlinks in /dev for lvm containers

When I create a new container in a LVM pool a few things have to be created in /dev. Whether this is purely done by udev I don’t know. But I noticed something strange.

For volumes created by LXD there is one block node in /dev/<vg_name> and a symlink in /dev/mapper' pointing to the one in /dev/<vg_name>`. For example

$ sudo lxc init images:ubuntu/bionic/amd64 -p pool2 test04
Creating test04
$ ls -l /dev/rapper-vg2/*test04* /dev/mapper/*test04*
brw-rw---- 1 root disk 253, 6 mei 19 14:01 /dev/mapper/rapper--vg2-containers_test04
lrwxrwxrwx 1 root root     41 mei 19 14:01 /dev/rapper-vg2/containers_test04 -> /dev/mapper/rapper--vg2-containers_test04

And in this case there is also a /dev/dm6

$ ls -l /dev/dm-6
brw-rw---- 1 root disk 253, 6 mei 19 14:01 /dev/dm-6

If you create a volume with lvcreate then you get a symlink in /dev/<vg_name> and /dev/mapper

$ sudo lvcreate --name mytest01 --yes --wipesignatures y rapper-vg2/LXDThinPool --thin --virtualsize 10G
  Logical volume "mytest01" created.
$ ls -l /dev/rapper-vg2/*test01* /dev/mapper/*test01*
lrwxrwxrwx 1 root root 7 mei 19 14:01 /dev/mapper/rapper--vg2-mytest01 -> ../dm-5
lrwxrwxrwx 1 root root 7 mei 19 14:01 /dev/rapper-vg2/mytest01 -> ../dm-5

And of course a /dev/dm-5.

So far I see that this is consistent and I don’t understand why. Is it a timing issue with udev maybe?

And on one LXD system I see that it doesn’t even create the files for snapshots in /dev. Something’s fishy.

What version of LXD and is it from snap?

The latest version of LXD doesn’t create devices in /dev until the volumes are activated by LXD, so that may explain what you are seeing.

Yes, snap. I was going to say snap 4.0.1, but to my surprise it is snap 4.1 (and another one at snap 4.0.1)

If you’re running snap then you may also need to instruct your host-side lvm tools to rescan the volumes before your tooling will see the volumes, see

Can you elaborate on that? What does this “activate” mean? The background to this question is that I want to create a snapshot and then I want to mount it to make a backup.

See setactivationskip in the LVM manpage for more info.

You can create a snapshot yourself so it will be at a known location and activated, and parse the output of lvs command so you know which volume name to take a snapshot of (taking into account the the github comment I linked to from @stgraber).