How to sync the sqlite db with reality?

Hi Everyone,

I wanted to check what the process is to sync the sqlite db with reality on a server, the images got removed with zfs destroy but

lxc storage show local

Still shows the deleted images:

  • /1.0/images/6a26c611488b9018dec0f2f84a36a69e16b27a4bcd4b08ff4a2bddb67b1a5fcb (Linked to existing container)
  • /1.0/images/7519c37df49e0ff6dc896d5b93b4871d63829818b1ed1c39fd46962e4dc689e2 (NEED TO REMOVE)
  • /1.0/images/836d8633e7de834aa55ed1eb2db5aa7d39ba2790292f2b7d45b4c5bb320644f5(NEED TO REMOVE)

they are not tied to any containers so I am not sure how else they can be deleted, did:

remove snapshot

zfs destroy ZPOOL/lxc/images/836d8633e7de834aa55ed1eb2db5aa7d39ba2790292f2b7d45b4c5bb320644f5@readonly

zfs destroy ZPOOL/lxc/images/836d8633e7de834aa55ed1eb2db5aa7d39ba2790292f2b7d45b4c5bb320644f5

Same for 6a26c611488b9018dec0f2f84a36a69e16b27a4bcd4b08ff4a2bddb67b1a5fcb

zfs destroy

zfs destroy ZPOOL/lxc/images/6a26c611488b9018dec0f2f84a36a69e16b27a4bcd4b08ff4a2bddb67b1a5fcb

Also, what is the proper way to remove these images with lxd?

Thank you in advance.


lxc image delete

Hi Stéphane,

Thanks for the reply, that is the thing lxc image list did not match with what I saw, that is why I did the zfs destroy:

lxc image list

shows nothing at the moment:

lxc storage show local

config: {}
description: “”
name: local
driver: zfs

  • /1.0/containers/mcon-example
  • /1.0/images/6a26c611488b9018dec0f2f84a36a69e16b27a4bcd4b08ff4a2bddb67b1a5fcb
  • /1.0/images/7519c37df49e0ff6dc896d5b93b4871d63829818b1ed1c39fd46962e4dc689e2
  • /1.0/images/836d8633e7de834aa55ed1eb2db5aa7d39ba2790292f2b7d45b4c5bb320644f5
  • /1.0/profiles/default

mcon-example is linked to 6a26c611488b9018dec0f2f84a36a69e16b27a4bcd4b08ff4a2bddb67b1a5fcb

How do I remove the other 2? I tried “lxc storage edit local” and removed the lines but it does not remove it.

Thanks again for the help.


Did you try lxc storage volume delete local image/7519c37df49e0ff6dc896d5b93b4871d63829818b1ed1c39fd46962e4dc689e2?

You should be able to delete all of them, even if one was used to create an instance. LXD will just have ZFS keep it around but it should be gone from the database entirely.

Tried, but got:

lxc storage volume delete local image/7519c37df49e0ff6dc896d5b93b4871d63829818b1ed1c39fd46962e4dc689e2
Error: not found

Can you show lxd sql global "SELECT name FROM storage_volumes"?

There’s a bunch of entries, just grepped for the ones I want to remove:

lxd sql global “SELECT name FROM storage_volumes”|grep 7519
| 7519c37df49e0ff6dc896d5b93b4871d63829818b1ed1c39fd46962e4dc689e2 |

lxd sql global “SELECT name FROM storage_volumes”|grep 836
| 836d8633e7de834aa55ed1eb2db5aa7d39ba2790292f2b7d45b4c5bb320644f5 |

lxd sql global "DELETE FROM storage_volumes WHERE name='7519c37df49e0ff6dc896d5b93b4871d63829818b1ed1c39fd46962e4dc689e2'" should do it

Perfect, that did the trick, thanks for the help, much appreciated.

Just a quick question, the reason behind this was we troubleshot an issue where /var on the vm running the lxd containers filled up, path /var/snap/lxd/common/lxd/images

This VM is part of an lxd cluster, but the images were outside of the zpool? Where did those images
come from and it occupied 4+GB but on troubleshooting this I also reloaded the lxd daemon and then saw:

t=2021-01-28T08:23:38+1100 lvl=info msg=“Pruning expired images”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Done pruning expired images”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Pruning expired instance backups”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Done pruning expired instance backups”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Expiring log files”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Done expiring log files”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Updating images”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Updating instance types”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Done updating images”
t=2021-01-28T08:23:38+1100 lvl=info msg=“Done updating instance types”

The images got removed?

I am just trying to understand why the images were in that folder and how we can prevent them from going “local” and route to some zfs mount point or something?

LXD always stores the raw image tarballs or squashfs in /var/snap/lxd/common/lxd/images. Those are always kept around in case they need to be transferred between servers, verified or are exported by the user.

The images then get unpacked into a dataset on first use and that dataset is cloned to make the instances.

You can move that image storage onto a custom volume in your storage pool though by using the storage.images_volume config option. The same applies to instance backups which are stored as tarballs in /var/snap/lxd/common/lxd/backups which can be controlled through storage.backups_volume.

Awesome, thanks for that info, once again, much appreciated.