Looking for an LXC vs. OpenVZ lineup? Read my side by side comparison!
After a few nights trying to get the OpenVZ kernel patch properly applied and compiled on Ubuntu 12.04 I decided to give LXC a shot. Although I finally got OpenVZ to work, I wasn’t really satisfied with the results. My main problem was, that the kernel version was quite old and there are some features in the newer kernels I really need. As my last information on LXC was it still being quite experimental, so I wasn’t expecting much. Boy, was I in for a surprise…
Be sure to read my new, more complete LXC tutorial!
My test server was a virtual machine with a gig of ram and an (almost) fresh installation of Ubuntu Server. So after reading Stéphane Grabers tutorial and doing some digging on my own, I ran the following commands:
apt-get install lxc lxc-create -t ubuntu-cloud -n test lxc-start -n test
Holy smokes, that was fast! The installation finished just under 30 seconds, while creating the virtual machine took about 2 minutes out of which it spent one minute downloading the image. After the start I could log in on the console using the username and password ubuntu.
Now that was pretty impressive, however I had a bit of a problem getting out of the console, so I shut the virtual environment down. After reading a bit in the LXC manual I found out, that virtual machines can be run as a daemon:
lxc-start -n test -d
Entering the console then would only require lxc-console like this:
lxc-console -n test
It would work just as a regular console, except that you can exit using Ctrl + a, q. Knowing how OpenVZ works, I was really curious, how my process list would look like in LXC. It turned out, it wasn’t that much different, except that lxc-start showed up in the process tree, making identification of guest VE processes simple:
root@host02:~# ps afx PID TTY STAT TIME COMMAND ... 4305 ? Ss 0:00 lxc-start -n test -d 4309 ? Ss 0:00 \_ /sbin/init 4435 ? S 0:00 \_ upstart-udev-bridge --daemon 4458 ? Ss 0:00 \_ dbus-daemon --system --fork --activation=upstart 4464 ? Ss 0:00 \_ /sbin/udevd --daemon 4466 ? Sl 0:00 \_ rsyslogd -c5 4580 ? S 0:00 \_ upstart-socket-bridge --daemon 4615 ? Ss 0:00 \_ dhclient3 -e IF_METRIC=100 -pf 4634 ? Ss 0:00 \_ /usr/sbin/sshd -D 4686 pts/4 Ss+ 0:00 \_ /sbin/getty -8 38400 tty4 4699 pts/2 Ss+ 0:00 \_ /sbin/getty -8 38400 tty2 4701 pts/3 Ss+ 0:00 \_ /sbin/getty -8 38400 tty3 4708 ? Ss 0:00 \_ cron 4709 ? Ss 0:00 \_ atd 4711 ? Ss 0:00 \_ acpid -c /etc/acpi/events -s /var/run/acpid.socket 4750 pts/5 Ss+ 0:00 \_ /sbin/getty -8 38400 console 4754 pts/1 Ss+ 0:00 \_ /sbin/getty -8 38400 tty1 4756 ? Ssl 0:00 \_ whoopsie
There was only one thing left to do before getting on with my usual server configuration routines: make the LXC container autostart. To do that I had to symlink the configuration into the /etc/lxc/auto directory:
cp -s /var/lib/lxc/test/config /etc/lxc/auto/test
tl;dr
Of course I did more testing, which is not the scope of this blog post, but I recon that with Ubuntu 12.04 LXC has become a full-fledged tool with all the bells and whistles it needs. Since being incorporated into the Linux kernel means faster security fixes and better support, I recommend it for general use over OpenVZ. If you want to read a detailed comparison, continue with this blog post.
Great article. I too have had issues and incompatibilities with OpenVZ and I’m about to give LXC a go.