How exactly does the command lxd import work?

Hi,

this is about this base problem users of LXD encounter again and again with different storages when they try to start their containers, maybe just “out of nothing” or after a migration or update of lxd:

ERROR    dir - storage/dir.c:dir_mount:198 - No such file or directory - Failed to mount "/var/snap/lxd/common/lxd/containers/XXX/rootfs" on "/var/snap/lxd/common/lxc/"
    lxc lxc1101-1304 20191206172015.198 ERROR    conf - conf.c:lxc_mount_rootfs:1353 - Failed to mount rootfs "/var/snap/lxd/common/lxd/containers/XXX/rootfs" onto "/var/snap/lxd/common/lxc/" with options "(null)"

The way to solve it:

  1. save the whole directory of the container ( […]/containers/$container ) somewhere
  2. delete $container
  3. putback your backup of the whole directory into ( […]/containers/$container )
  4. run lxd import $container

And your container will start working again.

Since i would prefere to find the real cause of these problems ( and not start to think about how to automate this workaround ), my question would be:

What exactly does lxd import do ? And any idea why it solves this kind of problems without doing absolute anything to the container files ( that could fix permission errors based in the container files ).

Thank you !