- Advertisement -

LXC, acronym for Linux Containers, is a lightweight Linux kernel based virtualization solution, which practically runs on top of the Operating System, allowing you to run multiple isolated distributions the same time.

The difference between LXC and KVM virtualization is that LXC doesn’t emulates hardware, but shares the same kernel namespace, similar to chroot applications.

This makes LXC a very fast virtualization solution compared to other virtualization solutions, such as KVM, XEN or VMware.

This article will guide you on how you can install, deploy and run LXC containers on a CentOS/RHEL and Fedora distributions.

Step 1: Installing LXC Virtualization in Linux

1. LXC virtualization is provided through Epel repositories. In order to use this repo, open a terminal and install Epel repositories in your system by issuing the following command:

- Advertisement -

2. Before continuing with LXC installation process, assure that Perl language interpreter, and debootstrap packages are installed by issuing the below commands.

3. Finally install LXC virtualization solution with the following command.

4. After LXC service has been installed, verify if LXC and libvirt daemon is running.

Sample Output

and check LXC kernel virtualization status by issuing the below command.

Sample Output

Step 2: Create and Manage LXC Containers in Linux

5. To list available LXC templates containers already installed on your system issue the below command.

6. The process of creating a LXC container is very simple. The command syntax to create a new container is explained below.

In the below excerpt we’ll create a new container named mydeb based on a debian template that will be pulled off from LXC repositories.

7. After a series of base dependencies and packages that will be downloaded and installed in your system the container will be created. When the process finishes a message will display your default root account password. Change this password once you start and login to the container console in order to be safe.

8. Now, you can use lxc-ls to list your containers and lxc-info to obtain information about a running/stopped container.

In order to start the newly created container in background (will run as a daemon by specifying the -d option) issue the following command:

9. After the container has been started you can list running containers using the lxc-ls --active command and get detailed information about the running container.

10. In order to login to the container console issue the lxc-console command against a running container name. Login with the user root and the password generated by default by lxc supervisor.

Once logged in the container you can run several commands in order to verify the distribution by displaying the /etc/issue.net file content, change the root password by issuing passwd command or view details about network interfaces with ifconfig.

Sample Output

11. To detach from the container console and go back to your host console, leaving the container in active state, hit Ctrl+a then q on the keyboard.

To stop the a running container issue the following command.

12. In order to create a LXC container based on an Ubuntu template, enter /usr/sbin/ directory and create the following debootstrap symlink.

13. Edit qemu-debootstrap file with Vi editor and replace the following two MIRROR lines as follows:

For reference, see the following content and place the above two lines as stated:

14. Finally create a new LXC container based on Ubuntu template issuing the same lxc-create command.

Once the process of generating the Ubuntu container finishes a message will display your container default login credentials as illustrated on the below screenshot.

Sample Output

15. In order to create a specific container based on local template use the following syntax:

Here is an excerpt of creating a debian wheezy container with an amd64 system architecture.

Sample Output

16. For instance, specific containers for different distro releases and architectures can be also created from a generic template which will be downloaded from LXC repositories as illustrated in the below example.

Here is the list of lxc-create command line switches:

17. Containers can be deleted from your host with the lxc-destroy command issued against a container name.

18. A container can be cloned from an existing container by issuing lxc-clone command:

19. And finally, all created containers reside in /var/lib/lxc/ directory. If for some reason you need to manually adjust container settings you must edit the config file from each container directory.

This are just the basic things you need to know in order to work your way around LXC.

- Advertisement -

There are no comments yet

  • Hello, guest