2008-04-23 17:08:31 +00:00
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<h1>LXC container driver</h1>
|
2009-04-15 20:00:29 +00:00
|
|
|
<p>
|
|
|
|
The libvirt LXC driver manages "Linux Containers". Containers are sets of processes
|
|
|
|
with private namespaces which can (but don't always) look like separate machines, but
|
|
|
|
do not have their own OS. Here are two example configurations. The first is a very
|
|
|
|
light-weight "application container" which does not have it's own root image. You would
|
|
|
|
start it using
|
|
|
|
</p>
|
|
|
|
|
2011-02-22 17:35:06 +00:00
|
|
|
<h2>Cgroups Requirements</h2>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
The libvirt LXC driver requires that certain cgroups controllers are
|
|
|
|
mounted on the host OS. The minimum required controllers are 'cpuacct',
|
|
|
|
'memory' and 'devices', while recommended extra controllers are
|
|
|
|
'cpu', 'freezer' and 'blkio'. The /etc/cgconfig.conf & cgconfig
|
|
|
|
init service used to mount cgroups at host boot time. To manually
|
|
|
|
mount them use:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
# mount -t cgroup cgroup /dev/cgroup -o cpuacct,memory,devices,cpu,freezer,blkio
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
NB, the blkio controller in some kernels will not allow creation of nested
|
|
|
|
sub-directories which will prevent correct operation of the libvirt LXC
|
|
|
|
driver. On such kernels, it may be neccessary to unmount the blkio controller.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
2009-04-15 20:00:29 +00:00
|
|
|
<h3>Example config version 1</h3>
|
|
|
|
<p></p>
|
|
|
|
<pre>
|
|
|
|
<domain type='lxc'>
|
2009-11-13 23:09:20 +00:00
|
|
|
<name>vm1</name>
|
|
|
|
<memory>500000</memory>
|
|
|
|
<os>
|
|
|
|
<type>exe</type>
|
|
|
|
<init>/bin/sh</init>
|
|
|
|
</os>
|
|
|
|
<vcpu>1</vcpu>
|
|
|
|
<clock offset='utc'/>
|
|
|
|
<on_poweroff>destroy</on_poweroff>
|
|
|
|
<on_reboot>restart</on_reboot>
|
|
|
|
<on_crash>destroy</on_crash>
|
|
|
|
<devices>
|
|
|
|
<emulator>/usr/libexec/libvirt_lxc</emulator>
|
|
|
|
<interface type='network'>
|
|
|
|
<source network='default'/>
|
|
|
|
</interface>
|
|
|
|
<console type='pty' />
|
|
|
|
</devices>
|
2009-04-15 20:00:29 +00:00
|
|
|
</domain>
|
|
|
|
</pre>
|
|
|
|
|
2010-06-15 22:46:21 +00:00
|
|
|
<p>
|
|
|
|
In the <emulator> element, be sure you specify the correct path
|
|
|
|
to libvirt_lxc, if it does not live in /usr/libexec on your system.
|
|
|
|
</p>
|
|
|
|
|
2009-04-15 20:00:29 +00:00
|
|
|
<p>
|
|
|
|
The next example assumes there is a private root filesystem
|
|
|
|
(perhaps hand-crafted using busybox, or installed from media,
|
|
|
|
debootstrap, whatever) under /opt/vm-1-root:
|
|
|
|
</p>
|
|
|
|
<p></p>
|
|
|
|
<pre>
|
|
|
|
<domain type='lxc'>
|
2009-11-13 23:09:20 +00:00
|
|
|
<name>vm1</name>
|
|
|
|
<memory>32768</memory>
|
|
|
|
<os>
|
|
|
|
<type>exe</type>
|
|
|
|
<init>/init</init>
|
|
|
|
</os>
|
|
|
|
<vcpu>1</vcpu>
|
|
|
|
<clock offset='utc'/>
|
|
|
|
<on_poweroff>destroy</on_poweroff>
|
|
|
|
<on_reboot>restart</on_reboot>
|
|
|
|
<on_crash>destroy</on_crash>
|
|
|
|
<devices>
|
|
|
|
<emulator>/usr/libexec/libvirt_lxc</emulator>
|
|
|
|
<filesystem type='mount'>
|
|
|
|
<source dir='/opt/vm-1-root'/>
|
|
|
|
<target dir='/'/>
|
|
|
|
</filesystem>
|
|
|
|
<interface type='network'>
|
|
|
|
<source network='default'/>
|
|
|
|
</interface>
|
|
|
|
<console type='pty' />
|
|
|
|
</devices>
|
2009-04-15 20:00:29 +00:00
|
|
|
</domain>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
In both cases, you can define and start a container using:</p>
|
|
|
|
<pre>
|
2009-04-17 15:34:53 +00:00
|
|
|
virsh --connect lxc:/// define v1.xml
|
2010-06-15 22:46:21 +00:00
|
|
|
virsh --connect lxc:/// start vm1
|
2009-04-15 20:00:29 +00:00
|
|
|
</pre>
|
|
|
|
and then get a console using:
|
|
|
|
<pre>
|
2010-06-15 22:46:21 +00:00
|
|
|
virsh --connect lxc:/// console vm1
|
2009-04-15 20:00:29 +00:00
|
|
|
</pre>
|
|
|
|
<p>Now doing 'ps -ef' will only show processes in the container, for
|
2010-06-15 22:46:21 +00:00
|
|
|
instance. You can undefine it using
|
2009-04-15 20:00:29 +00:00
|
|
|
</p>
|
2010-06-15 22:46:21 +00:00
|
|
|
<pre>
|
|
|
|
virsh --connect lxc:/// undefine vm1
|
|
|
|
</pre>
|
2008-04-23 17:08:31 +00:00
|
|
|
</body>
|
|
|
|
</html>
|