Xen hypervisor: Assign Virtual Disk to a Virtual Machine

Dealing with  our daily admin tasks we face lot of requests where we need to assign virtual disks or additional disks to Virtual Machines running on Xen hypervisor .

Xen hypervisor have lot of “xm” commands that can be used to manage the functionality  of Xen VM’s .

As we know that we can use xm block-attach commands to attach a new virtual disks to Xen VM .We have similar situation  here ,we need to add new disk via SAN storage to add on a VM ( either new disk or we can also use that virtual disk to append to existing filesystem via vgextend / resize2fs / lvextend)

Prerequisites : If you want to add disks via SAN storage LUN’s , Make sure the Xen hypervisor have SAN switch connections  and  HBA’s attached to them . You can check HBA via below command .

# lspci | grep -i HBA  

Above Command will list the Model and type of HBA on the system . Also , multipath package should be installed which give a configuration file multipath.conf and multipath service should be up and running.

# chkconfig multipathd on

# /etc/init.d/multipathd start

Method :

Below steps shows how we can scan and get the LUN’s listed in Xen hypervisor  .

Step:1  To Request a SAN LUN’s you have to provide wwpn numbers of the HBA attached to the system  Those WWPN for HBA are used to zone the storage with hostname .

To get details about he wwpn’s :

 #  cat /sys/class/fc_host/host?/port_name    (  where “?” is the port number of HBA )

Step:2 Once SAN LUN’s provisoned , use below commands to scan those on Xen hypervisor :

echo “- – -” > /sys/class/scsi_host/host0/scan

echo “- – -” > /sys/class/scsi_host/host1/scan

echo “- – -” > /sys/class/scsi_host/host2/scan

Step:3 Once the scan complete ( takes few sec only ) , the LUN’s get listed using  below command :

# multipath -ll 

This will list the newly assigned LUN’s as well as existing LUN’s if any .

Note: To set the LUN’s naming according to our  requirements we can edit multipath.conf file .

Then again reload multipath service : “/etc/init.d/multipathd reload“. This command will list the LUN’s names with new naming provided and also get those listed under /dev/mapper with new names .

Step:4  Now we need to attach the LUN’s to VM domain name :

Find out the VM name and domain id using below command :

# xm list

Choose the domain id and replace below domain-name with the one you choosed

# xm block-attach domain-name/Virtualmachinename   phy:/dev/mapper/lun_name  xvde w

where :  xvd<?>  is the available disk numbering .

Step:5  Once the above command run , append entries in VM conf file so that it will be persistent  on VM reboots .


Till now we worked on Xen hypervisior , now we have to login to virtual machine to see if the “dmesg” and “/var/log/messages” got the new disk entry .

 Check new disk with fdisk -l and Follow below steps :

1 )   Create partition  to newly attached virtual disk and format this with either ext3 or ext4 as per requirements  .

# fdisk /dev/xvde      //  ( Make partition 1 , like /dev/xvde1 )

Now , format the disk as :   mkfs.ext3  /dev/xvde1

2) Once format complete , put entry in fstab to mount the new drive or You can make this a part of existing LVM paritions , just do pvcreate , vgextend and then  resize2fs followed by lvextend command .

Please feel free to write comments to this post if you have queries and also add if any suggestions.

Leave a Comment