1

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.

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.