Skip to content

Commit 83f8b1a

Browse files
Renuka ApteDean Troyer
authored andcommitted
XenServer: Add script to mount OS domU in dom0
Change-Id: I1ad3d63c55b95f2588007c5e88704022f54e1c06
1 parent c0ae316 commit 83f8b1a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tools/xen/scripts/manage-vdi

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

0 commit comments

Comments
 (0)