Getting LXC up and running in Arch is a little more work then in Ubuntu. In Ubuntu you simply:
sudo apt install lxc
Thats it, your up and running. I would how ever both in Ubuntu and Arch configure a bridge so you can interact with the containers from other devices on your LAN. You can do that by following my guide here:
In fact, this guide uses that bridge, and LXC in arch does not come with a bridge)
Installing LXC in Arch (Antergos)
Open a terminal:
sudo pacman -S lxc arch-install-scripts
After you install LXC you need to enable the lxc.service if you want your LXC’s to be able to start at boot.
sudo systemctl enable lxc
If you want to run other systems (like ubuntu) you need to install their package manager. In this guide i will use Ubuntu so you will need:
sudo pacman -S debootstrap
For more information check out the arch wiki: https://wiki.archlinux.org/index.php/Linux_Containers
We also have to make som configurations to the default config LXC puts with our containers:
sudo nano /etc/lxc/default.conf
LXC will use this file as the default template for all the LXC’s you make. We should ad some useful configurations you could make use of at a later point if you need them.
Just replace the content with:
lxc.network.type = veth lxc.network.link = br0 #This bridge is created in another blogpost! lxc.network.flags = up #start container at boot #lxc.start.auto = 1 #restrict memmory #lxc.cgroup.memory.limit_in_bytes = 53687091 #restrict CPU's #lxc.cgroup.cpuset.cpus = 0,1,2,3,4,5,6,7 #add mounts (privileged (root) containers only) #lxc.mount.entry = /home/username/source /var/lib/lxc/containername/rootfs/home/username/destination none bind 0 0
If you want all containers you create to start at boot, have restrictions on hardware, you can uncomment the options here. If not you can change each containers config after you create them by:
sudo nano /var/lib/lxc/containername/config
Make your first container
It’s very easy to make containers!
sudo lxc-create -n ubuntu -t /usr/share/lxc/templates/lxc-ubuntu
/usr/share/lxc/templates/ has a list of templates you can use. For other systems simply list the dir to see available choices.
Lets look at the status of our new container:
sudo lxc-ls -f
(The -f adds a fancy list)
NAME STATE AUTOSTART GROUPS IPV4 IPV6 ubuntu STOPPED 0 - - -
We can se our container is currently stopped, lets start it!
sudo lxc-start -n ubuntu
Now lets check status again!
sudo lxc-ls -f
We can see its startet
NAME STATE AUTOSTART GROUPS IPV4 IPV6 ubuntu RUNNING 0 - 10.168.1.2 -
To connect to our new container we use:
sudo lxc-console -n ubuntu
The default username is ubuntu and the default password is ubutnu
To exit the console: Ctrl – a , Then q
Congratulations! You have your first container to play with!
To stop container
sudo lxc-stop -n ubuntu
To destroy it:
sudo lxc-destroy -n ubuntu