Openvz – cheat sheet
My current cheat sheet for OpenVZ on Debian. Will be updated continuously. Comments are welcome.
Installation
apt-get install linux-image-...-vz
Getting Debian Lenny template
in /var/lib/vz/templates/cache :
wget http://download.openvz.org/template/precreated/debian-5.0-x86.tar.gz
Create VM
vzctl create VEID --ostemplate debian-5.0-x86 --config vps.basic
vzctl set VEID --hostname HOST --save
vzctl set VEID --nameserver DNS --save
vzctl set VEID --ipadd IP --save
Give internet access to VM
On host : Enable net.ipv4.ip_forward=1 in /etc/sysctl.conf
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-save > /etc/iptab
Restore iptables on startup
(See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=434107)
Create /etc/init.d/iptables
#!/bin/sh
### BEGIN INIT INFO
# Provides: iptables
# Required-Start:
# Required-Stop:
# Default-Start: S
# Default-Stop: 0 6
# Short-Description: save/restore iptables rules
# Description:
# This script saves and restores iptables on
# shutdown and bootup. On sysv-rc systems: to
# disable saving on shutdown, remove
# /etc/rc[06].d/K20iptables. To disable restoring
# on bootup, rename the "S20iptables" symbolic link
# in /etc/rcS.d/ to "K20iptables".
### END INIT INFO
set -e
case "$1" in
start|restart|force-reload)
iptables-restore ;;
stop)
iptables-save >/etc/iptab
;;
*)
exit 1
;;
esac
update-rc.d iptables start 20 S . stop 20 0 6 .
Change template timezone
dpkg-reconfigure tzdata
Install vzdump
(From http://download.openvz.org/contrib/utils/vzdump/)
wget http://download.openvz.org/contrib/utils/vzdump/vzdump_1.2-4_all.deb
apt-get install liblockfile-simple-perl
Do a backup
vzdump --compress --suspend --dumpdir TARGET VEID
Change limits
Disk :
vzctl set VEID --diskspace 10G:12G --save
Memory :
vzctl set VEID --vmguarpages $((512 * 512)) --save
vzctl set VEID --privvmpages $((512 * 1024)) --save
Cores
vzctl set VEID --cpulimit 100 --save
CPU ratio
vzctl set VEID --cpuunits 500 --save







