Reliable script to set up and tear down a demo of lxd was hard to write?

Hi! Rank beginner here.
Trying to write a little script to reproducably do

I expected lxd to be easy to install and uninstall.
Not so!
I kept running into odd, broken situations, and areas where I needed
to know more than I expected about the underlying tools, and
had to do crazy things like add retry loops and delays
and even reboots!
Evidently lxd (not unlike other systems I’ve seen) is a bit of a leaky

After reading and
I eventually got something that was reliable-ish at just setting up and
tearing down lxd and the demo container.
It’s at
There are like four bits in there that could be considered bugs or at least
papercuts in lxd.

Am I just slow, or what?

1 Like

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 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.

I agree that a generic one would be useful, but I’m still trying to debug my special case one. I am currently using btrfs, and ran into rough edges there, too.

I kept seeing this:

$ lxc storage delete default
Error: invalid argument

/var/log/lxd/lxd.log is uninformative:

lvl=info msg=“Deleting BTRFS storage pool “default”.” t=2018-06-03T07:03:30-0700

Maybe that’s a spurious error, and the pool did get deleted?
Looping like this gets me past that:

while lxc storage list | grep default
    sudo btrfs subvolume delete /var/lib/lxd/storage-pools/default || true
    lxc storage delete default || true
    sleep 5

I guess I should file an issue for that.

Fun fact: there’s a patch out to allow rmdir to remove subvolumes:

Hi Dan…

You didn’t mention your environment, Host OS, Container OS, SNAP LXD or repository LXD (and lxd --version) etc.

Also, as I’ve not had any real problems installing/uninstalling/reinstalling could you describe some of the “odd, broken situations” you encountered (if you remember).


Oh, right: I’m using stock Ubuntu 18.04 for both host and guest, no snaps.

Here’s one of the odd problems:

See also, which now works reliably for me; if it looks too long to you, let me know what I can take out :slight_smile:

1 Like