Browse code

XenServer: Add script to mount OS domU in dom0

Change-Id: I1ad3d63c55b95f2588007c5e88704022f54e1c06

Renuka Apte authored on 2012/04/03 07:45:27
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,52 @@
0
+#!/bin/bash
1
+
2
+set -eux
3
+
4
+action="$1"
5
+vm="$2"
6
+device="${3-0}"
7
+part="${4-}"
8
+
9
+xe_min()
10
+{
11
+  local cmd="$1"
12
+  shift
13
+  xe "$cmd" --minimal "$@"
14
+}
15
+
16
+vm_uuid=$(xe_min vm-list name-label="$vm")
17
+vdi_uuid=$(xe_min vbd-list params=vdi-uuid vm-uuid="$vm_uuid" \
18
+                           userdevice="$device")
19
+
20
+dom0_uuid=$(xe_min vm-list is-control-domain=true)
21
+
22
+open_vdi()
23
+{
24
+  vbd_uuid=$(xe vbd-create vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid" \
25
+                         device=autodetect)
26
+  mp=$(mktemp -d)
27
+  xe vbd-plug uuid="$vbd_uuid"
28
+
29
+  udevsettle
30
+  dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
31
+  mount "/dev/$dev$part" "$mp"
32
+  echo "Your vdi is mounted at $mp"
33
+}
34
+
35
+close_vdi()
36
+{
37
+  vbd_uuid=$(xe_min vbd-list vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid")
38
+  dev=$(xe_min vbd-list params=device uuid="$vbd_uuid")
39
+  umount "/dev/$dev$part"
40
+
41
+  xe vbd-unplug uuid=$vbd_uuid
42
+  xe vbd-destroy uuid=$vbd_uuid
43
+}
44
+
45
+if [ "$action" == "open" ]
46
+then
47
+  open_vdi
48
+elif [ "$action" == "close" ]
49
+then
50
+  close_vdi
51
+fi