Saturday, October 11, 2014

Introduction to lxc -- linux container

lxc is linux containers. it work similar to vmware, virtualbox. but it does not full features as vmware or virtualbox. unlike vmware or virtualbox, lxc does not lock the memory when running, it share the memory with host machine.


1- install lxc
root@lxc-virt# apt-get install lxc

2- create lxc name deb7 and type is debian  -n: name, -t:template
root@lxc-virt# lxc-create -n deb7 -t debian
debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/debian/rootfs-wheezy-amd64 ...
Copying rootfs to /var/lib/lxc/deb7/rootfs...Generating locales (this might take a while)...
  en_US.UTF-8... done
  en_US.UTF-8... done
Generation complete.
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing

Current default time zone: 'America/New_York'
Local time is now:      Sat Oct 11 22:28:54 EDT 2014.
Universal Time is now:  Sun Oct 12 02:28:54 UTC 2014.

Root password is 'root', please change !


3- list and run the newly containers
root@lxc-virt# lxc-ls
deb1     deb7     tubuntu


root@lxc-virt# lxc-start -n deb7

4- shared directory /root/share1 from Host machine to container
add the following line to /var/lib/lxc/deb7/fstab

/home/share1 /var/lib/lxc/deb1/rootfs/share1 none ro,bind 0 0

then reboot reboot the container deb7, when we login to the deb7, we will see content on /share1

--- Note ---
 if the  don't have cache on /var/cache/lxc/debian/rootfs-wheezy-amd64, l;xc will try to install from the Internet, but if you already have iso file and want to use it to install you have to install the it in vmware/virtualbox first that mount the / to /var/cache/lxc/debian/rootfs-wheezy-amd64

and how to mount disk of vmware/virtualbox http://theamdara.blogspot.com/2013/12/how-to-mount-virtualbox-disk-vdi.html

No comments:

Post a Comment