﻿{"id":33,"date":"2012-03-20T13:58:54","date_gmt":"2012-03-20T16:58:54","guid":{"rendered":"http:\/\/binsfeld.com.br\/wp\/?p=33"},"modified":"2012-04-01T16:50:59","modified_gmt":"2012-04-01T19:50:59","slug":"script-attach-usb-storage-no-xenserver","status":"publish","type":"post","link":"http:\/\/binsfeld.com.br\/wp\/?p=33","title":{"rendered":"Script ATTACH USB STORAGE no Xenserver"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\">Modify the usbmount.bat script<\/span><\/p>\n<p>1. Using a text editor such as Notepad, edit the usbmount.bat script according to your requirements. The following attributes must be set:<\/p>\n<p>2. Set the username, password and address (IP or hostname) of your XenServer host:<\/p>\n<p>SET XE_USERNAME=root<br \/>\nSET XE_PASSWORD=CHANGEME<br \/>\nSET XE_SERVER=xxx.xxx.xxx.xxx<\/p>\n<p>3. Determine the universally unique identifier (UUID) of the Storage Repository that corresponds with the Removable Storage. You can determine this by running the following command from within your XenServer host console:<\/p>\n<p><strong>xe sr-list name-label=Removable\\ Storage<\/strong><\/p>\n<p>4. Once you have the UUID of the Removable Storage, make the change to the script:<\/p>\n<p>REM Removable Storage Repository UUID<\/p>\n<p>SET REMOVABLE_SR_UUID=CHANGEME<\/p>\n<p>5. Determine the UUID of the virtual machine (VM) you wish to attach the storage to. To do this, run:<\/p>\n<p><strong>xe vm-list<\/strong><\/p>\n<p>6. With the UUID of the VM, make the change to the script:<\/p>\n<p>REM UUID of the VM you wish to attach the USB storage to<\/p>\n<p>SET VM_UUID=CHANGEME<\/p>\n<p>7. Set the device order. It is important to ensure that there is no overlap and this is done by looking at the number of devices attached to the VM. For example, if only one storage device is currently being used (example: virtual hard disk), the next device name to use will be hdb.<\/p>\n<p>REM Device name\/order on the VM (example: hdb, hdc, hdd&#8230;)<\/p>\n<p>SET DEVICE_NAME=hdb<\/p>\n<p>8. Run or Schedule the Batch Program<\/p>\n<p>9. Once you have made the changes to the batch program, test it by running it from a Command Prompt window. Note that the utility requires a parameter, otherwise it exits.<\/p>\n<p>10. To attach the USB storage device to the VM, run:<\/p>\n<p><strong>usbmount.bat ATTACH<\/strong><\/p>\n<p>11. To detach the USB storage device from the VM, run:<\/p>\n<p><strong>usbmount.bat DETACH<\/strong><\/p>\n<p><strong>Listing of USBMOUNT.BAT<\/strong><\/p>\n<p>@ECHO OFF<br \/>\nsetlocal<br \/>\nREM Attach a USB flash device to a specified VM on XenServer 4.x<\/p>\n<p>REM &#8212;&#8212;&#8212;&#8212;- EDIT THE OPTIONS BELOW TO SUIT YOUR ENVIRONMENT &#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>REM XenServer Credentials<br \/>\nSET XE_USERNAME=root<br \/>\nSET XE_PASSWORD=CHANGEME<br \/>\nSET XE_SERVER=xxx.xxx.xxx.xxx<\/p>\n<p>REM Removable Storage Repository UUID<br \/>\nSET REMOVABLE_SR_UUID=CHANGEME<\/p>\n<p>REM UUID of the VM you wish to attach the USB storage to<br \/>\nSET VM_UUID=CHANGEME<\/p>\n<p>REM Device name\/order on the VM (e.g. hdb, hdc, hdd&#8230;)<br \/>\nset DEVICE_NAME=hdb<\/p>\n<p>REM &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>REM XenCenter Path<br \/>\nSET XE_CENTER_PATH=C:\\program files\\citrix\\XenCenter\\<\/p>\n<p>REM XE Binary and Baseline Parameters<br \/>\nSET XE_EXEC=&#8221;%XE_CENTER_PATH%\\xe.exe&#8221; -s %XE_SERVER% -u %XE_USERNAME% -pw %XE_PASSWORD%<\/p>\n<p>REM Temporary working file<br \/>\nSET TEMP_FILE=%TEMP%\/xs-usbmount.tmp<\/p>\n<p>REM &#8212;&#8212;&#8212;&#8212; DO NOT EDIT BEYOND THIS LINE &#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>IF &#8220;%1&#8243;==&#8221;ATTACH&#8221; GOTO ATTACH_STORAGE<br \/>\nIF &#8220;%1&#8243;==&#8221;DETACH&#8221; GOTO DETACH_STORAGE<\/p>\n<p>REM No parameters<br \/>\necho Usage USBMOUNT.BAT ^&lt;ATTACH ^| DETACH^&gt;<br \/>\nGOTO END<\/p>\n<p>:DETACH_STORAGE<br \/>\n%XE_EXEC% vdi-list sr-uuid=%REMOVABLE_SR_UUID% params=vbd-uuids &#8211;minimal &gt; %TEMP_FILE%<br \/>\nSET \/P VBD_UUIDS= &lt; %TEMP_FILE%<\/p>\n<p>IF &#8220;%VBD_UUIDS%&#8221;==&#8221;&#8221; GOTO NOT_BOUND<br \/>\n%XE_EXEC% vbd-unplug uuid=%VBD_UUIDS%<br \/>\n%XE_EXEC% vbd-destroy uuid=%VBD_UUIDS%<br \/>\necho.Storage Detached<\/p>\n<p>GOTO END<\/p>\n<p>:ATTACH_STORAGE<\/p>\n<p>REM See if the storage is already bound to a VBD<br \/>\n%XE_EXEC% vdi-list sr-uuid=%REMOVABLE_SR_UUID% params=vbd-uuids &#8211;minimal &gt; %TEMP_FILE%<br \/>\nSET \/P VBD_UUIDS= &lt; %TEMP_FILE%<\/p>\n<p>IF NOT &#8220;%VBD_UUIDS%&#8221;==&#8221;&#8221; GOTO ALREADY_BOUND<\/p>\n<p>%XE_EXEC% vdi-list sr-uuid=%REMOVABLE_SR_UUID% params=uuid &#8211;minimal &gt; %TEMP_FILE%<br \/>\nSET \/P VDI_UUID= &lt; %TEMP_FILE%<\/p>\n<p>%XE_EXEC% vbd-create vm-uuid=%VM_UUID% device=%DEVICE_NAME% vdi-uuid=%VDI_UUID% &#8211;minimal &gt; %TEMP_FILE%<br \/>\nSET \/P VBD_UUID= &lt; %TEMP_FILE%<\/p>\n<p>%XE_EXEC% vbd-plug uuid=%VBD_UUID%<\/p>\n<p>echo.VBD UUID attached as: %VBD_UUID%<br \/>\nGOTO END<\/p>\n<p>:ALREADY_BOUND<br \/>\necho.Removable storage already attached to a VM &#8211; aborting.<br \/>\nGOTO END<\/p>\n<p>:NOT_BOUND<br \/>\necho.Storage device not bound to any VMs &#8211; aborting.<br \/>\nGOTO END<\/p>\n<p>:END<br \/>\nendlocal<\/p>\n<p># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- #<\/p>\n<p>Script usbmount.sh<\/p>\n<p>#!\/bin\/bash<br \/>\nxe vbd-create vm-uuid=c145b8f0-7c3d-9208-c219-14cbec468911 device=autodetect vdi-uuid=146a5021-77a5-44b6-bcaa-edc5a1d4c822 &gt; \/marlo\/vbduuid<br \/>\nvbduuid=$(cat \/marlo\/vbduuid)<br \/>\nxe vbd-plug uuid=$vbduuid<\/p>\n<p># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- #<\/p>\n<p>Cr\u00e9dito :\u00a0<a href=\"http:\/\/support.citrix.com\/article\/CTX118198\">http:\/\/support.citrix.com\/article\/CTX118198<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modify the usbmount.bat script 1. Using a text editor such as Notepad, edit the usbmount.bat script according to your requirements. The following attributes must be set: 2. Set the username,<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-virtualizacao"],"_links":{"self":[{"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=\/wp\/v2\/posts\/33"}],"collection":[{"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=33"}],"version-history":[{"count":2,"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"predecessor-version":[{"id":41,"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions\/41"}],"wp:attachment":[{"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/binsfeld.com.br\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}