Created
July 31, 2012 17:11
-
-
Save n00bsys0p/3218617 to your computer and use it in GitHub Desktop.
Script to convert a VirtualBox VDI to RAW disk image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LODEV=$(sudo losetup -f) | |
# The output file name | |
FNAME="diskimage" | |
# File extension for the vmdk copy | |
VMDKEXT="vmdk" | |
# File extension for the raw copy | |
RAWEXT="raw" | |
echo "Cleaning up old files" | |
[[ -f $FNAME.$RAWEXT ]] && rm $FNAME.$RAWEXT | |
VBoxManage list hdds | |
read -p "Enter the UUID of the VDI you want to convert: " VDIUUID | |
echo "Converting VDI to VMDK format." | |
VBoxManage clonehd $VDIUUID $FNAME.$VMDKEXT --format=VMDK | |
echo "Converting VMDK to RAW format." | |
qemu-img convert -f vmdk $FNAME.$VMDKEXT -O raw $FNAME.$RAWEXT | |
echo "Listing partitions and offsets in VDI." | |
parted $FNAME.$RAWEXT unit b print | |
read -p "Please provide the offset as required from above: " OFFSET | |
sudo losetup -o $OFFSET $LODEV $FNAME.$RAWEXT | |
# Remove the VMDK file, as it's not required any more | |
[[ -f $FNAME.$VMDKEXT ]] && rm $FNAME.$VMDKEXT | |
echo "$LODEV is now ready to mount the partition you require access to." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment