Aussie owned and operated, with 23+ years of industry experience, Gold Coast InfoTech is delighted to support all of your business technology requirements.

Gallery

Contacts

success@goldcoastinfotech.com.au

1800 291 071

KBArticles

XenServer Mount USB from HOST

Situation: USB Drive attached to the XenServer host, need to mount directly into a VM for removable usb drive access.

Solution: Download the usbmount.bat from http://support.citrix.com/article/CTX118198

Edit the file with your xenserver details  and your vm and usb uuid’s.

HOW DO I FIND MY XENSERVER VM UUID?

bring up a console session on the XenServer and run

xe vm-list

HOW DO I FIND MY XENSERVER USB UUID?

the citrix provided command for listing Removable storage didn’t return any results in my setup.

xe sr-list name-label=Removable Storage

So under the XenServer Console > Click the Removable storage node in the console > Right click and copy the UUID Displayed

 

RUNNING THE SCRIPT

Edit the below script with your details

then run

usbmount.bat ATTACH

or

usbmount DETACH

—————————————————————————————–START SCRIPT —————————————————————————————————-

@ECHO OFF
setlocal
REM Attach a USB flash device to a specified VM on XenServer 4.x

REM ————- EDIT THE OPTIONS BELOW TO SUIT YOUR ENVIRONMENT ————-

REM XenServer Credentials
SET XE_USERNAME=root
SET XE_PASSWORD=CHANGEME
SET XE_SERVER=xxx.xxx.xxx.xxx

REM Removable Storage Repository UUID
SET REMOVABLE_SR_UUID=CHANGEME

REM UUID of the VM you wish to attach the USB storage to
SET VM_UUID=CHANGEME

REM Device name/order on the VM (e.g. hdb, hdc, hdd…)
set DEVICE_NAME=hdb

REM —————————————————————————

REM XenCenter Path
SET XE_CENTER_PATH=C:program filescitrixXenCenter

REM XE Binary and Baseline Parameters
SET XE_EXEC=”%XE_CENTER_PATH%xe.exe” -s %XE_SERVER% -u %XE_USERNAME% -pw %XE_PASSWORD%

REM Temporary working file
SET TEMP_FILE=%TEMP%/xs-usbmount.tmp

REM ———— DO NOT EDIT BEYOND THIS LINE —————-

IF “%1″==”ATTACH” GOTO ATTACH_STORAGE
IF “%1″==”DETACH” GOTO DETACH_STORAGE

REM No parameters
echo Usage USBMOUNT.BAT ^<ATTACH ^| DETACH^>
GOTO END

:DETACH_STORAGE
%XE_EXEC% vdi-list sr-uuid=%REMOVABLE_SR_UUID% params=vbd-uuids –minimal > %TEMP_FILE%
SET /P VBD_UUIDS= < %TEMP_FILE%

IF “%VBD_UUIDS%”==”” GOTO NOT_BOUND
%XE_EXEC% vbd-unplug uuid=%VBD_UUIDS%
%XE_EXEC% vbd-destroy uuid=%VBD_UUIDS%
echo.Storage Detached

GOTO END

:ATTACH_STORAGE

REM See if the storage is already bound to a VBD
%XE_EXEC% vdi-list sr-uuid=%REMOVABLE_SR_UUID% params=vbd-uuids –minimal > %TEMP_FILE%
SET /P VBD_UUIDS= < %TEMP_FILE%

IF NOT “%VBD_UUIDS%”==”” GOTO ALREADY_BOUND

%XE_EXEC% vdi-list sr-uuid=%REMOVABLE_SR_UUID% params=uuid –minimal > %TEMP_FILE%
SET /P VDI_UUID= < %TEMP_FILE%

%XE_EXEC% vbd-create vm-uuid=%VM_UUID% device=%DEVICE_NAME% vdi-uuid=%VDI_UUID% –minimal > %TEMP_FILE%
SET /P VBD_UUID= < %TEMP_FILE%

%XE_EXEC% vbd-plug uuid=%VBD_UUID%

echo.VBD UUID attached as: %VBD_UUID%
GOTO END

:ALREADY_BOUND
echo.Removable storage already attached to a VM – aborting.
GOTO END

:NOT_BOUND
echo.Storage device not bound to any VMs – aborting.
GOTO END

:END
endlocal

Author

Customer

Comments (2)

  1. tom
    21 August 2012

    Perhaps the command “xe sr-list name-label=Removable Storage” didn’t return anything because “storage” should be lower case

    • scanjam
      5 September 2012

      nice one! cheers!

Leave a comment

Your email address will not be published. Required fields are marked *