Let's assume that your own IP is 192.168.1.1, your gateway is 192.168.1.254 and your network is 192.168.1.0/24.
You should make a bridged interface on your host machine, like this in /etc/network/interfaces file
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 192.168.1.1
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.254
bridge_ports eth0
bridge_stp off
bridge_fd 3
bridge_hello 1
bridge_maxage 5
and then install a basic ubuntu in LXC:
apt-get install lxc vlan bridge-utils python-software-properties screen
mkdir /lxc
debootstrap oeniric /lxc/ubuntu
chroot ubuntu
locale-gen en_US.UTF-8
apt-get update
apt-get install lxcguest ssh
passwd
rm /etc/mtab
ln -s /proc/mounts /etc/mtab
exit
create a file /lxc/ubuntu.config with the content
lxc.utsname = ubuntu
lxc.tty = 8
lxc.rootfs = /lxc/ubuntu
lxc.mount = /lxc/ubuntu.fstab
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.network.mtu = 1500
lxc.network.ipv4 = 192.168.1.10/24
/lxc/ubuntu.fstab with
none /lxc/ubuntu/dev/pts devpts defaults 0 0
none /lxc/ubuntu/proc proc defaults 0 0
none /lxc/ubuntu/sys sysfs defaults 0 0
none /lxc/ubuntu/run tmpfs defaults 0 0
add to /lxc/ubuntu/etc/rc.local
route add default gw 192.168.1.254
edit /lxc/ubuntu/etc/resolv.cont according your needs.
Then you can create your machine with
lxc-create -f /lxc/ubuntu.config -n ubuntu
then start
lxc-start -n ubuntu
or stop
lxc-stop -n ubuntu
or finally destroy
lxc-destroy -n ubuntu
Your new virtual machine will have the IP 192.168.1.10 and will be accessible on the network.
I do this all the time using LXC and the OpenVZ CentOS templates.
The two guides I followed initially are here and here.
I usually place my containers under /srv/
or /srv/lxc/
. I don't bother with LVM, but if you want to, just mount your new LVM volume under /srv/lxc/container_name
per-container. That makes sense, right?
In this example, I have a ZFS-on-Linux mount at the place where I want the container to reside under /srv
:
[root@Lancaster_Mirror1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 12G 1.9G 9.4G 17% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
/dev/cciss/c0d0p1 291M 59M 218M 22% /boot
/dev/cciss/c0d0p7 2.0G 119M 1.8G 7% /tmp
/dev/cciss/c0d0p3 9.9G 1.9G 7.5G 20% /usr
/dev/cciss/c0d0p6 6.0G 321M 5.3G 6% /var
vol2/images 98G 43G 56G 44% /images
vol3/Lancaster_Test 98G 22G 77G 22% /srv/Lancaster_Test <<--container
As for the LXC installation, I take the prebuilt OpenVZ image and put it in the destination container directory, then unpack it - tar -ztvf centos-6-x86_64-devel.tar.gz
. Nothing needs to be modified on the template to make this work.
426 wget http://downloads.sourceforge.net/project/lxc/lxc/lxc-0.7.3/lxc-0.7.3.tar.gz
427 rpmbuild -ta lxc-0.7.3.tar.gz
429 rpmbuild -ta lxc-0.7.3.tar.gz
434 yum --nogpg install lxc-0.7.3-1.x86_64.rpm libvirt
437 lxc-create -f /etc/lxc/Lancaster_Test.conf -n Lancaster_Test
438 lxc-checkconfig
441 screen -dmS init-Lancaster_Test /usr/bin/lxc-start -n Lancaster_Test
442 screen -dmS console-Lancaster_Test /usr/bin/lxc-console -n Lancaster_Test
Maybe I'm off, but I choose to use the containers directly on a filesystem. Are you doing something different?
I can provide excerpts of the lxc config files, but you don't seem to have an issue with that.
Best Answer
it is a good document http://www.scribd.com/doc/36864274/Create-Lucid-LXC-Container and you can extract open vz template to make a jail rootfs instead of using debootstrap