LXD attach volume to qemu VM

I can’t seem to figure this out. I can attach a volume to an instance and profile, but it doesn’t show up inside the VM (created with --vm).

Is attaching a disk other than the root disk and cloud-config supported?

Yes but you need the agent running in the VM for the volume to get mounted into place.

All images from the images: remote come with the agent pre-installed so should work fine. Images that ship the agent also do not need the cloud-config disk as the agent handles seeding that on its own.

For images without the agent, once you get a shell you can install the agent with:

mount -t 9p config /mnt
cd /mnt
./install.sh
reboot

At which point the agent should start on boot and will mount those volumes.

Stephane, Thanks for taking the time to reply.

I do see it’s being mounted now via the 9p protocol. Thanks!

Is there a way to expose the block device itself? Say, for example, a Ceph disk?

-Shane

Currently storage volumes can only be of type filesystem and so only attached over 9p.

You can however attach arbitrary block devices or files as block device to the VM, using a disk device with source pointing to a block device or file (no path supported in this case).

1 Like

Thanks, the only way I can add an arbitrary disk is by directly editing the instance config.
Trying to add via cli, I get an error. Is there something wrong with my command?

$ lxc config device add ceph2 disk source=/dev/zvol/tank/ceph/ceph2_disk1
 Error: Invalid devices: Device validation failed "disk": Unsupported device type

$ lxc config device add ceph2 unix-block source=/dev/zvol/tank/ceph/ceph2_disk1
Error: Invalid devices: Device validation failed "unix-block": Unsupported device type

@tomp shouldn’t that work?

@stgraber yes this should work.

I tested this morning adding an iso file as a disk using:

lxc config device add v1 mydisk disk source=mydisk.iso

I believe the issue @shaner is experiencing is because he has not specified a device name.

E.g. it should be:

lxc config device add <instance> <device name> disk source=/dev/zvol/tank/ceph/ceph2_disk1

Indeed, that was my issue. Thank you both for your time!

I look forward to being able to create/attach storage volumes as block devices to VM’s. Hopefully this is on the roadmap?

@stgraber How to add a device that is allocated from the default storage pool?

And the new block device is also published as root.

Currently you can’t create block custom volumes. It’s on our roadmap though and should be implemented in the next couple of months.

So the only thing you can do with custom volumes is have them attached as filesystems through 9p, but that’s not going to help you if you need a block device in the VM.

@stgraber Another issue of 9p:

lxc stop vm
lxc config device add vm data disk source=/srv/vm path=/data readonly=on
lxc start vm

The guest will not mount it automatically!I have to mount it manually by

mount -t 9p -o trans=virtio,version=9p2000.L lxd_data /data

How to solve it?

@like

The VM needs to have the config disk added before first boot.

Yes you need the lxd-agent running to auto mount the 9p shares.

Yes. lxd-agent has been already started automatically.

But the additional 9p mount point still need to be mounted manually.

Hi, so I tested this this morning and it does work for me (I used the images:ubuntu/focal image as that has the lxd-agent built in):

mkdir /home/user/shared
touch /home/user/shared/hello.txt 
lxc init images:ubuntu/focal v1 --vm
lxc config device add v1 data disk source=/home/user/shared path=/data readonly=on
lxc start v1
lxc exec v1 -- mount | grep data
lxd_data on /data type 9p (ro,relatime,sync,dirsync,access=client,trans=virtio)

So something is different about your setup.

Please can you advise what image you built your VM from, and whether there are any logs in journalctl from the lxd-agent.

Also can you show the output of mount inside your VM.

Thanks.