lost and found ( for me ? )

Ubuntu 13.10 : LXC

Reference

# tail -1 /etc/lsb-release ;uname -ri
DISTRIB_DESCRIPTION="Ubuntu 13.10"
3.11.0-15-generic x86_64

install lxc

# apt-get install lxc lxc-templates

# dpkg -l lxc*
+++-==============-============-============-=================================
ii  lxc            1.0.0~alpha1 amd64        Linux Containers userspace tools
ii  lxc-templates  1.0.0~alpha1 all          Linux Containers userspace tools

[ setup ]

Here are config files which are under /etc/init directory.
# ls /etc/init/lxc*
/etc/init/lxc.conf  /etc/init/lxc-instance.conf  /etc/init/lxc-net.conf

/etc/default/lxc  is config file as well.

- use br0 tied to eth0

edit /etc/default/lxc-net
# egrep -v ^# /etc/default/lxc-net
USE_LXC_BRIDGE="false"

LXC_BRIDGE="br0"
LXC_ADDR="10.0.3.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.0.3.0/24"
LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
LXC_DHCP_MAX="253"



# cat /etc/lxc/default.conf
lxc.network.type = veth
#lxc.network.link = lxcbr0
lxc.network.link = br0
lxc.network.flags = up



interfaces file is as below.
# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
address 192.168.11.100
netmask 255.255.255.0
gateway 192.168.11.1
dns-nameservers 127.0.0.1 8.8.8.8
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0

[ directory where containers are stored ]

/var/lib/lxc : containers are stored
/var/cache/lxc  : cached data are stored ( I am not sure .. )

If you want to change the directory where containers stored, create symbolic links like this:
# rm -rf /var/lib/lxc /var/cache/lxc/

root@ubuntu:~:# mkdir /var/disk1/lxclib
root@ubuntu:~:# mkdir /var/disk1/lxccache

root@ubuntu:~:# ln -s /var/disk1/lxclib /var/lib/lxc
root@ubuntu:~:# ln -s /var/disk1/lxccache /var/cache/lxc

[ build containers by using templates ]

here is the list of container templates you can build.
# ls /usr/share/lxc/templates/
lxc-alpine     lxc-busybox  lxc-fedora    lxc-sshd
lxc-altlinux   lxc-cirros   lxc-opensuse  lxc-ubuntu
lxc-archlinux  lxc-debian   lxc-oracle    lxc-ubuntu-cloud

build ubuntu 13.10 container.

-t means use template (  lxc-ubuntu )
-n : container name
-- :  template option
-r : distribution name
# lxc-create -t ubuntu -n ubuntu1310-cn1 -- -r saucy
Checking cache download in /var/cache/lxc/saucy/rootfs-amd64 ...
installing packages: vim,ssh,language-pack-en,language-pack-ja
Downloading ubuntu saucy minimal ...
I: Retrieving Release
I: Retrieving Release.gpg
<snip>
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##


#

okay.

:# ls /var/lib/lxc/ubuntu1310-cn1/*
/var/lib/lxc/ubuntu1310-cn1/config  /var/lib/lxc/ubuntu1310-cn1/fstab

/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



start the container

# lxc-ls --fancy
NAME            STATE    IPV4  IPV6  AUTOSTART  
----------------------------------------------
ubuntu1310-cn1  STOPPED  -     -     NO   

# lxc-start -n ubuntu1310-cn1



[ clone ]

stop the container and then clone

root@ubuntu:~:# lxc-stop -n ubuntu1310-cn1


root@ubuntu:~:# lxc-clone -o ubuntu1310-cn1 -n ubuntu1310-cn2
Created container ubuntu1310-cn2 as copy of ubuntu1310-cn1
#

No comments:

Post a Comment

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