lost and found ( for me ? )

Ubuntu 13.10: manage LXC containers with libvirt

Here is how to manage LXC with libvirt.

reference

install LXC and create a container.
# tail -1 /etc/lsb-release;uname -ri
DISTRIB_DESCRIPTION="Ubuntu 13.10"
3.11.0-17-generic x86_64

# apt-get install lxc lxc-templates

# lxc-create -t ubuntu -n ubuntu1310-cn1 -- -r saucy

##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##



The container “ubuntu1310-cn1” has been installed under /var/lib/lxc directory.
# ls /var/lib/lxc/ubuntu1310-cn1/rootfs/
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr



download a template file.
# wget https://gist.githubusercontent.com/lowescott/7647800/raw/76ca9a923773b577f6d8ed0cd5171f675b61eef6/lxc-template

edit the file to suite my environment.
# sed 's/REPLACE/ubuntu1310-cn1/g' lxc-template > ubuntu1310-cn1.xml

# cat ubuntu1310-cn1.xml
<domain type='lxc'>
 <name>ubuntu1310-cn1</name>
 <memory>327680</memory>
 <os>
   <type>exe</type>
   <init>/sbin/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/lib/libvirt/libvirt_lxc</emulator>
   <filesystem type='mount'>
     <source dir='/var/lib/lxc/ubuntu1310-cn1/rootfs'/>
     <target dir='/'/>
   </filesystem>
   <interface type='network'>
     <source network='default'/>
   </interface>
   <console type='pty'/>
 </devices>

I am using openvswitch, so edit the file  to use openvswitch.

Here is how to install openvswitch.

# cat ubuntu1310-cn1.xml
<domain type='lxc'>
 <name>ubuntu1310-cn1</name>
 <memory>327680</memory>
 <os>
   <type>exe</type>
   <init>/sbin/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/lib/libvirt/libvirt_lxc</emulator>
   <filesystem type='mount'>
     <source dir='/var/lib/lxc/ubuntu1310-cn1/rootfs'/>
     <target dir='/'/>
   </filesystem>
   <interface type='bridge'>
     <source bridge='br0'/>
     <virtualport type='openvswitch'/>
   </interface>
   <console type='pty'/>
 </devices>
</domain>

deploy the container with libvirt.
# virsh -c lxc:// define ubuntu1310-cn1.xml
ドメイン ubuntu1310-cn1 が ubuntu1310-cn1.xml から定義されました

# virsh -c lxc:// list --all
Id    名前                         状態
----------------------------------------------------
-     ubuntu1310-cn1                 シャットオフ



start
# virsh -c lxc:// start ubuntu1310-cn1
ドメイン ubuntu1310-cn1 が起動されました

access to the container via virsh console

# virsh -c lxc:// console ubuntu1310-cn1



Ubuntu 13.10 ubuntu1310-cn1 tty1

ubuntu1310-cn1 login:

# ping www.google.com -c 1
PING www.google.com (74.125.235.178) 56(84) bytes of data.
64 bytes from nrt19s12-in-f18.1e100.net (74.125.235.178): icmp_seq=1 ttl=53 time=10.4 ms

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 10.427/10.427/10.427/0.000 ms

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.