sakana

very short memo

CentOS on ubuntu

Ok, let us create a RedHat clone instance, say, cent OS on ubuntu. So as to manipulate RPM packages, you need to install curl and yum package.

$ sudo apt-get install curl yum

By default, there is no lxc template for Cent OS. You need to deploy lxc template manually. For example,

$ sudo wget -O /usr/share/lxc/templates/lxc-centos https://gist.github.com/hagix9/3514296/raw/7f6bb4e291fad1dad59a49a5c02f78642bb99a45/lxc-centos
$ sudo chmod 755 /usr/share/lxc/templates/lxc-centos

You need some adjustment in case that architecture of you machine is i686.

$ arch
i686
$ diff /usr/share/lxc/templates/lxc-centos /usr/share/lxc/templates/lxc-centos.org
170,171c170
<         #RELEASE_URL="$MIRROR_URL/Packages/centos-release-$release-$releaseminor.el6.centos.10.$arch.rpm"
<         RELEASE_URL="$MIRROR_URL/Packages/centos-release-$release-$releaseminor.el6.centos.10.i686.rpm"
---
>         RELEASE_URL="$MIRROR_URL/Packages/centos-release-$release-$releaseminor.el6.centos.10.$arch.rpm"

Ok, now you are ready to start instance creation.

$ sudo lxc-create -t centos -n centos01

Please be noted that first time execution may take time, as this will download substantial amount of PRM packages.

After successful creation of instance, you can launch it and login via ssh. By the way, default root password is password.

$ sudo lxc-start -n centos01 -d
$ ssh -l root `cut -d " " -f3 /var/lib/misc/dnsmasq.lxcbr0.leases`

lxc continued

Let us create virtual machine of your choice. Suppose that you would like to create an instance of ubuntu. (Please do not ask me reason why I need to run ubuntu on unbutu :-)).

$ sudo lxc-create -t ubuntu -n ubuntu01

As this command execution will download files, therefore first time execution may take time. So please wait for a while, say, by drinking coffee.

After successful execution, you will have an ubuntu instance named “ubuntu01”.

Ok, let us start lxc as daemon.

$ sudo lxc-start -n ubuntu01 -d

According to dhcp server (dnsmasq), 10.0.3.198 may have been leased.

$ cat /var/lib/misc/dnsmasq.lxcbr0.leases
1379835957 00:16:3e:08:50:7f 10.0.3.198 ubuntu01 *

Let us login via ssh. Default uid/password combination is ubuntu/ubuntu.

$ ssh -l ubuntu 10.0.3.198

Ok, network plan would be like this.

None

lxc introduction

You may be tempted (or may be not) to create lightweight virtual machine on you host. lxc (LinuX Container) must be one of your options.

Installing lxc package will install all dependent packages.

$ sudo apt-get install lxc

virtual machine is manipulated by lxc- commands.

$ lxc-<TAB><TAB>
lxc-aa-custom-profile  lxc-clone              lxc-execute            lxc-list               lxc-restart            lxc-unfreeze
lxc-attach             lxc-console            lxc-freeze             lxc-ls                 lxc-shutdown           lxc-unshare
lxc-cgroup             lxc-create             lxc-halt               lxc-monitor            lxc-start              lxc-version
lxc-checkconfig        lxc-destroy            lxc-info               lxc-netstat            lxc-start-ephemeral    lxc-wait
lxc-checkpoint         lxc-device             lxc-kill               lxc-ps                 lxc-stop

You will see lxc related configuration files under /etc/init directory.

$ ls /etc/init/lxc*
/etc/init/lxc-instance.conf  /etc/init/lxc-net.conf  /etc/init/lxc.conf

You will notice that new virtual interface is added and activated.

$ ifconfig lxcbr0
lxcbr0    Link encap:Ethernet  HWaddr a6:1a:10:32:67:87
          inet addr:10.0.3.1  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::a41a:10ff:fe32:6787/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:13896 (13.8 KB)

And you will see that DHCP server is already running as well.

dnsmasq -u lxc-dnsmasq --strict-order --bind-interfaces --pid-file=/var/run/lxc/dnsmasq.pid --conf-file= --listen-address 10.0.3.1 --dhcp-range 10.0.3.2,10.0.3.254 --dhcp-lease-max=253 --dhcp-no-override --except-interface=lo --interface=lxcbr0 --dhcp-leasefile=/var/lib/misc/dnsmasq.lxcbr0.leases --dhcp-authoritative