From 83f8b1abce4962334b1776e2896f57e8cf8efee1 Mon Sep 17 00:00:00 2001 From: Renuka Apte Date: Mon, 2 Apr 2012 15:45:27 -0700 Subject: [PATCH] XenServer: Add script to mount OS domU in dom0 Change-Id: I1ad3d63c55b95f2588007c5e88704022f54e1c06 --- tools/xen/scripts/manage-vdi | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 tools/xen/scripts/manage-vdi diff --git a/tools/xen/scripts/manage-vdi b/tools/xen/scripts/manage-vdi new file mode 100755 index 0000000000..a0a27e8a8f --- /dev/null +++ b/tools/xen/scripts/manage-vdi @@ -0,0 +1,52 @@ +#!/bin/bash + +set -eux + +action="$1" +vm="$2" +device="${3-0}" +part="${4-}" + +xe_min() +{ + local cmd="$1" + shift + xe "$cmd" --minimal "$@" +} + +vm_uuid=$(xe_min vm-list name-label="$vm") +vdi_uuid=$(xe_min vbd-list params=vdi-uuid vm-uuid="$vm_uuid" \ + userdevice="$device") + +dom0_uuid=$(xe_min vm-list is-control-domain=true) + +open_vdi() +{ + vbd_uuid=$(xe vbd-create vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid" \ + device=autodetect) + mp=$(mktemp -d) + xe vbd-plug uuid="$vbd_uuid" + + udevsettle + dev=$(xe_min vbd-list params=device uuid="$vbd_uuid") + mount "/dev/$dev$part" "$mp" + echo "Your vdi is mounted at $mp" +} + +close_vdi() +{ + vbd_uuid=$(xe_min vbd-list vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid") + dev=$(xe_min vbd-list params=device uuid="$vbd_uuid") + umount "/dev/$dev$part" + + xe vbd-unplug uuid=$vbd_uuid + xe vbd-destroy uuid=$vbd_uuid +} + +if [ "$action" == "open" ] +then + open_vdi +elif [ "$action" == "close" ] +then + close_vdi +fi