2

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.

Amon Bune
  • 41
  • 1
  • 5

2 Answers2

3

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

Adam Ryczkowski
  • 690
  • 1
  • 9
  • 29
  • I wish there was a way to override the "correct" answer. The one which you delineated is correct and works for all situations. I moved from a ceph cluster to zfs and used this technique. The other "hack" would not have worked. – Tony Richards Feb 20 '22 at 12:52
0

I found a "hack" that resolves the issue.

The problem is that lxc storage create newstorage does create a 15GB image per default. This value cannot be changed.

One has to have access to another Linux machine with a fresh install of LXD and execute lxd init there. Select btrfs, a loop device size of the desired new capacity of the image and the image name. Now copy that new storage.img to the server.

The steps to copy the contents are:

  1. Shut down all containers
  2. Reboot machine
  3. Mount old storage.img to /mnt/oldstorage
  4. Mount new storage.img to /mnt/newstorage
  5. Execute sudo cp -rpv /mnt/oldstorage /mnt/newstorage
  6. Move old storage.img out of the /var/lib/lxd/disks/ folder
  7. Move new storage.img to /var/lib/lxd/disks/
  8. Reboot machine
  9. Start all containers

Edit: This method works fine as long as you don't delete any existing containers. LXD does create a subvolume for each container. If you want to keep the ability to delete existing containers you should create a subvolume for each container.

btrfs subvolume create [-i <qgroupid>] [<dest>/]<name>
Amon Bune
  • 41
  • 1
  • 5