# LXD Containers Step by Step

**URL:** https://discussion.scottibyte.com/t/lxd-containers-step-by-step/242
**Category:** Uncategorized
**Created:** [June 28, 2023, 2:59pm UTC](https://discussion.scottibyte.com/t/lxd-containers-step-by-step/242 "2023-06-28T14:59:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scott](https://discussion.scottibyte.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://discussion.scottibyte.com/u/scott)
#### Post date: [June 28, 2023, 2:59pm UTC](https://discussion.scottibyte.com/t/lxd-containers-step-by-step/242/1 "2023-06-28T14:59:52Z")

</div>

I have had requests for an updated version of my “LXD Containers 101” video. This is it. The assumption is you are starting with Ubuntu 22.04LTS server running on a dedicated hardware with preferably 16GB or more memory.

During your installation of [Ubuntu 22.04 Server](https://ubuntu.com/download/server), be sure to expand your root file system to use the entire disk as shown in the video.

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/b0354a13c1f463500d1aa82b7868ba93b341ad85.png)

Set the Size of your root (/) volume to whatever the indicated max size is.

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/0138d8c68681a477a3bac2828e4bd98b64d97b72.png)

Log into your server via ssh after installation is complete.

```auto
ssh 192.168.1.x

```

We are going to create a software bridge which is sometimes referred to as a virtual switch. Move over to the Netplan folder.

```auto
cd /etc/netplan

```

You can safely delete all of the files in this folder or rename them to \*.sav if you like.

Create a yaml file to create the bridge as discussed in the video.

```auto
sudo nano 00-installer-config.yaml

```

Put the following template in the editor session.

```auto
network:
  version: 2

  ethernets:
    enp5s0:
      dhcp4: false
      dhcp6: false

  bridges:
    bridge0:
      interfaces: [enp5s0]
      addresses: [172.16.1.247/16]
      routes:
         - to: default
           via: 172.16.0.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 1.0.0.1
      parameters:
        stp: true
        forward-delay: 4
      dhcp4: no

```

In the above file, change enp5s0 to be the name of your Ethernet device (ip a) in the two locations shown. Change the 172.16.1.247 address to be your current address and subnet mask (ip a).

_ **BIG GLARING NOTE: Some Linux systems use device eno1 which stands for Embedded Network Onboard. The “o” is a letter and not a Zero “0”. So, the device is “eno1” and not “en01”.** _

Another Note: your subnet mask will probably be /24 instead of my /16.

Change the via: 172.16.0.1 to be the address of your router and select any name servers that you want to use.

Save the file with CTRL O and Enter and CTRL X to exit the editor.

Apply the new network configuration:

```auto
sudo netplan apply

```

If all worked well, your physical Ethernet adapter (enp5s0 in my example) should no longer have an IP address and you should have a bridge0 device that has your IP address.

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/960006ea3b38783558bc459b547d726ac58de8f2.jpeg)

Move back to your home folder.

```auto
cd

```

Install LXD.

```auto
sudo snap install lxd 

```

Configure LXD as shown in the video.

```auto
sudo lxd init

```

 ![image](https://discussion.scottibyte.com/uploads/default/original/1X/bcd49a9c8081ddfba06a467143afe8482d9a4fb9.jpeg)

In the above screenshot, I set my LXD default pool storage size to be 350GB. My recommendation is to set this to be 70% of your root file system size. My root file system was 500GB in size.

Now that LXD is configured, we need to create a LXD Profile to use the bridge0 device to offer containers on your main LAN.

```auto
lxc profile create bridgeprofile
lxc profile device add bridgeprofile eth0 nic nictype=bridged parent=bridge0

```

You can now create a container using the above profile and you should see if get created with an address on your LAN.

```auto
lxc launch ubuntu:22.04 test --profile default --profile bridgeprofile -c boot.autostart=true

```

List your LXD Container(s):

```auto
lxc list

```

To enter your container for the first time in order to add a user account and/or configure it:

```auto
lxc shell test

```

When you are done configuring the container “exit” will log out of it and return to your Ubuntu Server (LXD host).

If you have a VLAN, you can create a profile for your VLAN. In my case, I created a LXD Profile for my IoT VLAN, which is vlan 30 on my network.

```auto
lxc profile create IoT
lxc profile device add IoT eth0 nic nictype=macvlan parent=bridge0 vlan=30

```

To create a container on my IoT VLAN:

```auto
lxc launch ubuntu:22.04 test-iot-vlan --profile default --profile IoT -c boot.autostart=true

```

Pro Tip: To update your LXD Server to the latest version:

```auto
sudo snap refresh lxd --channel=latest/stable

```
