Ubuntu – LXD moving containers/snapshots to another drive

lxclxd

The default path for LXD is /var/lib/lxd, so containers are in
/var/lib/lxd/containers and snapshots are placed in /var/lib/lxd/snapshots.

The /var/ partition is getting full, so I'm planning to use another partition for containers and snapshots which has much more space.

My current options are:

  • Create a symlink to the new directory (in the other drive)
  • Bind (mount) the new directory into the current one
  • Change some lxd setting (if exists) which points to a directory in the other drive

Not sure which method is easier and if there are any other ways to achieve this easily.

I'm worried about having problems with apparmor, the container's permissions or causing issues in lxd/lxc.

Which would be the correct (or best) way to move them?

(April 2017) UPDATE ******************

LXD 2.9+ supports multiple storage pools.

Best Answer

  • The big problem with LXD is that (currently) it only seems to support just one storage pool. In particular, this becomes somewhat of an issue if you would like to run part of your containers in one disk volume and part in another. Say, have some "fast" containers in an SSD volume and some "slow" containers in an HDD volume.

    Should you wish to only run your containers in a single volume, the solution is simple as hell:

    • stop your containers
    • stop LXD (service lxd stop)
    • move your whole /var/lib/lxd directory to your new storage pool
    • create a symlink to your new storage pool
    • start LXD (service lxd start)
    • you're done

    For instance, if you have your new storage mounted under /mnt/largepool in a subdirectory named lxd, then create the link like this: ln -s /mnt/largepool/lxd /var/lib/lxd

    This way, you will have your containers on your new storage volume.

    Please beware that if you are using BTRFS or ZFS as storage backends, you might wish to create the necessary subvolumes on your new storage first, so your containers happen to be located in their own subvolumes. For instance, if you have btrfs and have containers named c1 and c2 and have the directory /mnt/largepool/lxd/containers already in place, before the actual moving of files, create subvolumes: btrfs su create /mnt/largepool/lxd/containers/c1 btrfs su create /mnt/largepool/lxd/containers/c2

    This would make it easy to create container snapshots afterwards.

    I hope this information was helpful.

  • Related Question