Mount a VDI file and copy its content to a directory

Archived topics about LMDE 1 and LMDE 2
Locked
Schoelje

Mount a VDI file and copy its content to a directory

Post by Schoelje »

I've been working on an issue I had while working on the UP5 version of the unofficial LMDE KDE (http://forums.linuxmint.com/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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
dhdurgee
Level 4
Level 4
Posts: 433
Joined: Thu Jul 02, 2009 7:56 pm

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

Post by dhdurgee »

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
Schoelje

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

Post by Schoelje »

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.
dhdurgee
Level 4
Level 4
Posts: 433
Joined: Thu Jul 02, 2009 7:56 pm

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

Post by dhdurgee »

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
Locked

Return to “LMDE Archive”