How do I know if LXD is initialized?

Let’s say I ssh into a server and see that LXD is installed. How do I know if I have to do lxd init? For those who know LXD well that might not be a problem, but for me who never used it extensively that’s an issue.

What I’ve found is the lxd init --dump command. It’s not too documented, but it seems to output some sort of current cofiguration. (One thing that makes me doubt is the fact the configuration itself contains a config key.) Anyways, here’s what it looks like before running lxd init --auto (lxd-5.x):

config: {}
networks: []
storage_pools: []
profiles:
- config: {}
  description: Default LXD profile
  devices: {}
  name: default
projects:
- config:
    features.images: "true"
    features.networks: "true"
    features.profiles: "true"
    features.storage.volumes: "true"
  description: Default LXD project
  name: default

And after lxd init --auto:

config: {}
networks:
- config:
    ipv4.address: 10.86.71.1/24
    ipv4.nat: "true"
    ipv6.address: fd42:3aab:6664:4737::1/64
    ipv6.nat: "true"
  description: ""
  name: lxdbr0
  type: bridge
  project: default
storage_pools:
- config:
    source: /var/snap/lxd/common/lxd/storage-pools/default
  description: ""
  name: default
  driver: dir
profiles:
- config: {}
  description: Default LXD profile
  devices:
    eth0:
      name: eth0
      network: lxdbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default
projects:
- config:
    features.images: "true"
    features.networks: "true"
    features.profiles: "true"
    features.storage.volumes: "true"
  description: Default LXD project
  name: default

If you have better ideas, you’re welcome.

1 Like

The minimum required to launch an instance is for there to be a storage pool and a root disk in the default profile using that pool.

So that could be used as an indicator that lxd is initialized. But the actual configuration will differ depending on your needs.

You dont have to use lxd init at all. You can achieve the sane effect via multiple calls to the lxc command to configure lxd as you need.

So think of lxd init as just a “helper” that automates some common configurations rather than a boolean yes/no as to whether its initialized.

1 Like

I’ve managed to create what looks like a similar configuration w/o lxd init:

$ lxc storage create default dir
$ lxc profile device add default root disk pool=default path=/
$ lxc network create lxdbr0
$ lxc profile device add default eth0 nic network=lxdbr0 name=eth0

The trickiest part is to find information for the lxc profile device add command (disk, nic).

W/o some sort of initialization what you get when you try to launch a container:

$ lxc launch ubuntu:lts c
Creating c
Error: Failed instance creation: Failed creating instance record: Failed initialising instance: Invalid devices: Failed detecting root disk device: No root device could be found
2 Likes

Indeed :slight_smile:

1 Like