Installing and Running XenServer 4.1 on an External USB Drive
With a few tweaks, you can run XenServer from an external USB drive.
I often get asked about running hypervisors from portable storage devices and in this column, I'd like to talk about a method for installing and running XenServer 4.1 from a portable USB hard drive. This is useful if you are testing multiple hypervisor solutions and do not want to multi-boot the hypervisors on local server storage. Since XenServer Express Edition is free
, you can evaluate the product for as long as you like and eventually upgrade the license if you want to unlock the product's enterprise-class features.
Of course, the physical host server is going to need to meet XenServer 4.1's system requirements. Servers with support for hardware-assisted virtualization (one of XenServer's hardware requirements) should also support USB device boot. Many USB flash drives offer enough storage space for a XenServer installation (16GB is required per the official requirements). Note that the actual software installation will only consume about 2GB. However, keep in mind that USB flash drives perform considerably slower than traditional hard disks. So if performance is a consideration, I highly recommend using a 2.5" external USB drive. In preparation for this article, I used a Seagate external USB 2.0 40 GB hard disk.
While not required, I disabled all internal hard disks in the test server's BIOS so that the XenServer installation would only see the external USB drive. This prevents accidentally installing XenServer on an internal server hard disk.
At this point, you should be ready to install XenServer 4.1. You can do so by following the installations steps documented in the XenServer 4.1 Installation Guide. Note that you will only be prompted to select the installation drive if the system can see multiple attached drives. If you take the cautionary step to disable all locally attached physical drives, you will not see this option. If multiple drives are present, you will also be prompted to select the drive for virtual storage, which again should be the external USB drive.
Once the XenServer installation completes, you will be prompted to hit Enter to reboot the server. This is where the trouble will begin. USB support is not preloaded by the mkinitrd image, by default, which will eventually cause a kernel panic and automatic reboot when XenServer starts. Note that if you are not seeing XenServer boot, that's probably because the USB drive was listed farther down in the boot order than another system drive. You can select to boot from the USB drive by clicking the hotkey to access the boot options menu and selecting to boot from the USB drive at that point. For example, the boot options menu on many Dell servers is accessed by hitting the F11 key when the server boots.
To get XenServer to successfully boot on an external USB drive, follow these steps:
- When the server boots, hit the hotkey for the boot options menu.
- Ensure that the XenServer installation CD is in the CD-ROM drive.
- In the boot options menu, select the option to boot from the CD-ROM.
- As soon as the Welcome to XenServer setup screen loads, immediately press the F2 key to view the advanced setup options.
- Now type shell and hit Enter.
- When the system finishes booting, run the following command to create a temporary folder where you will mount the external USB drive:
- You will now mount the USB drive to the temporary location. Note that I'm assuming the USB drive is the only drive attached to the system and therefore is mounted as /dev/sda. To mount the first partition of sda to the /tmp/sda folder, run this command:
mount -t ext3 /dev/sda1 /tmp/sda
- You will now need to copy the sys/block drivers from the setup environment to the USB drive. However, you will first need to change the driver file permissions prior to the copy. To do this, run this command:
chmod -R 664 /sys/block
- You can now copy the contents of /sys/block to the USB drive. To do this, run this command:
cp -R /sys/block/ /tmp/sda/sys/block/
Note: Disregard the resultant "Input/Output error" message. The file copy will complete successfully.
- Next you need to change the root location to /tmp/sda. You can do this by running the command:
- Now let's change to the /boot folder on the USB drive. To do this, run the command:
- Now we will rename the original primary initrd image file because the new image file will have the same name as the original file for ease of configuration. To rename the primary initrd image file, run this command:
mv initrd-2.6.18-53.1.13.el5.xs184.108.40.206.273xen.img initrd-2.6.18-53.1.13.el5.xs220.127.116.11.273xen.img.old
- Next, we'll create a new initrd image that includes the USB driver. To do this, run this command:
mkinitrd --with-usb initrd-2.6.18-53.1.13.el5.xs18.104.22.168.273xen.img 2.6.18-53.1.13.el5.xs22.214.171.124.273xen
- At this point, you will now be able to successfully boot XenServer from an external USB drive. To reboot, the server, type exit and hit Enter and then type reboot and press Enter. Remember to select the external USB drive from the boot options menu when the server boots.
When the XenServer system successfully boots, you should see that the post installation script that XenServer attempts to run will fail. The post install script will try and configure the third partition created during the XenServer installation as a data store for VM files, but will fail in the process. Since the script fails to add a local data store, you'll just need to do this manually. Note that this assumes that you have enough additional storage on the external USB drive for VM storage.
If you plan to use local storage for VMs, follow these steps:
- Login to the XenServer console using the root account and the root account password you specified when you installed XenServer.
- Run fdisk -l to view the available partitions on the attached USB drive. The command execution and output is shown below:
[root@xensrv1 ~]# fdisk -l
Disk /dev/sda: 40.0 GB, 40007761920 bytes
64 heads, 32 sectors/track, 38154 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 3907 4000752 83 Linux
/dev/sda2 3908 7814 4000768 83 Linux
/dev/sda3 7815 38154 31068160 83 Linux
- As you can see, most of the drive's storage blocks are allocated to /dev/sda3. This is the partition you will configure as a local data store for VM files. Next, you need to query the host universal unique identifier (UUID) which is generated when XenServer is installed. To do this, run this command:
The command execution and its output is shown here:
[root@xensrv1 /]# cat /etc/xensource-inventory
- Note the INSTALLATION_UUID value listed in the cat command's output. You will need it to create the new local storage repository. You can now add the local storage repository by using the xe sr-create command with the following syntax:
xe sr-create content-type="localSR" host-uuid=<INSTALLATION_UUID> type=ext device-config-device=<disk partition> shared=false name-label "<friendly label>"
On my test system, the following values were used:
Disk partition: /dev/sda3
Friendly label: "Local USB Storage"
The full command used to configure the local storage repository in my test environment is shown below:
[root@xensrv1 /]# xe sr-create content-type="localSR" host-uuid=d3e7e1e6-80f3-4241-a6cf-3bf83971c0e6 type=ext device-config-device=/dev/sda3 shared=false name-label "Local USB Storage"
The remaining configuration can be performed with the XenCenter management server, which can be installed on any Windows system in your environment. XenCenter is the GUI-based central administration tool for XenServer environments. You can get more information on XenCenter on the Citrix XenServer page.
You should now be able to login to XenCenter and manage the new XenServer with its available local USB storage. At this point, you are ready to install a VM on the local storage. Of course, if you do not have additional room on the local disk, you can configure network storage (i.e. NFS, iSCSI, Fibre Channel) and store VM files on the network storage array.
Now you can create a new VM by clicking the "New VM" object in the XenCenter toolbar and entering the required information in the New VM wizard.
When you're done testing, just shut down any running VMs and shut down the XenServer. If you disabled any local hard disks in the system BIOS, just re-enable them and your test server is returned to its original configuration.
Chris Wolf is VMware's CTO, Global Field and Industry.