lost and found ( for me ? )

Ubuntu 12.04 64bit desktop : how to install/use Linux Container ( LXC ) part 1

I’m newbie to lxc.
Here’s an explanation of how to install lxc , make containers.

host server info , which is running within KVM.

# uname –ri
3.2.0-34-generic x86_64

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:        12.04
Codename:       precise


[ install lxc ]

install lxc package via apt-get
# apt-get install lxc –y

# lxc-version
lxc version: 0.7.5


check what kind of kernel namespace your kernel on the host supports.
root@ubuntu1204:~# lxc-checkconfig
Kernel config /proc/config.gz not found, looking in other places...
Found kernel config file /boot/config-3.2.0-34-generic
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled

--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled


sample template files for containers.
# ls /usr/lib/lxc/templates/
lxc-busybox  lxc-fedora    lxc-sshd    lxc-ubuntu-cloud
lxc-debian   lxc-opensuse  lxc-ubuntu


sample configuration files for network configuration.
# ls /usr/share/doc/lxc/examples/
lxc-complex.conf      lxc-macvlan.conf   lxc-phys.conf  lxc-vlan.conf
lxc-empty-netns.conf  lxc-no-netns.conf  lxc-veth.conf

network configuration file.
# cat /etc/lxc/lxc.conf
lxc.network.type=veth
lxc.network.link=lxcbr0
lxc.network.flags=up

# brctl show
bridge name     bridge id               STP enabled     interfaces
lxcbr0          8000.000000000000       no

build ubuntu 12.10 ( quantal ) container using lxc-ubuntu template
# lxc-create -t ubuntu -n quantal-01 -- -r quantal

No config file specified, using the default config
debootstrap is /usr/sbin/debootstrap
<snip>
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##

'ubuntu' template installed
'quantal-01' created
root@ubuntu1204:~#

containers are installed under /var/lib/lxc/ by default.
# ls /var/lib/lxc/quantal-01/*
/var/lib/lxc/quantal-01/config  /var/lib/lxc/quantal-01/rootfs.hold
/var/lib/lxc/quantal-01/fstab

/var/lib/lxc/quantal-01/rootfs:
bin   dev  home  lib64  mnt  proc  run   selinux  sys  usr
boot  etc  lib   media  opt  root  sbin  srv      tmp  var

list containers
# lxc-list –all
RUNNING

FROZEN

STOPPED
 quantal-01

get info about quantal-01 container.
# lxc-info -n quantal-01
state:   STOPPED
lxc-info: 'quantal-01' is not running
pid:        -1

start the container.
root : ubuntu , credentials : ubuntu
# lxc-start -n quantal-01
process 10: arguments to dbus_server_disconnect() were incorrect, assertion "old_refcount > 0" failed in file ../../dbus/dbus-server.c line 786.
This is normally a bug in some application using the D-Bus library.
process 10: arguments to dbus_server_unref() were incorrect, assertion "old_refcount > 0" failed in file ../../dbus/dbus-server.c line 749.
This is normally a bug in some application using the D-Bus library.

Ubuntu 12.10 quantal-01 console

quantal-01 login: ubuntu
Password:
Welcome to Ubuntu 12.10 (GNU/Linux 3.2.0-34-generic x86_64)

* Documentation:  https://help.ubuntu.com/

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

ubuntu@quantal-01:~$

root@quantal-01:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.10
Release:        12.10
Codename:       quantal

root@quantal-01:~# uname -ri
3.2.0-34-generic x86_64

on the host
# lxc-ps --name quantal-01
CONTAINER    PID TTY          TIME CMD
quantal-01 18227 ?        00:00:00 init
quantal-01 18359 ?        00:00:00 upstart-udev-br
quantal-01 18383 ?        00:00:00 udevd
quantal-01 18391 ?        00:00:00 rsyslogd
quantal-01 18393 ?        00:00:00 upstart-socket-
quantal-01 18431 ?        00:00:00 dhclient
quantal-01 18453 ?        00:00:00 sshd
quantal-01 18487 pts/5    00:00:00 getty
quantal-01 18490 pts/3    00:00:00 getty
quantal-01 18492 pts/4    00:00:00 getty
quantal-01 18499 ?        00:00:00 cron
quantal-01 18517 pts/7    00:00:00 login
quantal-01 18521 pts/2    00:00:00 getty
quantal-01 18537 pts/7    00:00:00 bash
quantal-01 18552 pts/7    00:00:00 sudo
quantal-01 18553 pts/7    00:00:00 su
quantal-01 18554 pts/7    00:00:00 bash

on the host
# lxc-info
lxc-info: missing container name, use --name option
root@ubuntu1204:~# lxc-info --name quantal-01
state:   RUNNING
pid:     18227

connect to the container via lxc-console
root@ubuntu1204:~# lxc-console --name quantal-01

Type <Ctrl+a q> to exit the console


Ubuntu 12.10 quantal-01 tty1

quantal-01 login: ubuntu
Password:
Last login: Tue Dec  4 07:13:06 UTC 2012 on lxc/console
Welcome to Ubuntu 12.10 (GNU/Linux 3.2.0-34-generic x86_64)

* Documentation:  https://help.ubuntu.com/
ubuntu@quantal-01:~$  <- Crtl a + q to quit console
root@ubuntu1204:~#

shutdown the container from the host


on the host
root@ubuntu1204:~# lxc-shutdown --name quantal-01

make a clone container from the quantal-01 container.


on the host
root@ubuntu1204:~# lxc-clone -o quantal-01 -n quantal-02
Tweaking configuration
Copying rootfs...
Updating rootfs...
'quantal-02' created

root@ubuntu1204:~# ls /var/lib/lxc/
quantal-01  quantal-02

start quantal-02 without tty access. ( -d )
root@ubuntu1204:~# lxc-start -n quantal-02 -d -c /var/log/lxc-console.log

         -d, --daemon
             Run the container as a daemon. As the container has no more tty,
             if  an  error occurs nothing will be displayed, the log file can
             be used to check the error.

    -c, --console console_file
             Specify a file to output the container console. If the option is
             not specified the output will go the terminal except if  the  -d
             is specified.

root@ubuntu1204:~# lxc-list --all
RUNNING
 quantal-02

FROZEN

STOPPED
 quantal-01

connect to the quantal-02
root@ubuntu1204:~# lxc-console -n quantal-02

Type <Ctrl+a q> to exit the console
Ubuntu 12.10 quantal-02 tty1

quantal-02 login: ubuntu
Password:
Last login: Tue Dec  4 07:13:21 UTC 2012 on lxc/tty1
Welcome to Ubuntu 12.10 (GNU/Linux 3.2.0-34-generic x86_64)

* Documentation:  https://help.ubuntu.com/
ubuntu@quantal-02:~$
root@ubuntu1204:~#

remove a container from file system entirely
root@ubuntu1204:~# lxc-list
RUNNING

FROZEN

STOPPED
 quantal-01
 quantal-02

root@ubuntu1204:~# lxc-destroy -n quantal-02
root@ubuntu1204:~#

root@ubuntu1204:~# lxc-list
RUNNING

FROZEN

STOPPED
 quantal-01

root@ubuntu1204:~#

root@ubuntu1204:~# ls /var/lib/lxc/
quantal-01

No comments:

Post a Comment

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