Thanks for going into this!
My immediate suggestion would be to separate the part that does the set up of LXD and the tear-down.
It is a more generic task that of configuring LXD, so such a script would be useful elsewhere as well.
In addition, you can use a preseed
file when you set up LXD and also a profile
for the guiapps containers.
See https://blog.simos.info/a-closer-look-at-chrome-os-using-lxd-to-run-linux-gui-apps-project-crostini/ and specifically the link with the preseed
content that they use for the Chromebooks.
In addition, when you set up ZFS or BTRFS for the storage backend (instead of dir
) you get much faster container management. That would make it easy when you want to extend with some GUI program like VirtualBox clone.