Linux – Move LXD container to other storage

btrfscontainerslinuxlxdstorage

I have an issue with my current storage.img file (btrfs). I had 2TB data inside a container and so the storage.img got 2TB large. After this I deleted everything, leaving me with 100GB of real data. The problem is now, that the storage.img did not shrink itself to 100GB. It is still 2TB big.

I have created another storage newstorage.img (btrfs) in LXD with the command lxc storage create newstorage but I don't know how to transfer the containers to the new storage the right way so I can delete the old storage.img and reclaim my HDD space.

I tried things like manually mounting the two imgs and doing cp -R /one/* /new/ but then I cannot start the containers.

Best Answer

No tricks needed:

lxc stop container_name
lxc move container_name temp_container_name -s new_storage_pool
lxc move temp_container_name container_name
lxc start container_name

Credits: https://discuss.linuxcontainers.org/t/how-to-move-containers-to-a-new-storage-pool-on-the-same-host/2798