Configuring a 2nd local partition on Citrix Xenserver 6.2

Recently, I came across a server with two storage arrays, one hdd  and one ssd. Citrix Xenserver was installed on the first storage array and the second one was not configured. I had to ssh on xenserver and run a few commands to force xenserver see the 2nd array properly.

First run fdisk -l

fdisk command

fdisk command

As you can see /dev/sda is the first storage array and /dev/sdb partition is not valid. So run pvcreate /dev/sdb to create the LVM on sdb physical storage device.

pvcreate command

pvcreate command

Finally create the local storage repository by running

xe sr-create type=lvm content-type=user device-config:device=/dev/sdb name-label="Local SSD"

sr-create command

sr-create command

Now the new storage disk will appear on xencenter under the “Local SSD” label.

Reading and Writing on a NTFS USB Drive attached on a Citrix Xenserver 6.2

Sometimes you need to backup your VMs on a USB drive to easily carry them away or because there is not enough space on your NFS/CIFS storage. So the question is, how to mount an external NTFS USB drive on Xenserver with read/write permissions.

First of all ssh to your xenserver and type in the fdisk -l command.

Fdisk command output

Fdisk command output

fdisk shows the disks that xenserver knows about. Notice that the device name of the usb drive is /dev/sdc and its first partition is /dev/sdc1. If you try to mount the device, for example let’s create a usb directory and mount the drive on it:

mkdir /mnt/usb

mount -t ntfs /dev/sdc1 /mnt/usb

The problem is that xenserver supports only read access on NTFS formatted drives. So you may read anything or restore VMs under the /mnt/usb directory, but you cannot write any file including your backups. Let’s try to import a backup file.

xe vm-import filename='/mnt/usb/myBackupFile.xva'

If your drive is ext3 formatted, you will be able to mount it in read/write mode, but it will be difficult to mount it on a windows machine. We need to install to xenserver the appropriate  NTFS-3G driver to be able to have write permission as well. Ok, let’s first unmount to USB drive.

umount /mnt/usb

The following is a summary of information from various pages regarding the installation of NTFS-3G drivers on xenserver and I successfully installed it on a xenserver 6.2.

First we need to download rpmforge package for CentOS 5. More info at this page.

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm

Install DAG’s GPG key

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

Verify the package

rpm -K rpmforge-release-0.5.2-2.el5.rf.i386.rpm

Install it

rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm

Disable it by changing the following flag: enabled = 1 to enabled = 0 in the following file

vi /etc/yum.repos.d/rpmforge.repo

Install the library/driver

yum --enablerepo=rpmforge --enablerepo=base install fuse-sshfs

yum --enablerepo=rpmforge install ntfs-3g

Finally mount the USB drive

mount -t ntfs-3g /dev/sdc1 /mnt/usb

Now the usb drive is NTFS writeable. Don’t forget to unmount the drive by issuing the umount command

umount /mnt/usb

Free Backup for Citrix Xenserver Live Virtual Machines

A few days ago, I was looking for a free backup solution for live Citrix Xenserver 6.2 VMs and I came across a rather old script on this page

http://www.jansipke.nl/creating-backups-of-running-vms-in-xenserver/

The script uses Xenserver’s XE commands to do the following:

  • Enumerates the VMs and finds their UUIds
  • Creates a snapshot for each live VM
  • Exports the snapshot to a xva file
  • And finally removes each snapshot

I edited the script to match my needs, for example my setup includes a pool of two Xenservers 6.2 connected to a NAS storage (running Synology‘s DSM ) that publish an iscsi and nfs shares. I wanted the Xenservers to mount the nfs share and save the backup. So I added a few more lines

cmd = "mount -t nfs 192.168.178.225:/volume1/nfs/backups /mnt/nfs"
commands.getoutput(cmd)

and

cmd = "umount /mnt/nfs"
commands.getoutput(cmd)

This script can be easily scheduled to run whenever you like. The final script is like this

#!/usr/bin/python

import commands, time

def get_backup_vms():
result = []

cmd = "xe vm-list is-control-domain=false is-a-snapshot=false"
output = commands.getoutput(cmd)

for vm in output.split("\n\n\n"):
lines = vm.splitlines()
uuid = lines[0].split(":")[1][1:]
name = lines[1].split(":")[1][1:]
result += [(uuid, name)]

return result

def backup_vm(uuid, filename, timestamp):
cmd = "xe vm-snapshot uuid=" + uuid + " new-name-label=" + timestamp
snapshot_uuid = commands.getoutput(cmd)

cmd = "xe template-param-set is-a-template=false ha-always-run=false uuid=" + snapshot_uuid
commands.getoutput(cmd)

cmd = "xe vm-export vm=" + snapshot_uuid + " filename=" + filename
commands.getoutput(cmd)

cmd = "xe vm-uninstall uuid=" + snapshot_uuid + " force=true"
commands.getoutput(cmd)
cmd = "mount -t nfs 192.168.178.225:/volume1/nfs/backups /mnt/nfs"
commands.getoutput(cmd)
for (uuid, name) in get_backup_vms():
timestamp = time.strftime("%Y%m%d-%H%M", time.gmtime())
print timestamp, uuid, name
filename = "\"/mnt/nfs/" + timestamp + " " + name + ".xva\""
backup_vm(uuid, filename, timestamp)
cmd = "umount /mnt/nfs"
commands.getoutput(cmd)

First let’s see my NFS setup

My NFS setup

My NFS setup

You may notice that my two xenservers  have read/write access to the share folder and the NAS publish the nfs folder as /volume1/nfs. The nfs storage should be configured on xencenter’s pool by right clicking on your pool and selecting New SR… Check the NFS ISO library and type in the Share Name as <ip>:/<path>, in my case 192.168.178.225:/volume1/nfs.

NFS Storage Setup

NFS Storage Setup

Then ssh to pool master xenserver and create a new file e.g. backup.sh (with vi), edit the aforementioned script to match your storage needs and paste it to the shell script, give execute permissions to it and run it. The output will be like this

Script Output

Script Output

the first field is the UUid of the VM and the second field is its name. During the backup process you can watch the steps of the script on XenCenter’s gui. First the ctration of vm’s snapshot.

Snapshot Creation

Snapshot Creation

Then the snapshot’s export.

VM's export

VM’s export

Finished export

Finished export

It took 12 minutes for a 4 GB snapshot, not bad for a 100Mbit LAN. Then the snapshot is erased.

No snapshot

No snapshot

Finally, let’s look the backed up files on NFS storage.

Backed up VM files

Backed up VM files

This is a free, simple, transparent and easy solution to backup your Xenserver VMs. It works with the latest 6.2 open source version. It is not that advanced to do deduplication or WAN acceleration or other fancy staff, but it works and it’s free and pretty enough for small setups or home labs.

Post Notes:

  • Due to wordpress preformatting problems, you may find the script at http://pastebin.com/5E6wJS7u
  • The mount path should exist so execute mkdir /mnt/nfs to create the nfs directory

Applying Hotfixes on Citrix Xenserver 6.2 hypervisor without XenCenter

Citrix Xenserver is a beautiful open source (from 6.2 edition and later) hypervisor that tries to grab as much as possible market share on virtualization/cloud world. It carries many years of development efforts by Citrix, many well established implementations and a broad support community.

XenMotion, High Availability and all the great features of Xenserver are available on the licensed and unlicensed versions of the hypervisor. The licensed version includes automated patches and updates through XenCenter console and 24×7 Citrix Technical Support. On the unlicensed version, the administrator should apply the xenserver patches by himself through an ssh console. XenCenter still notifies the availability of new patches.

So, on XenCenter when you goto Tools – Install Updates, you get grayed out options like this

XenCenter Upadtes Installation

XenCenter Upadtes Installation

So, first of all we should download the new patches from Citrix webserver, XenCenter will help you to do so. Then unzip the contents of the downloaded files and secure ftp them on XenServer.

Ftp the updates to XenServer

Ftp the updates to XenServer

I use filezilla to sftp the updates to XenServer in binary transfer mode and upload them to /var/tmp directory. Then ssh to XenServer (I use putty utility to do so but you can use anything you are comfortable with). Login as root and run the following command

xe patch-upload file-name=/var/tmp/<update file>

this command produces a uuid alphanumeric string. Copy it to the clipboard and on XenCenter notice the yellow down icons that appear, indicating that a hotfix or update exists but has not been applied.

XenCenter warning icon

XenCenter warning icon

Run

xe patch-pool-apply uuid=<uuid>

pasting the uuid string. You may verify the applied patches by running

xe patch-list

Verifying patches

Verifying patches

If the update has been successful, the hosts field should contain the uuids of all the hosts in the pool. Finally, run

xe-toolstack-restart

to reload the toolstack on all hosts, you may loose the connection if you run it on Pool Master.

Applying Patches

Applying Patches

Now, your XenServer is patched!

XenCenter Install Updates window

XenCenter Install Updates window

Citrix Xenserver 6.2 Release

Today Citrix organized a webinar called Xenserver 6.2 Release under the Cloud Master Class series. The presenters summarized the new features and performance improvements of the free, now, Xenserver 6.2 and the open source advantages. It was a crowdy place with about a thousand registrations, 50% customers, 20% consultants, 20% partners and 10% potential customers, if I recall correctly. Citrix is on its way to grab more market share on server virtualization platforms!

I attach the latest slide of the presentation that underlines the main points of Citrix Xenserver 6.2

Xenserver 6.2 Summary

Xenserver 6.2 Summary

Looking forward to upgrade my setups…

More at http://www.xenserver.org