Grant McWilliams

Add a CD to a VM

Prerequisites

  • XCP/Xenserver

Adding a CD to a running VM is not a difficult task if you know which commands to use. By adding I mean we're going to insert a virtual CD disk into a virtual machine using our little virtual hands. ;-)

 

1. Get the name of your Virtual Machine

In this case the name is CentOS6 and the UUID is cefb9f88-0424-6701-5ba1-070490c69203.

[ [email protected] ~/bin ] xe vm-list
     uuid ( RO)           : cefb9f88-0424-6701-5ba1-070490c69203
          name-label ( RW): CentOS6
         power-state ( RO): running

 

2. Get the name of the CD disk

In this case our disk is named CentOS-6.3-x86_64-LiveCD.iso.

[ [email protected] ~/bin ] xe cd-list
    uuid ( RO)          : 0549c68a-e38d-4cd8-9974-ba0b9167ff5a
        name-label ( RW): CentOS-6.3-x86_64-LiveCD.iso

 

3. Identify a free Virtual Block Device number

Use the VM UUID that we retrieved in step 1.

[ [email protected] ~/bin ] xe vm-param-get uuid=cefb9f88-0424-6701-5ba1-070490c69203 \
param-name=allowed-VBD-devices 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15

 

4. Add the CD to the VM. Use the VM UUID from step 1, the CD name from step 2 and the VBD device number from step 3.

[ [email protected] ~/bin ] xe vm-cd-add uuid=cefb9f88-0424-6701-5ba1-070490c69203 \
device=5 cd-name=CentOS-6.3-x86_64-LiveCD.iso

 

5. Verify using xe vm-cd-list

 By using xe vm-cd-list we can list the CD's currently plugged into our VM.

 

[ [email protected] ~/bin ] xe vm-cd-list uuid=cefb9f88-0424-6701-5ba1-070490c69203 
CD 0 VBD:
uuid ( RO)             : 40f6b5c9-14fd-4379-d82c-d0ff34472a04
    vm-name-label ( RO): 955300270
            empty ( RO): false
       userdevice ( RW): 5


CD 0 VDI:
uuid ( RO)             : 0549c68a-e38d-4cd8-9974-ba0b9167ff5a
       name-label ( RW): CentOS-6.3-x86_64-LiveCD.iso
    sr-name-label ( RO): NFS ISO
     virtual-size ( RO): 725614592

 

6. Unplugging the CD disk

When done with the CD you can unplug it even easier. We specify the VM UUID and tell it to eject the CD which it does. 

 

 [ [email protected] ~/bin ] xe vm-cd-eject uuid=cefb9f88-0424-6701-5ba1-070490c69203

 

Add a comment

Create an LVM CD repository

 Prerequisites 

  • XCP/Xenserver

 Utilizing an ISO image in a VM's cdrom drive is fairly easy to do but because of the limited size of the Control Domain's (dom0) operating system partition it's difficult to download ISO images to /opt/xensource/packages/iso and it isn't really recommended to put them there anyway. In this tutorial we'll create a CD repository using an local Logical Volume.

First we need to know the name of the LVM Volume Group. This is taken from the Storage Repository's UUID. To get this we'll use xe host-list. 

[[email protected] ~]# xe sr-list type=lvm
uuid ( RO)                : 36bf480a-5df9-4453-50f0-2bac4a86cb42
          name-label ( RW): localsr-cloud1
    name-description ( RW): 
                host ( RO): cloud1.acs.edcc.edu
                type ( RO): lvm
        content-type ( RO): user

Using xe sr-list type=lvm shows only our local Storage Repository which has the UUID of 36bf480a-5df9-4453-50f0-2bac4a86cb42. We'll now use the vgs command to give us the names of all Volume Groups including VG_XenStorage-36bf480a-5df9-4453-50f0-2bac4a86cb42 which matches our SR UUID.

Add a comment

Read more: Create an LVM CD repository

Create an EXT CD repository

 Prerequisites 

  • XCP/Xenserver

 Utilizing an ISO image in a VM's cdrom drive is fairly easy to do but because of the limited size of the Control Domain's (dom0) operating system partition it's difficult to download ISO images to /opt/xensource/packages/iso and it isn't really recommended to put them there anyway. In this tutorial we'll create a CD repository using an additional hard drive on Dom0.

First we need to know the device name of the disk. 

[[email protected] media]# cat /proc/partitions 
major minor  #blocks  name
   8        0  976762584 sda
   8        1    4194304 sda1
   8        2    4194304 sda2
   8        3  968371393 sda3
   8       16  234431064 sdb
Add a comment

Read more: Create an EXT CD repository

Create an NFS CD repository

 Prerequisites 

  • XCP/Xenserver

 Utilizing an ISO image in a VM's cdrom drive is fairly easy to do but because of the limited size of the Control Domain's (dom0) operating system partition it's difficult to download ISO images to /opt/xensource/packages/iso and it isn't really recommended to put them there anyway. In this tutorial we'll create a CD repository using an NFS share.

In our example we'll be using a share on the cloud0 host named /media/NFSISO. To set this up on cloud0 you'd log into cloud0 as root and add this line to the /etc/exports file of your NFS server. 

 

/media/NFSISO/ *(rw)

 

I'd recommend that you secure your NFS share more tightly than I've done here but for the purpose of this tutorial we'll go with it. We need to make a directory that we can mount our NFS share on first.

Add a comment

Read more: Create an NFS CD repository

List XCP Host information

I've been working on ways of getting information to the XCP/Xenserver Admins eyes faster than the standard xe commandline tool provides. This tool - lshosts is a rewrite of lshostvms.sh which showed each host and how many running VMs were on it, something I often would like to know. While rewriting it to include some of the better structure of my newer tools I started adding features. Now it displays either the Host's name-label or UUID, the number of running VMs, the CPU type, CPU cores, CPU speed, Total Memory, Free Memory and Network backend type. 

As an added bonus I've added a -c option so the output is in CSV format. All future commands should have this option and I'll be retrofitting older commands when I get time.

Download it from the XCP Downloads section. http://grantmcwilliams.com/tech/virtualization/downloads/category/4-xen-cloud-platform

Add a comment

Reboot stuck VMs

Prerequisites

  • XCP/Xenserver

 

Sometimes I get a stuck Virtual Machine that just won't go down and it's usually due to a lack of memory in the VM. When I issue a shutdown command from within the VM it starts the shutdown process but hangs part way through. Executing xe vm-shutdown --force uuid=<insert UUID here>  does nothing but lock up the terminal. If this happens to you follow the steps below to forcefully shut the VM down.  

  1. xe task-list (find the pending tasks UUID)
  2. xe task-cancel uuid=<task UUID>
  3. xe vm-list (note the VM's UUID)
  4. list_domains (find the VM's UUID and note the domain id)
  5. /opt/xensource/debug/destroy_domain -domid XX (where XX is the domain id from step 2)
  6. xe vm-shutdown --force uuid=<UUID from step 1>
This will canceling the tasks that may be locking any new tasks e.g. the shutdown commands, destroying the domain and then shutting the VM down. I've had to do this several times on an Apache webserver that's getting pummeled from the Internet. 
 

The steps above in script form (if you trust me). Step one has to be entered in manually. The rest can be copied and pasted.

name="Name Label"
TASK=$(xe task-list status=pending --minimal)
xe task-cancel uuid="$TASK"
VMUUID=$(xe vm-list name-label="$name" --minimal)
DOMID=$(xe vm-list uuid="$VMUUID" params=dom-id --minimal) /opt/xensource/debug/destroy_domain -domid "$DOMID" xe vm-shutdown --force uuid="$VMUUID"

 

 

 

 

 

 

Add a comment

Tool to list XCP/Xenserver networks

My newest XCP tool is to list networks in a quick concise manner. By default lsnetworks shows the network name, the bridge it's associated with, the VLAN tag (if there is one), the VMs that have a network interface on it and the number of that interface. 

It can be found in the xenapi-admin-tools github.

 

 

 

Because XCP/Xenserver relies so much on UUID numbers I've provided a -u option which lists every object by UUID number if it has one. This won't be quite as useful as an interactive tool but if you're copy and pasting UUID's into xe commands this will give you a quick summary of them in relation to networks. 

 

Add a comment

A disk free command for Xen Cloud Platform

XCP and Xenserver store their Virtual Disk Images on storage repository. To see how much space you have on your LVM or lvmoisci storage repositories from the commandline can be quite a chore so I wrote a df command for storage repositories. My dfsr command mimics the output of the Linux df command with the human readable flag set (-h). All values will be printed in Kilobytes, Megabytes, Gigabytes and so on. It shows the size of the repository, how much is used, how much is available, the percent used and the Storage Repository type. 

 Get it from my Virtualization downloads section.

 

 

 

 

 

 

 

Add a comment

Cleaning up XCP's xe command with BASH

I've mentioned before that XCP/Xenserver's xe command is great for scripting but not always that great for interactive use. Because XCP relies so much on using UUID's for identification it's not very human friendly. Also the xe help is quite bad leading to our team that's working on writing documentation for xe. Even so xe makes a great scripting tool. 

To show the difference between xe's output and what I think it could be let me introduce my lstemplate.sh script available in the XCP Downloads Section of this website. The xe command has a tendency to show output on multiple lines which isn't very parsable and is sort of hard to read. I understand that it's easier to program though. I however, like as much info on one line as possible allowing me to send the output into awk/cut if I wish and also keeps formatting clean. 

Below is the output from xe template-list 

  ....

You can see the output doesn't wrap well and isn't that easy to read. My biggest irritation is trying to find the template for the OS I want to use. There are a lot of templates and I usually end up scrolling for quite some time to get the right one. My other choice is to pipe the output of xe template-list into grep -B1 to search for the name and print the line before the name-label which will show the UUID number. For instance xe template-list | grep -B1 'Red Hat'. As easy as that is I find myself scanning the output of xe template-list in order to know what to grep for which defeats the purpose of grepping. 

To solve this I wrote a small script called lstemplate.sh (list template). Below is the output. 

 

You can also pass a -v (verbose) flag to get the descriptions too. 

 

 

Add a comment

New XCP tools

As I and the team are writing manpages for XCP's xe command and it's 361 sub commands I'm writing more XCP tools. Last night I hacked out lshostvms.sh and xcptop.sh.

The lshostvms.sh script gives a quick list of hosts and shows numerically how many VMs are currently running on each. This includes the Control Domain itself currently  but I may change that in the future.

 

 

 

 

 

 

 

 The xcptop.sh script gives a list of all hosts and for each CPU core shows the utilisation according to XCP. 

 

Add a comment