drvlxc.html.in 2.6 KB
Newer Older
1 2 3
<html>
  <body>
    <h1>LXC container driver</h1>
4 5 6 7 8 9 10 11 12 13 14 15
<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>

<h3>Example config version 1</h3>
<p></p>
<pre>
&lt;domain type='lxc'&gt;
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  &lt;name&gt;vm1&lt;/name&gt;
  &lt;memory&gt;500000&lt;/memory&gt;
  &lt;os&gt;
    &lt;type&gt;exe&lt;/type&gt;
    &lt;init&gt;/bin/sh&lt;/init&gt;
  &lt;/os&gt;
  &lt;vcpu&gt;1&lt;/vcpu&gt;
  &lt;clock offset='utc'/&gt;
  &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
  &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
  &lt;on_crash&gt;destroy&lt;/on_crash&gt;
  &lt;devices&gt;
    &lt;emulator&gt;/usr/libexec/libvirt_lxc&lt;/emulator&gt;
    &lt;interface type='network'&gt;
      &lt;source network='default'/&gt;
    &lt;/interface&gt;
    &lt;console type='pty' /&gt;
  &lt;/devices&gt;
34 35 36
&lt;/domain&gt;
</pre>

S
Serge Hallyn 已提交
37 38 39 40 41
<p>
In the &lt;emulator&gt; element, be sure you specify the correct path
to libvirt_lxc, if it does not live in /usr/libexec on your system.
</p>

42 43 44 45 46 47 48 49
<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>
&lt;domain type='lxc'&gt;
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  &lt;name&gt;vm1&lt;/name&gt;
  &lt;memory&gt;32768&lt;/memory&gt;
  &lt;os&gt;
    &lt;type&gt;exe&lt;/type&gt;
    &lt;init&gt;/init&lt;/init&gt;
  &lt;/os&gt;
  &lt;vcpu&gt;1&lt;/vcpu&gt;
  &lt;clock offset='utc'/&gt;
  &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
  &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
  &lt;on_crash&gt;destroy&lt;/on_crash&gt;
  &lt;devices&gt;
    &lt;emulator&gt;/usr/libexec/libvirt_lxc&lt;/emulator&gt;
    &lt;filesystem type='mount'&gt;
      &lt;source dir='/opt/vm-1-root'/&gt;
      &lt;target dir='/'/&gt;
    &lt;/filesystem&gt;
    &lt;interface type='network'&gt;
      &lt;source network='default'/&gt;
    &lt;/interface&gt;
    &lt;console type='pty' /&gt;
  &lt;/devices&gt;
72 73 74 75 76 77
&lt;/domain&gt;
</pre>

<p>
In both cases, you can define and start a container using:</p>
<pre>
D
Daniel Veillard 已提交
78
virsh --connect lxc:/// define v1.xml
S
Serge Hallyn 已提交
79
virsh --connect lxc:/// start vm1
80 81 82
</pre>
and then get a console  using:
<pre>
S
Serge Hallyn 已提交
83
virsh --connect lxc:/// console vm1
84 85
</pre>
<p>Now doing 'ps -ef' will only show processes in the container, for
S
Serge Hallyn 已提交
86
instance.  You can undefine it using
87
</p>
S
Serge Hallyn 已提交
88 89 90
<pre>
virsh --connect lxc:/// undefine vm1
</pre>
91 92
  </body>
</html>