-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqemu-img.vmdk3.hack.sh
executable file
·50 lines (47 loc) · 2.05 KB
/
qemu-img.vmdk3.hack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Why?
#
# smite@desktop03:~/dev/puppet/manifests> vagrant mutate ubuntu-64-x64-vbox4210-nocm libvirt
# Converting ubuntu-64-x64-vbox4210-nocm from virtualbox to libvirt.
# qemu-img: 'image' uses a vmdk feature which is not supported by this qemu version: VMDK version 3
# qemu-img: Could not open '/home/smite/.vagrant.d/boxes/ubuntu-64-x64-vbox4210-nocm/virtualbox/box-disk1.vmdk': Wrong medium type
# Determining the virtual size of the disk image failed
#
# Bah! Humbug!
#
# smite@desktop03:~/dev/puppet/manifests> ~/dev/one-liners/qemu-img.vmdk3.hack.sh /home/smite/.vagrant.d/boxes/ubuntu-64-x64-vbox4210-nocm/virtualbox/box-disk1.vmdk
# /home/smite/.vagrant.d/boxes/ubuntu-64-x64-vbox4210-nocm/virtualbox/box-disk1.vmdk is VMDK3.
# Patching to VMDK2.
# Run this script again when you're done to patch it back.
#
# For realz?
#
# smite@desktop03:~/dev/puppet/manifests> vagrant mutate ubuntu-64-x64-vbox4210-nocm libvirt
# Converting ubuntu-64-x64-vbox4210-nocm from virtualbox to libvirt.
# (98.57/100%)
# The box ubuntu-64-x64-vbox4210-nocm (libvirt) is now ready to use.
#
# Fo' realz!
#
# smite@desktop03:~/dev/puppet/manifests> ~/dev/one-liners/qemu-img.vmdk3.hack.sh /home/smite/.vagrant.d/boxes/ubuntu-64-x64-vbox4210-nocm/virtualbox/box-disk1.vmdk
# File is VMDK2. Patching to VMDK3.
# smite@desktop03:~/dev/puppet/manifests>
#
# Thank you, come again!
VMDK=$1
FULLSIZE=`stat -c%s "$VMDK"`
VMDKFOOTER=$[$FULLSIZE - 0x400]
VMDKFOOTERVER=$[$VMDKFOOTER + 4]
case "`xxd -ps -s $VMDKFOOTERVER -l 1 \"$VMDK\"`" in
03)
echo -e "$VMDK is VMDK3.\n Patching to VMDK2.\n Run this script again when you're done to patch it back."
echo -en '\x02' | dd conv=notrunc oflag=seek_bytes seek=$[VMDKFOOTERVER] of="$VMDK" 2> /dev/null || echo 'Patching failed'
;;
02)
echo "File is VMDK2. Patching to VMDK3."
echo -en '\x03' | dd conv=notrunc oflag=seek_bytes seek=$[VMDKFOOTERVER] of="$VMDK" 2> /dev/null || echo 'Patching failed'
;;
*) # default
echo "$VMDK is not VMDK3 or patched-VMDK3."
;;
esac