Skip to content

Setup LXD based on a feature pull request

mas-who edited this page Mar 5, 2024 · 4 revisions

This guide details the steps for setting up a LXD build based on a pull request that is not yet released.

  1. Make sure you have lxd snap installed, if not, refer to HACKING.md for instructions.

  2. Create and launch a VM instance with ubuntu:22.04, name it lxd-dev or something suitable. The VM will be used as a development environment for lxd where the project binaries are compiled. Doing it this way ensures that dependencies are the same as those used in the published snaps.

  3. Once the VM is running, navigate to its terminal:

    1. update and upgrade apt with:
    apt update
    apt -y upgrade
    
    1. install package dependencies for lxd
    apt -y install acl attr autoconf automake dnsmasq-base git libacl1-dev libcap-dev liblxc1 liblxc-dev libsqlite3-dev libtool libudev-dev liblz4-dev libuv1-dev make pkg-config rsync squashfs-tools tar tcl xz-utils ebtables
    apt -y install lvm2 thin-provisioning-tools
    apt -y install btrfs-progs
    apt -y install curl gettext jq sqlite3 socat bind9-dnsutils
    apt -y install shellcheck
    
    1. install go
    apt -y install snapd
    snap install go --classic
    
    1. clone the source code
    git clone https://github.com/canonical/lxd
    cd lxd
    
    1. check out a specific pull request from the lxd repo. You will need the pull request id and replace pull_id in the command below
    git fetch origin pull/[pull_id]/head:[branch_name] && git switch [branch_name]
    
    1. build lxd dependencies, make sure you are inside the /lxd directory
    make deps
    
    1. at the end of step 3.6, there will be some instructions displayed in the shell output for setting up environment variables. Copy those and run them to set them up, an example is shown below (to persist the environment variables you should and them to .bashrc inside of the VM):
    export CGO_CFLAGS="-I/root/go/deps/raft/include/ -I/root/go/deps/dqlite/include/"
    export CGO_LDFLAGS="-L/root/go/deps/raft/.libs -L/root/go/deps/dqlite/.libs/"
    export LD_LIBRARY_PATH="/root/go/deps/raft/.libs/:/root/go/deps/dqlite/.libs/"
    export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
    
    1. We can now build the lxd and lxc binaries
    make
    
    1. Once the binaries have been compiled, add the below line items to .bashrc. Then run source ~/.bashrc.
    export GOPATH="$(go env GOPATH)"
    alias lxc="$GOPATH/bin/lxc"
    alias lxd="$GOPATH/bin/lxd -v -d"
    
    1. Finally now you can run the command lxd in the terminal and the lxd server will start running.

    2. In case if there are upstream changes from the lxd pull request, you can updated the local git branch that's tracking the pull request and execute steps v. - x. again.

  4. Connect the UI to the lxd server running inside of the VM instance. To do this, note down the IP address for the VM instance and add it to .env.local in your lxd-ui project. The IP address should be set against the LXD_UI_BACKEND_IP environment variable as shown below in the example.

LXD_UI_BACKEND_IP=10.147.196.7
  1. Run dotrun from the root level of your lxd-ui project and now the UI will be conected to the lxd server that contains features that do not exist in the official snap release.