Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceremcem/d093287564b3729f6bfc61c5006ee0aa to your computer and use it in GitHub Desktop.
Save ceremcem/d093287564b3729f6bfc61c5006ee0aa to your computer and use it in GitHub Desktop.
Install Ubuntu containers on Archlinux using LXC

Install Debian containers on Archlinux using LXC

Install the lxc and the debootstrap packages:

# pacman -Sy lxc debootstrap 

Install an Debian container

I will install Debian Buster.

I create an LXC container named mydebian with the release buster and the architecture amd64:

# lxc-create --name=mydebian --template=download -- --dist debian --release buster --arch amd64

Setup the network

Install the libvirt package because we need the virsh program. Also, we will need ebtables and dnsmasq for the default NAT/DHCP networking. (*)

# pacman -Sy libvirt ebtables dnsmasq

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/mydebian/config to set-up the network configuration of the container:

lxc.net.0.type = veth
lxc.net.0.flags = up
lxc.net.0.name = eth0
lxc.net.0.link = virbr0

Setup the virb0 interface:

# virsh net-start default

Set-up the debian password

sudo lxc-attach -n mydebian
# passwd debian

Type ctrl-d to detach to the session.

Install openssh-server

sudo lxc-start -F -n mydebian

Connect as debian and install openssh-server as follow:

sudo apt install openssh-server

Start the Debian container

Start the Debian container as follow:

# lxc-start --name mydebian

Get the IP of the Debian container:

# lxc-ls -f mydebian -F IPV4

You can stop the Debian container as follow:

# lxc-stop --name mydebian

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 xenial container:

# lxc-stop --name mydebian

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

lxc.net.0.ipv4.address = 192.168.122.2/24

Restart the mydebian container.

Connect to the container

# ssh debian@192.168.122.2

Use the password debian to connect.

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