Mount a VDI file and copy its content to a directory

Write tutorials and howtos in here
More tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please, Before you post please read this

Mount a VDI file and copy its content to a directory

Postby Schoelje on Sun Aug 05, 2012 3:05 pm

I've been working on an issue I had while working on the UP5 version of the unofficial LMDE KDE (viewtopic.php?f=61&t=106426).
I thought, and don't ask me why, that upgrading in Virtualbox and copying that to a directory on my hard drive would solve that issue...well, it worked but didn't solve that particular problem.

However, the script I made is perhaps something that might help somebody in the future so I'm going to share it here:

Code: Select all
#!/bin/bash
# ===================================================================
# Mount VirtualBox VDI and copy contents to directory
# Run as su
# Usage: copyvdi /path_to_vdi /path_to_destination_directory mounted_partition_nr
# mounted_partition_nr: default = 1
# ===================================================================

VDI1=/mnt/vdi1
VDI2=/mnt/vdi2

if [ `id -u` != "0" ]; then
   echo "This script must be run as root." 1>&2
   exit 1
fi

if [ -z $1 ]; then
   echo "Image file argument is missing." 1>&2
   exit 1
fi

if [ -z $2 ]; then
   echo "Destination directory argument is missing." 1>&2
   exit 1
fi

if [ -z $3 ]; then
   $3=1
fi

if [ -e $1 ]; then
   echo > /dev/null
else
   echo "Passed image file does not exist." 1>&2
   exit 1
fi

if [ -d $2 ]; then
   echo > /dev/null
else
   mkdir -p $2
fi

# First install virtualbox-fuse
FCHK=$(apt search virtualbox-fuse | grep ^i)
if [ "$FCHK" = "" ]; then
    apt-get install virtualbox-fuse
fi

# Create mount directories
if [ -d $VDI1 ]; then
   echo > /dev/null
else
   mkdir -p $VDI1
fi
if [ -d $VDI2 ]; then
   echo > /dev/null
else
   mkdir -p $VDI2
fi

# Mount the vdi
vdfuse -r -f $1 $VDI1
echo "Check if $VDI1 is mounted (ENTER to continue)"
read

#Mount the partition
# If you get a mount error here, try one of the other Partitions
mount $VDI1/Partition$3 $VDI2
echo "Check if $VDI2 is mounted (ENTER to continue)"
read

# Copy with rsync
rsync -avx $VDI2/ $2 --exclude={/tmp/*,/mnt/*,/lost+found/*,/home/*/.gvfs}

# When done
umount $VDI2 && umount $VDI1
rm -r $VDI2 && rm -r $VDI1

echo ""
echo "Done: $1 copied to $2"
echo "Press ENTER to quit"
read
User avatar
Schoelje
Level 5
Level 5
 
Posts: 791
Joined: Wed Jan 18, 2012 6:25 am
Location: Netherlands

Linux Mint is funded by ads and donations.
 

Re: Mount a VDI file and copy its content to a directory

Postby dhdurgee on Sat Sep 08, 2012 9:03 pm

I was looking at this as something I might want to use, but I have been using the oracle version of virtualbox, which is now at 4.1.22, and installing the fuse would downgrade the application several levels!

Who should be contacted about updating the fuse to the current virtualbox release?

Dave
dhdurgee
Level 4
Level 4
 
Posts: 215
Joined: Thu Jul 02, 2009 7:56 pm

Re: Mount a VDI file and copy its content to a directory

Postby Schoelje on Sun Sep 09, 2012 2:04 am

This script was intended to use with the packages from the testing repositories.
Both testing and unstable have version 4.1.18-dfsg-1 of virtualbox.
If you downloaded the latest from Oracle because you had problems with the above I cannot help you any further.
Otherwise, I recommend uninstalling the .22 version and use the version from the repositories.
User avatar
Schoelje
Level 5
Level 5
 
Posts: 791
Joined: Wed Jan 18, 2012 6:25 am
Location: Netherlands

Re: Mount a VDI file and copy its content to a directory

Postby dhdurgee on Mon Sep 10, 2012 4:34 pm

I was looking at using this as a way to access and confirm the content of one of my VDI W7 boot files. Given I am running the latest oracle version and have their extensions installed I would prefer not to fall back to an earlier level.

Looking at the thread over on the virtualbox web site it looks as if it might not be too hard to build it myself from source, but given I have such a limited interest in this I think I will simply download a mint iso that is bootable in the virtualbox and use that instead

Dave
dhdurgee
Level 4
Level 4
 
Posts: 215
Joined: Thu Jul 02, 2009 7:56 pm


Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 3 guests