How to Multi Boot Distros using Linux Containers
Linux Containers (LXC) are a lightweight virtualization technology and they have various uses. It is office of the Linux kernel, and tin let you emulate one, or multiple Linux distros on a single Linux host. Think of information technology equally a centre ground between a chroot and full virtualization technologies such as VirtualBox, KVM or Xen. A similar applied science present in the BSD world are FreeBSD Jails.
As an example, the automobile I am writing on is a laptop running Linux Mint 18, powered by an Intel Atom processor, and has a meager 2 GB of RAM. Nevertheless, I am running three Linux containers, each with an example of the Apache web server running, without a big functioning hit. This would exist unthinkable with a traditional virtual machine similar VirtualBox. And so, if you take been wanting to run multiple distros on your Linux organisation, Linux Containers should practice the task for you merely fine.
Installing and Configuring Linux Containers
We are setting upwardly LXC on Linux Mint 18 64-scrap. The installation instructions provided here volition also work unmodified on Ubuntu 16.04 and in a higher place. If y'all are using another distro, please refer to your distro'due south official documentation if something does not work as expected. A familiarity with the control line and general troubleshooting is also assumed.
Prerequisites
Hither are a few things you should set up to commencement using multiple distros:
1. Install LXC and other prerequisite software using:
[sourcecode]sudo apt install lxc lxc-templates uidmap[/sourcecode]
two. At present you need to configure your profile. Enter the post-obit commands to set it upward:
[sourcecode]mkdir -p ~/.config/lxc
echo "lxc.id_map = u 0 100000 65536" > ~/.config/lxc/default.conf
echo "lxc.id_map = grand 0 100000 65536" >> ~/.config/lxc/default.conf
echo "lxc.network.blazon = veth" >> ~/.config/lxc/default.conf
echo "lxc.network.link = lxcbr0" >> ~/.config/lxc/default.conf
echo "$USER veth lxcbr0 two" | sudo tee -a /etc/lxc/lxc-usernet[/sourcecode]
three. And so, you demand to prepare the user permissions as follows:
[sourcecode]sudo usermod –add-subuids 100000-165536 $USER
sudo usermod –add-subgids 100000-165536 $USER
sudo cgm create all user
sudo cgm chown all user $(id -u) $(id -g)
cgm movepid all user $$[/sourcecode]
Setting Up Your Container
Now that you have LXC Container installed forth with other prerequisite software, here are the steps to ready upwardly the Container:
1. In this instance, we will set up an Ubuntu container, named <code>ubu1</code>. To exercise information technology, execute the post-obit command:
[sourcecode]lxc-create –template download –proper noun ubu1[/sourcecode]
2. Hither, the <code>–template</lawmaking> parameter tells lxc to download a preconfigured epitome from the cyberspace, while the <code>–proper noun</lawmaking> parameter specifies the proper noun of the container – <code>ubu1</lawmaking> in this example. You can utilize whichever name you similar.
3. You will now see a list of supported distro images:
4. Enter the specifics of the distribution that y'all wish to install. I will install the 64-bit version of Ubuntu sixteen.04 (codename xenial) hither:
5. If you wish to install the image non-interactively, the following command achieves the same result as the in a higher place:
[sourcecode]lxc-create -t download -n ubu1 — –dist ubuntu –release xenial –arch amd64[/sourcecode]
6. LXC volition now download and install a minimal Ubuntu xenial image on your host system. The download and installation might accept a bit of time depending on your internet connection and your PC's speed. After the installation, y'all will meet a screen similar this:
Y'all are now ready to use your newly set up Ubuntu container.
Using Multiple Distros with Linux Containers
Starting Up The Container
Start your container using the <code>lxc-start</code> control:
[sourcecode]lxc-starting time -n ubu1 -d[/sourcecode]
Here, the <lawmaking>-n</code> parameter specifies the name of the container that you wish to commencement (<code>ubu1</lawmaking> in this example), and the <code>-d</lawmaking> parameter makes it run in the background.
You can verify that the container started by using the <code>lxc-ls</lawmaking> command:
[sourcecode]lxc-ls -f[/sourcecode]
The <code>-f</code> parameter enables fancy reporting. Here, you can see that I have two containers – 1 Debian (stopped) and i Ubuntu (running).
Accessing and Using Your Container
You can admission the container's console using the <code>lxc-attach</code> control:
[sourcecode]lxc-adhere -due north ubu1[/sourcecode]
Y'all will now have a root shell on your container. It is recommended that y'all prepare a password for the root user, and create a regular user account:
[sourcecode]passwd
adduser beebom[/sourcecode]
Of course, supersede beebom with the username you want. You can so install software and configure your container like you lot would do on a regular system. For example, in a Debian or Ubuntu container:
[sourcecode]apt install wget openssh-server htop tmux nano iptables[/sourcecode]
Stopping Your Container
After you lot are washed playing with the container, either employ the <lawmaking>go out</code> command to return to the host system. At present employ the <code>lxc-end</code> command to cease your container:
[sourcecode]lxc-stop -north ubu1[/sourcecode]
This will make the container close downwardly cleanly and it will non consume any more resources on your organization, except for disk infinite.
Cloning and Snapshots
Clones
Once you accept installed programs in a container and configured information technology to your liking, y'all might desire to create ane or multiple copies of it for piece of cake provisioning. You can practise this by creating a clone, which is an exact replica of a container.
For instance, to create a clone of the <code>ubu1</code> container (permit'due south call information technology <lawmaking>ubu2</code>), first stop the container using <lawmaking>lxc-end</code>, then use the <lawmaking>lxc-re-create</code> command:
[sourcecode]lxc-stop -n ubu1
lxc-copy -northward ubu1 -N ubu2[/sourcecode]
Here, the -due north option specifies the source container, and the -N option specifies the name of the clone. To verify that the container was cloned, use the <lawmaking>lxc-ls</lawmaking> command:
Snapshots
Suppose you are about to make some potentially dangerous or hard to recover from changes to a container, such equally re-configuring a web server. To minimise the damage, you can create a snapshot of the container earlier making such a modify. In instance something goes incorrect during the configuration, you can but cease the container and recover information technology to its previous working land by restoring a snapshot.
To create the snapshot, commencement stop the container:
[sourcecode]lxc-cease -n ubu1[/sourcecode]
Then, create a snapshot using the <code>lxc-snapshot</code> command:
[sourcecode]lxc-snapshot -n ubu1[/sourcecode]
This creates a snapshot called <lawmaking>snap0</code>. Whatever subsequent snapshots you create using this control will be chosen snap1, snap2, etc.
Afterward this, you tin can starting time the container, and brand the changes you desire. If at any time you lot desire to return to a snapshot you created, stop the container , and use the <code>lxc-snapshot</code> command with the <code>-r</code> parameter to restore a snapshot:
[sourcecode]lxc-snapshot -r snap0 -north ubu1[/sourcecode]
This will restore the snapshot <code>snap0</code> to the <code>ubu1</code> container.
Auto-starting time Containers at Boot
You can make a container, for example, a web server container, start up automatically when you kicking up your system. To do this, get to the container's config file, located in <code>$Habitation/.local/share/lxc/<NAME OF CONTAINER>/config</code>, and add together the following lines:
[sourcecode]lxc.start.auto = 1
lxc.first.delay = 5[/sourcecode]
The outset line specifies that the container should be started at boot. The second tells the organisation to wait 5 seconds before starting the next container, if any.
Troubleshooting
If you are having trouble starting containers, the outset thing to try is to run the <lawmaking>lxc-start</code> command in Foreground way. For instance:
[sourcecode]lxc-showtime -northward ubu1 -F[/sourcecode]
This will testify yous the errors on the current consoldue east, which is very useful in identifying the nature of the problem.
Problems With Running Multiple Containers Simultaneously
If yous try to run multiple containers at once, yous might see errors such as "Quota reached", or "failed to create the configured network". This is because you are running more than network interfaces than allotted to y'all. You can increase the number of network bridges a user tin can run by modifying the <code>/etc/lxc/lxc-usernet</code> file equally root. It might look something similar this:
[sourcecode]# USERNAME Type BRIDGE COUNT
beebom veth lxcbr0 v[/sourcecode]
You tin can change the number at the end (5 in this example), to a bigger number such as x. This will let you to sew to 10 containers at once.
Other Uses of Linux Containers
Linux containers have various uses. You can use them as lightweight test boxes, for example, to test out various configurations of a web or database server earlier committing them to a product server. Another use case is to test how an application runs on different versions of various distros.
You tin can besides apply them to isolate applications that you practice not trust – any damage such an application does will be limited to its own container, and volition not affect the host arrangement. Delight annotation that while it is possible to run GUI applications in a container, information technology takes a significant amount of fourth dimension and effort, and is thus not recommended. If you lot wish to run GUI apps in a sandbox, refer to our article on how to sandbox apps in Linux.
SEE ALSO: seven Best VirtualBox Alternatives You Tin can Use
Run Multiple Distros Simultaneously With Linux Containers
Thus ends our How-To on running multiple Linux distros on a unmarried computer, without the overhead of a full-sized virtual motorcar. The utility of this engineering is simply limited by your creativity, so feel free to experiment and find out novel utilise cases. If you accept trouble setting up containers, feel complimentary to inquire us a question in the comments section.
Source: https://beebom.com/how-run-multiple-distros-using-linux-containers/
Posted by: williamsoftere.blogspot.com
0 Response to "How to Multi Boot Distros using Linux Containers"
Post a Comment