When installing a Xen virtual machine, you need to determine what kind of block devices you want to work with. There are three possibilities: installing directly on a dedicated partition, using an important disk image file or creating your own disk image file with dd. In this article, you'll get an overview of the most important options.
Using physical disks
If you go for maximum performance, a physical disk device is the best way to go. When using physical disk devices, you can install on a partition or on a logical volume and when using logical volumes, you can use either EVMS or LVM. Using logical volumes does offer some advantages:
- Logical volumes are resizable.
- You can use snapshots to accomodate making backups.
The usage of physical disk devices has as its most important benefit that it offers the best possible performance. However, physical storage devices are not portable. Where it is easy to copy a disk image file, it is lots harder to make a copy of a logical volume or physical partition. Notice that it is harder, but not impossible. If for example you want to copy the entire logical volume /dev/xen/vm1 to a pre-existing logical volume with the name /dev/xen/vm1-backup, just use dd if=/dev/xen/vm1 of=/dev/xen/vm1-backup.
To address physical disk devices from the configuration file of a virtual machine, you need the following syntax in the disk definition:
, ,[r|w] For
example: disk=[ 'phy:/dev/system/mainserver,xvda,w', 'phy:/dev/cdrom,xvdb,r', ]
Using Xen disk image files
When installing a virtual machine on SUSE or Red Hat, by default Xen disk image files are used. This is an image file that is created using the dd utility, so basically there is nothing special to it. A dd disk image file doesn't compare to a file in the virtual hard disk (VHD) format, since there is no metadata associated to this type of disk image file; it's just ones and zeroes.
To create a disk image file, you need the dd utility to copy zeroes from the /dev/zero device to your disk image file. For example, if you want to create a 4 GB file with the name /var/lib/xen/images/disk1, use the following command:
dd if=/dev/zero of=/var/lib/xen/images/disk1 bs=1M count=4096
Apart from creating empty image files using the dd utility, you can also use ISO files as an alternative for your physical optical drives. The usage is the same as the usage of a disk image file created with dd. Don't have an ISO file yet? Then we have good news for you; it's easy to create one. If the cd-rom of which you want to create an ISO file is in your optical drive, use the following to copy it to a file with the name cdrom.iso:
dd if=/dev/cdrom of=/isos/cdrom.iso
After creating either a disk image file or an ISO file, you need to include the disk image file in your virtual machine configuration using the file option in the disk definition:
disk=[ 'file:/var/lib/xen/images/disk1,hda,w', 'file:/isos/cdrom.iso,hdc,r', ]
Working with image files from other sources
In some cases, you want to install a new virtual machine and create an image file to start with. In other situations you'll use with a disk image file from another virtualization environment. This can be a vmdk-file from a VMware environment, a qcow file from q Qemu environment or anything else. To work with these, you need the "tap" disk image. In the following line you see the syntax that you need to work with a vmdk-file from a VMware environment:
disk=[ 'tap:vmdk:/var/lib/xen/server1.vmdk,hda,w', ]
A special kind of tap device, is the Xen disk image file that uses the xen blktap kernel module. This module allows you to address a disk image file in a full virtualized environment as a para virtual device. To use this module, you need the aio device type. The disk image file itself can be an ordinary disk image file that is created with the dd command. The syntax to use in the configuration file for devices like that, would be as in the following:
disk=[ 'tap:aio:/var/lib/xen/server2.img,xvda,w', ]
The advantage of working with tap disk images is that you can use just any type of disk image. There is however also a disadvantage. In the current state management utilities such as virtual manager don't support tap devices. This means that you have to configure machine using this device manually.
Network block devices
The last disk type that you can use in a virtual machine, is the network disk type. This can be either a network block device such as a DRBD device, or an iSCSI device. This offers excellent possibilities to address a LUN on your iSCSI SAN directly, but do remember to start the iSCSI initiator in Domain0 first.
This disk image type is not portable, that means that you need to take the appropriate precautionary measures on the SAN to protect this type of disk image file. Think for example of making SAN level snapshots to protect these. To make a connection to an iSCSI LUN, you need to include the complete iSCSI Qualifying Name (iqn) in the configuration file of your Xen virtual machine. For example, if the iqn you need to use is iqn.2007-08.nl.example:xendata, you would need the following configuration line:
disk=[ 'iscsi:2007-08.nl.example:xendata,xvda,w', ]
In this article, you have read about the different options that exist to address disk devices in virtual machines. Even if in most scenarios the file and phy devices are used, other device types offer useful possibilities as well, in special the tap device type that allows you to communicate to almost any disk image file.
About the author: Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. Vugt is also a technical consultant for high-availability (HA) clustering and performance optimization, as well as an expert on SLED 10 administration.
This was first published in November 2007