Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ceremcem/d093287564b3729f6bfc61c5006ee0aa to your computer and use it in GitHub Desktop.

Select an option

Save ceremcem/d093287564b3729f6bfc61c5006ee0aa to your computer and use it in GitHub Desktop.
Install Ubuntu containers on Archlinux using LXC

Install Ubuntu containers on Archlinux using LXC

Install the lxc and the debootstrap packages:

# pacman -Sy lxc debootstrap 

Install an Ubuntu container

I will install Ubuntu 14.04 LTS. Therfore, I will use the trusty release. If you want to install Ubuntu 12.04 LTS, use the precise release.

I create an LXC container named trusty with the release trusty:

# lxc-create --name=trusty --template=ubuntu -- --dist ubuntu --release trusty --arch amd64

Setup the network

Install the libvirt package because we need the virsh program.

# pacman -Sy libvirt

Start and enable the libvirtd daemon.

# systemctl start libvirtd
# systemctl enable libvirtd

Print the virtual network configuration default provided by libvirtd.

# virsh net-dumpxml default
<network>
  <name>default</name>
  <uuid>f9f9128b-8183-4c2c-af56-23cd52100d3a</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:8d:ea:7f'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

Edit the file /var/lib/lxc/trusty/config to set-up the network configuration of the container:

lxc.network.type = veth
lxc.network.flags = up
lxc.network.name = eth0
lxc.network.link = virbr0

Setup the virb0 interface:

# virsh net-start default

Start the Ubuntu container

Start the Ubuntu container as follow:

# lxc-start --name trusty

Get the IP of the Ubuntu container:

# lxc-ls -f trusty -F IPV4

You can stop the Ubuntu container as follow:

# lxc-stop --name trusty

Set a static IP for the container

Edit the default virtual network provided by libvirtd to restrict the DHCP range from 192.168.122.2-192.168.122.254 to 192.168.122.10-192.122.254.

# virsh net-edit default

as follow:

<network>
  <name>default</name>
  <uuid>bd881c3e-406f-40bb-84ed-b09e68f210e2</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:2d:23:30'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.10' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

Restart the libvirtd daemon:

# systemctl restart libvirtd

Stop the the trusty container:

# lxc-stop --name trusty

Add the following line in the file /var/lib/lxc/trusty/config:

lxc.network.ipv4 = 192.168.122.2

Restart the trusty container.

Connect to the container

# ssh ubuntu@192.168.122.2

The password is ubuntu.

@mnhunter
Copy link
Copy Markdown

mnhunter commented Aug 22, 2025

How install older ubuntu version in lxc? In this error message - not found lxc-template

@ceremcem
Copy link
Copy Markdown
Author

ceremcem commented Aug 22, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment