Install Multiple VPS On Ubuntu With OpenVZ

OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; a container can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files. OpenVZ is free open source software, available under GNU GPL.

Before install OpenVZ please remember this:

  • OpenVZ was only supported in Ubuntu 8.04 LTS (Hardy Heron), and not in Ubuntu 10.04 (Lucid Lynx)
  • At writing moment (november 2010) OpenVZ patch for kernel Linux 2.6.32 works, but is not yet released as stable, and for this reason is not recommended for production environments.
  • Ext4 filesystem is not yet supported by vzquota, then if you want to have host kernel stability, better use Ext3 for containers space in /vz or /var/lib/vz

How to install and configure OpenVZ on Ubuntu server:

  1. Open your terminal and login as root (otherwise you should prepend all the command below with su).
  2. Just in case your default shell is /bin/dash, you should change it to /bin/bash.:
    dpkg-reconfigure dash
    #install dash as /bin/sh? N
  3. Just in case you have AppArmor installed, remove it!
    /etc/init.d/apparmor stop
    update-rc.d -f apparmor remove
    apt-get remove apparmor apparmor-utils
  4. Find your kernel series:
    uname -r
    #Mine return 2.6.32-24-server
  5. Install these package below to build a new kernel:
    aptitude install kernel-package libncurses5-dev fakeroot wget bzip2 module-assistant debhelper

    then build the kernel

    aptitude build-dep linux-image-2.6.32-24-server
  6. Download the 2.6.32 kernel sources plus the OpenVZ kernel patch and the official config for the OpenVZ kernel:
    cd /usr/src
    m-a prepare
  7. Then run this command:
    echo "CONCURRENCY_LEVEL := 5" >> /etc/kernel-pkg.conf
    #Note: CONCURRENCY_LEVEL is same as your CPU core + 1. I have 4 core CPU so i make it 5
  8. Patch the kernel sources and prepare the build:
    tar -xpf linux-2.6.32.tar.bz2
    mv linux-2.6.32 linux-2.6.32-openvz
    rm -f linux
    ln -s linux-2.6.32-openvz linux
    cd linux
    gunzip -dc ../patch-belyayev.1-combined.gz | patch -p1
    cp -rf ../kernel-2.6.32-x86_64.config.ovz .config
    make oldconfig
  9. Build the OpenVZ kernel with the following command:
    fakeroot make-kpkg --initrd --append-to-version=-ovz32 --revision=1.0 kernel_image kernel_headers
  10. Look for new compiled kernel:
    cd ..
    ls -l *.deb
    # My result:
    #-rw-r--r-- 1 root src  6300866 2010-11-25 19:18 linux-headers-
    #-rw-r--r-- 1 root src 26274680 2010-11-25 19:12 linux-image-
  11. Install the new kernel:
    dpkg -i linux-image- linux-headers-
  12. Then update the initrd and the GRUB bootloader configuration:
    mkinitramfs -k -o /boot/initrd.img-
  13. Build the OpenVZ tools (vzctl, vzquota, vzpkg):

    aptitude install git-core git-buildpackage automake autoconf libtool liblockfile-simple-perl cstream liblog-agent-perl ssl-cert postfix rpm yum alien


    git clone git:// vzctl
    cd vzctl
    ./configure --enable-bashcomp --enable-logrotate
    make install
    make install-debian


    git clone git:// vzquota
    cd vzquota
    make install


    git clone git:// vzpkg
    cd vzpkg
    make install
  14. Run OpenVS on startup:
    update-rc.d vz defaults
    ln -s /vz /var/lib/vz

    15. Check sysctl.conf:

    vim /etc/sysctl.conf

    Should be like this:

    net.ipv4.conf.default.proxy_arp = 0
    kernel.sysrq = 1
    net.ipv4.conf.default.send_redirects = 1
    net.ipv4.conf.all.send_redirects = 0

    Reload sysctl.conf:

    sysctl -p
  15. Open /etc/vz/vz.conf and set NEIGHBOUR_DEVS to all:
    vim /etc/vz/vz.conf


  16. Reboot the machine:
  17. Check your kernel it should changed now:
    uname -r

OpenVZ is now installed, now we need to make a virtual machine in it:

  1. Download the OpenVZ template and place it under /vz/template/cache directory. You can download it from this link:
  2. I download Ubuntu 10.04 for this example:
    cd /vz/template/cache
  3. Set up a VPS from the Ubuntu 10.04 template:
    vzctl create 99 --ostemplate ubuntu-10.04-x86_64 --config basic

    note: 99 must be a unique id – each virtual machine must have its own unique ID

  4. Run the virtual machine on boot:
    vzctl set 99 --onboot yes --save
  5. Set a hostname and IP address for the vm:
    vzctl set 99 --hostname --save
    vzctl set 99 --ipadd --save
  6. Set the number of sockets to 120 and assign nameservers:
    vzctl set 99 --numothersock 120 --save
    vzctl set 99 --nameserver --nameserver --save

    note: Virtual machine configuration is locate in /etc/vz/conf/{vm-id}.conf

  7. Start vm:
    vzctl start 99
  8. Now you have a virtual machine. Test it and have fun with it.

    Additional vzctl command:
    To set a root password:

    vzctl exec {vm-id} passwd

    Connect to vm ssh:

    vzctl enter {vm-id}

    Stop vm:

    vzctl stop {vm-id}

    Restart vm:

    vzctl restart {vm-id}

    Delete vm:

    vzctl destroy {vm-id}

    List of your vm and status:

    vzlist -a

    Fin more command in vzctl manual:

    man vzctl

Useful links:


  1. Yuswar says:

    keren dan simpel, semua komando unix, lihat, priksa dan run!

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.