LXD moving containers/snapshots to another drive

Solution 1:

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.

Solution 2:

LXD is based on a sqlite db so to change pool location just change the db:

install sqlite3 client if you don't have one

echo "UPDATE config SET value='new_pool_lxd' WHERE \ key='storage.zfs_pool_name';"|sqlite3 /var/lib/lxd/lxd.db

assuming your lxd db in default location

then check

echo "SELECT * FROM config;"|sqlite3 /var/lib/lxd/lxd.db

1|storage.zfs_pool_name|new_pool_lxd

hope this helps