Skip to content

Getting Started with LXD on Fedora

Reto Gantenbein edited this page Nov 3, 2024 · 10 revisions

First time initialization

Add user account to lxd group. This user will then be able to create/start/stop LXD containers:

# usermod -a -G lxd <user>

Set sub{u,g}id range for mapping container users/groups to host UIDs/GIDs. For more information see man (5) subuid.

# echo "root:1000000:65536" >> /etc/subuid
# echo "root:1000000:65536" >> /etc/subgid

Enable and start lxd:

# systemctl enable lxd && systemctl start lxd

Run the daemon initialization (see How to initialize LXD for more information):

# lxd init

If the host runs firewalld the Incus bridge (defaults to incusbr0) must be added to the trusted zone otherwise the containers won't be able to communicate:

# firewall-cmd --zone=trusted --change-interface=lxdbr0 --permanent
# firewall-cmd --reload

Start your first container

Start your first container:

$ lxc launch ubuntu:22.04

Start your first virtual machine

Ensure you have the necessary packages installed. See the Installation Instructions.

First create a new profile for your virtual machine(s):

$ lxc profile create virtualmachine
$ lxc profile edit virtualmachine

Now paste the profile definition. This will store the cloud-init configuration. Import is that secure boot must be disabled because Fedora is missing the corresponding UEFI files. You can also add SSH public keys or many other cloud-init definitions:

config:
  security.secureboot: "false"
  user.user-data: |
    #cloud-config
    ssh_pwauth: yes
    users:
    - name: vagrant
      passwd: "$6$wBwgyPQYbcR2au8u$r/2VnQJGak0OSH794cO2Glcnowu6joy4XSAYMEEUnVfPRuMVbMl.a3R.qy0GldG9XxhI3jbOBDobhwZFXSvC21"
      lock_passwd: false
      shell: /bin/bash
      sudo: ALL=(ALL) NOPASSWD:ALL
description: LXD profile for virtual machines
devices:
  config:
    source: cloud-init:config
    type: disk
  eth0:
    nictype: bridged
    parent: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: virtualmachine
used_by: []

Launch the virtual machine by passing the new profile and the --vm flag:

$ lxc launch ubuntu:22.04 --vm --profile virtualmachine

Serve documentation via LXD API

It's possible to serve the LXD documentation available via lxd-doc RPM via the LXD API:

# dnf install lxd-doc

If not already done enable network access to the LXD API. E.g.:

# lxc config set core.https_address :8443
# systemctl restart lxd

Eventually the documentation is exposed via /documentation endpoint (e.g. https://localhost:8443/documentation).

Enable LXD UI

There is a project lxd-ui that provides a web UI for LXD. It is also packaged as RPM and can be installed via:

# dnf install lxd-ui

The UI is also an extension to the LXD API therefore you must ensure to enable network access to LXD (see above). Afterwards the UI is exposed via /ui endpoint (e.g. https://localhost:8443/ui). UI access must always be authenticated so you must generate a client certificate which is explained in the upstream documentation about how to access the LXD web UI.