In the previous article we installed xen 4.1 on debian squeeze, now let’s install some tools that will help us manage our VPSs, for now install xen-tools vnstat and, as always using apt-get for the update management is more easy.
First install vnstat
root@x49:/# apt-get install vnstat Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: vnstati The following NEW packages will be installed: vnstat 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/82.4 kB of archives. After this operation, 311 kB of additional disk space will be used. Selecting previously deselected package vnstat. (Reading database ... 28735 files and directories currently installed.) Unpacking vnstat (from .../vnstat_1.10-1_amd64.deb) ... Processing triggers for man-db ... Setting up vnstat (1.10-1) ... Starting vnStat daemon: vnstatdZero database found, exiting. failed!
The error is that there is not assigned network interfaces to vnstat, then proceed to add, in this case add eth0, eth1 and xenbr0
root@x49:/# vnstat -u -i eth0 Error: Unable to read database "/var/lib/vnstat/eth0". Info: -> A new database has been created. root@x49:/# vnstat -u -i eth1 Error: Unable to read database "/var/lib/vnstat/eth1". Info: -> A new database has been created. root@x49:/# vnstat -u -i xenbr0 Error: Unable to read database "/var/lib/vnstat/xenbr0". Info: -> A new database has been created. root@x49:/#
and the restart vnstat
root@x49:/# /etc/init.d/vnstat restart Stopping vnStat daemon: vnstatd. Starting vnStat daemon: vnstatd. root@x49:/#
Now install xen-tools, install the version that is in debian testing, first add at the end of your /etc/apt/preferences the following lines
Package: xen-tools Pin: release a=testing Pin-Priority: 750
and now proceed to install
root@x49:/# apt-get install xen-tools Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: debootstrap libconfig-inifiles-perl libexpect-perl libfile-slurp-perl libio-pty-perl libio-stty-perl libtext-template-perl Suggested packages: reiserfsprogs xfsprogs cfengine2 btrfs-tools Recommended packages: rinse The following NEW packages will be installed: debootstrap libconfig-inifiles-perl libexpect-perl libfile-slurp-perl libio-pty-perl libio-stty-perl libtext-template-perl xen-tools 0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded. Need to get 559 kB of archives. After this operation, 1,761 kB of additional disk space will be used. Do you want to continue [Y/n]? Get:1 http://ftp.debian.org/debian/ squeeze/main libio-stty-perl all 0.02-10 [10.1 kB] Get:2 http://ftp.debian.org/debian/ squeeze/main libio-pty-perl amd64 1:1.08-1 [42.5 kB] Get:3 http://ftp.debian.org/debian/ squeeze/main libexpect-perl all 1.20-2 [78.0 kB] Get:4 http://ftp.debian.org/debian/ squeeze/main libfile-slurp-perl all 9999.13-1 [16.8 kB] Get:5 http://ftp.debian.org/debian/ squeeze/main debootstrap all 1.0.26+squeeze1 [57.5 kB] Get:6 http://ftp.debian.org/debian/ squeeze/main libconfig-inifiles-perl all 2.52-1+squeeze1 [48.0 kB] Get:7 http://ftp.debian.org/debian/ squeeze/main libtext-template-perl all 1.45-1 [54.5 kB] Get:8 http://ftp.debian.org/debian/ wheezy/main xen-tools all 4.3.1-1 [252 kB] Fetched 559 kB in 5s (104 kB/s) Selecting previously deselected package libio-stty-perl. (Reading database ... 28749 files and directories currently installed.) Unpacking libio-stty-perl (from .../libio-stty-perl_0.02-10_all.deb) ... Selecting previously deselected package libio-pty-perl. Unpacking libio-pty-perl (from .../libio-pty-perl_1%3a1.08-1_amd64.deb) ... Selecting previously deselected package libexpect-perl. Unpacking libexpect-perl (from .../libexpect-perl_1.20-2_all.deb) ... Selecting previously deselected package libfile-slurp-perl. Unpacking libfile-slurp-perl (from .../libfile-slurp-perl_9999.13-1_all.deb) ... Selecting previously deselected package debootstrap. Unpacking debootstrap (from .../debootstrap_1.0.26+squeeze1_all.deb) ... Selecting previously deselected package libconfig-inifiles-perl. Unpacking libconfig-inifiles-perl (from .../libconfig-inifiles-perl_2.52-1+squeeze1_all.deb) ... Selecting previously deselected package libtext-template-perl. Unpacking libtext-template-perl (from .../libtext-template-perl_1.45-1_all.deb) ... Selecting previously deselected package xen-tools. Unpacking xen-tools (from .../xen-tools_4.3.1-1_all.deb) ... Processing triggers for man-db ... Setting up libio-stty-perl (0.02-10) ... Setting up libio-pty-perl (1:1.08-1) ... Setting up libexpect-perl (1.20-2) ... Setting up libfile-slurp-perl (9999.13-1) ... Setting up debootstrap (1.0.26+squeeze1) ... Setting up libconfig-inifiles-perl (2.52-1+squeeze1) ... Setting up libtext-template-perl (1.45-1) ... Setting up xen-tools (4.3.1-1) ... root@x49:/#
We have it installed, now proceed to configure xen-tools for that must edit /etc/xen-tools/xen-tools.conf look so well
NOTE: This is a basic configuration for testing, the original file has many options and are very well commented making it easy to fit the needs of each particular installation
NOTE 2: Modify data by corresponding network, this file is for a network 192.168.252.0
root@x49:/# cat /etc/xen-tools/xen-tools.conf ## dir = /var/lib/xen/DomUs # # # install-method = [ debootstrap | rinse | rpmstrap | copy | tar ] # # install-method = debootstrap # ## # Disk and Sizing options. ## # size = 4Gb # Disk image size. memory = 512Mb # Memory size swap = 512Mb # Swap size # noswap = 1 # Don't use swap at all for the new system. fs = ext4 # use the EXT3 filesystem for the disk image. dist = `xt-guess-suite-and-mirror --suite` # Default distribution to install. image = full # Specify sparse vs. full disk images. # # Uncomment and adjust these network settings if you wish to give your # new instances static IP addresses. # gateway = 192.168.252.1 netmask = 255.255.255.0 broadcast = 192.168.252.255 # # You can also change the password length by uncommenting and # changing the line below # genpass_len = 8 # # # Uncomment the following line if you wish to interactively setup a # new root password for images. # # passwd = 1 # # # Default kernel and ramdisk to use for the virtual servers # kernel = /boot/vmlinuz-`uname -r` initrd = /boot/initrd.img-`uname -r` # # The architecture to use when using debootstrap, rinse, or rpmstrap. # # This is most useful on 64 bit host machines, for other systems it # doesn't need to be used. # # arch = [i386|amd64] # # # The default mirror for debootstrap to install Debian-derived distributions # mirror = `xt-guess-suite-and-mirror --mirror` # # Filesystem options for the different filesystems we support. # ext3_options = noatime,nodiratime,errors=remount-ro ext2_options = noatime,nodiratime,errors=remount-ro xfs_options = defaults reiserfs_options = defaults btrfs_options = defaults root@x49:/#
Create the file /etc/xen-tools/partitions.d/default_4G with the following content
NOTE: This file is created for our tests, you can create multiple files with different partitioning schemes using the example /etc/xen-tools/partitions.d/sample-server
NOTE 2: If you are going to use reiserfs, xfs or btrfs not forget before install packages reiserfsprogs, xfsprogs and btrfs-tools
root@x49:/# cat /etc/xen-tools/partitions.d/default_4G [root] size=4G type=ext4 mountpoint=/ options=sync,errors=remount-ro [swap] size=512M type=swap root@x49:/#
Now create the file /etc/modprobe.d/loop.conf with the following content (NOTE: max_loop configure it with a 32 but should choose the one that best fits your needs)
root@x49:/# cat /etc/modprobe.d/loop.conf options loop max_loop=32 root@x49:/#
Then unload and load the loop module to load with the option you have configured
root@x49:/# rmmod loop ; modprobe loop root@x49:/#
We now proceed to perform the first installation of a DomU and checked that everything runs smoothly
root@x49:/# xen-create-image --dist=squeeze --hostname=x50 --vifname=x50 --mac=00:16:C0:A8:FC:32 --ip=192.168.252.50 --partitions=default_4G WARNING ------- You appear to have a "dummy" vif-script, or network-script, setting in the Xen configuration file /etc/xen/xend-config.sxp. Please fix this and restart Xend, or your guests will not be able to use any networking! General Information -------------------- Hostname : x50 Distribution : squeeze Mirror : http://ftp.debian.org/debian/ Partitions : swap 512M (swap) / 4G (ext4) Image type : full Memory size : 512Mb Kernel path : /boot/vmlinuz-3.2.0-0.bpo.4-amd64 Initrd path : /boot/initrd.img-3.2.0-0.bpo.4-amd64 Networking Information ---------------------- IP Address 1 : 192.168.252.50 [MAC: 00:16:C0:A8:FC:32] Netmask : 255.255.255.0 Broadcast : 192.168.252.255 Gateway : 192.168.252.1 Creating partition image: /var/lib/xen/DomUs/domains/x50/swap.img Done Creating swap on /var/lib/xen/DomUs/domains/x50/swap.img Done Creating partition image: /var/lib/xen/DomUs/domains/x50/root.img Done Creating ext4 filesystem on /var/lib/xen/DomUs/domains/x50/root.img Done Installation method: debootstrap Done Running hooks Done No role scripts were specified. Skipping Creating Xen configuration file Done No role scripts were specified. Skipping Setting up root password Generating a password for the new guest. All done Logfile produced at: /var/log/xen-tools/x50.log Installation Summary --------------------- Hostname : x50 Distribution : squeeze IP-Address(es) : 192.168.252.50 RSA Fingerprint : 92:96:56:40:60:4d:17:ce:72:5a:28:32:81:6f:9a:b3 Root Password : xxxxxxxx root@x49:/#
Now edit the file /etc/xen/x50.cfg and add extra options for our kernel
Note: Each particular case may require different kernel options.
root@x49:/# cat /etc/xen/x50.cfg # # Configuration file for the Xen instance x50, created # by xen-tools 4.3.1 on Thu Jan 17 01:33:06 2013. # # # Kernel + memory size # kernel = '/boot/vmlinuz-3.2.0-0.bpo.4-amd64' ramdisk = '/boot/initrd.img-3.2.0-0.bpo.4-amd64' vcpus = '1' memory = '512' # # Disk device(s). # root = '/dev/xvda2 ro' disk = [ 'file:/var/lib/xen/DomUs/domains/x50/root.img,xvda2,w', 'file:/var/lib/xen/DomUs/domains/x50/swap.img,xvda1,w', ] # # Physical volumes # # # Hostname # name = 'x50' # # Networking # vif = [ 'ip=192.168.252.50 ,mac=00:16:C0:A8:FC:32,vifname=x50' ] # # Behaviour # on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart' extra = 'elevator=deadline console=hvc0 noht loglevel=0'
And now we proceed to start the VPS
root@x49:/# xen create /etc/xen/x50.cfg -c Parsing config file /etc/xen/x50.cfg Daemon running with PID 18964 Loading, please wait... Begin: Loading essential drivers ... done. Begin: Running /scripts/init-premount ... done. Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done. Begin: Running /scripts/local-premount ... done. Begin: Running /scripts/local-bottom ... done. done. Begin: Running /scripts/init-bottom ... done. INIT: version 2.88 booting Using makefile-style concurrent boot in runlevel S. Starting the hotplug events dispatcher: udevd. Synthesizing the initial hotplug events...done. Waiting for /dev to be fully populated...done. Activating swap...done. Checking root file system...fsck from util-linux-ng 2.17.2 /dev/xvda2: clean, 13836/262144 files, 168287/1048576 blocks done. Loading kernel modules...done. Cleaning up ifupdown.... Setting up networking.... Activating lvm and md swap...done. Checking file systems...fsck from util-linux-ng 2.17.2 done. Mounting local filesystems...done. Activating swapfile swap...done. Cleaning up temporary files.... Configuring network interfaces...done. Cleaning up temporary files...Setting kernel variables ...done. . INIT: Entering runlevel: 2 Using makefile-style concurrent boot in runlevel 2. Starting enhanced syslogd: rsyslogd. Starting periodic command scheduler: cron. Starting OpenBSD Secure Shell server: sshd. Debian GNU/Linux 6.0 x50 hvc0 x50 login:
Then we login via ssh and check our VPS is installed correctly.
Then we can create a custom script vif-bridge so that when starting the VPS add the interface to vnstat, we put the script in /usr/local/xen/vif-bridge-local.sh with the following content
root@x49:/# cat /usr/local/xen/vif-bridge-local.sh #!/bin/bash XENSTORE_READ=/usr/sbin/xenstore-read VNSTAT=/usr/bin/vnstat THIS_FILE=`basename $0` FILE_LOG_ERRORS=/var/log/${THIS_FILE}.log . /etc/xen/scripts/xen-script-common.sh ACTION_TYPE=$1 TYPEIF=$2 evalVariables "$@" dev=vif case "$type_if" in vif) dev=${vif} ;; tap) dev=$INTERFACE ;; *) exit 1 ;; esac if [ "${ACTION_TYPE}" = "online" ] then if [ "${type_if}" = "vif" ] then /etc/xen/scripts/vif-bridge $@ KEY_VIFNAME=/local/domain/0/${XENBUS_PATH}/vifname vifname=`${XENSTORE_READ} ${KEY_VIFNAME} 2>/dev/null` ${VNSTAT} -u -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} ${VNSTAT} --enable -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} ${VNSTAT} --sync -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} ${VNSTAT} --reset -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} else /etc/xen/scripts/vif-bridge $@ fi fi if [ "${ACTION_TYPE}" = "offline" ] then if [ "${type_if}" = "vif" ] then KEY_VIFNAME=/local/domain/0/${XENBUS_PATH}/vifname vifname=`${XENSTORE_READ} ${KEY_VIFNAME} 2>/dev/null` ${VNSTAT} -r --disable -i ${vifname} 1>/dev/null 2>>${FILE_LOG_ERRORS} /etc/xen/scripts/vif-bridge $@ else /etc/xen/scripts/vif-bridge $@ fi fi if [ "${ACTION_TYPE}" = "add" ] then /etc/xen/scripts/vif-bridge $@ fi root@x49:/#
And edit /etc/xen/xl.conf look so
root@x49:/# cat /etc/xen/xl.conf ## Global XL config file ## # automatically balloon down dom0 when xen doesn't have enough free # memory to create a domain autoballoon=0 # full path of the lockfile used by xl during domain creation lockfile="/var/lock/xl" # default vif script #vifscript="/etc/xen/scripts/vif-bridge" vifscript="/usr/local/xen/vif-bridge-local.sh" root@x49:/#
Within this script if we can call some script itself to be responsible for limiting the bandwidth of the interface VPS, we’ll see in a future article.

About Ricardo Marcelo Alvarez
- Web |
- More Posts(58)