Problem with "lxc storage attach" of block volume to VM

I’m sure this worked for me before (because I documented it as I went along), but it isn’t working now.

$ lxc launch images:ubuntu/18.04/cloud foo --vm
Creating foo
Starting foo

$ lxc storage volume create default foo1 --type block
Storage volume foo1 created

$ lxc storage volume attach default foo1 foo /dev/sdb
Error: Failed to add device "foo1": Custom block volumes cannot have a path defined

$ lxc storage volume attach default foo1 foo
  Attach new storage volumes to instances

  lxc storage volume attach [<remote>:]<pool> <volume> <instance> [<device name>] <path> [flags]

This is under lxd 4.11 from snap, and the “default” storage pool is of type “dir”.

$ snap list
Name    Version   Rev    Tracking       Publisher   Notes
core18  20210128  1988   latest/stable  canonical✓  base
lxd     4.11      19389  latest/stable  canonical✓  -
snapd  11036  latest/stable  canonical✓  snapd
$ sudo snap refresh
All snaps up to date.

In case it’s relevant:

$ lxc config show foo -e
architecture: x86_64
  environment.http_proxy: ""
  image.architecture: amd64
  image.description: Ubuntu bionic amd64 (20210212_07:42)
  image.os: Ubuntu
  image.release: bionic
  image.serial: "20210212_07:42"
  image.type: disk-kvm.img
  image.variant: cloud
  user.network_mode: ""
  volatile.base_image: 951a329c395256b99c6829d0e5c9f727dffd616c6059643510bc7141934fe1e2
  volatile.eth0.host_name: tapdbb9fb6f
  volatile.eth0.hwaddr: 00:16:3e:8d:a3:a7
  volatile.last_state.power: RUNNING
  volatile.uuid: 449d85ef-271d-4750-9a00-95be89e26363
    name: eth0
    nictype: bridged
    parent: lxdbr0
    type: nic
    path: /
    pool: default
    type: disk
ephemeral: false
- default
stateful: false
description: ""
$ lxc exec foo -- /bin/bash -c 'ls -l /dev/sd*'
brw-rw---- 1 root disk 8, 0 Feb 12 19:43 /dev/sda
brw-rw---- 1 root disk 8, 1 Feb 12 19:43 /dev/sda1
brw-rw---- 1 root disk 8, 2 Feb 12 19:43 /dev/sda2

What’s the correct way to attach a new block volume to a VM instance?



lxc config device add foo foo1 disk pool=default source=foo1 should do it.

It looks like with the above, the client tried to set /dev/sdb as the path property and that’s not allowed for block storage where we don’t control where it would be mounted.

lxc config device add foo foo1 disk pool=default source=foo1 should do it.

That works, thank you.

It seems odd that it worked before. This was about 2-3 weeks ago; possibly it was running an older version of lxd, which snap updated by itself? Anyway, not a problem now.

That check was added here:


It is also possible on older versions (before this PR) to attach a block volume to a VM using:

lxc storage volume attach <pool> <volume> <instance> ""

Results in an instance disk device:

    pool: <pool>
    source: <volume>
    type: disk

But this new approach is more user friendly :slight_smile:

1 Like