Syndicate content

Copy files between a guest (virtualbox) and the host

I use VirtualBox and had a problem with copying files between my host (main computer on which you boot your computer) and the guests (virtual computer that you run on your host).

The fact is that it is all explained right here:

http://www.virtualbox.org/manual/ch04.html#sharedfolders

There are a few steps as follow.

Install the Virtual Box Tools

Install the Virtual Box Tools (called Guest Additions) on your guest; these tools allow your guest to communicate with the host to allow files to be written in a directory on the host.

To install those, it should be as easy as using the Install Guest Additions... menu option (under Devices). That auto-mounts an .iso and autoexec's whatever needs to be done. However, it does not always work right. For example, if you already have a CDROM in your virtual machine, it won't be able to load another CD in there. Might have to reboot to remove the existing CD and get the additions CD inserted with that menu option.

Also, the autorun.sh script may fail. In that case use df to find your CD path and look into it. Just try to run the autorun.sh by hand or whatever installation command with whatever package there is on the CD. For Solaris I ran the following:

pkgadd /media/VBOXADDITIONS-<version>/VBoxSolarisAdditions.pkg

From the Command Line

Installing the additional features has not been working right with the menu. It seems that the menu option assumes that you are running X11 when I generally don't want to install the whole X11 for a tiny super simple server. So this requires you to do the installation manually.

In Ubuntu 14.04, I ended up having to install the additions from the Ubuntu servers with apt-get:

sudo apt-get install virtualbox-guest-additions-iso

This installs the ISO that you can then mount with:

sudo mount /usr/share/virtualbox/VBoxGuestAdditions.iso /media/cdrom

Before running the installation script, you may need to install some kernel tools (you'd think that the script can do it, and maybe it does, but that won't hurt much):

sudo apt-get install build-essential module-assistant

Now you can install the actual additions by running one of the scripts. Which one is mainly determine by the operating system you're running. For Linux:

sudo sh /media/cdrom/VBoxLinuxAdditions.run

That will take care of all the necessary installations so you can create shared folders.

Create Shared Folder

Create a shared folder (or several...) where you place your data that can be transferred both ways (unless you make the shared folder read only or give it an owner / group such that you cannot write to the directory!?)

To do that, use the menu entry "Shared Folders ..." from the Devices menu. There you should be able to create the shared folders without too much trouble. That should also work when you tweak the settings of your guest.

Mounting the Shared Folder

Once you have these two things, you are ready to mount the partition. The mount instruction changes depending on the guest you are running. Note that this is specific to the guest, not the other way around. That is, you can mount the host directory on the guest. Got it? If your main computer runs Linux and your guest is Windows, then you add a drive with:

net use x: \\vboxsvr\sharename

from your Windows virtual computer.

Similarly, from your Guest Linux, use mount as in:

mount -t vboxsf [-o OPTIONS] sharename mountpoint

The Solaris mount command is the same, only it uses -F instead of -t:

mount -F vboxsf [-o OPTIONS] sharename mountpoint

Note that all those features, installing the the Virtual Box Additions, creating a shared folder, mounting, are availabe via the command line. I just did not try those but if you need to script all of that, it's possible.

Mount not working...

At least in version 14.04 of Ubuntu, the guest additions place the mount.vboxsf in a new place. This causes problems when trying to mount a shared folder. You will have to fix the soft link found in /usr/lib to the new location:

sudo rm /usr/lib/VBoxGuestAdditions
sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

The mount may not be the old thing that has problems, but that's what many people bump into.

Common error when the mount fails:

mount: wrong fs type, bad option, bad superblock on /mnt/path,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

Source: https://forums.virtualbox.org/viewtopic.php?f=3&t=60921

Copying Files

Assuming you create a directory on your host (main computer) named /mnt/solaris and you mounted that as /mnt/host on your Solaris guest, you can copy files with:

# On the host
cp ~/my-file.txt /mnt/solaris

# On the guest
cp ~/this-other-file.txt /mnt/host

Here I show how to copy from the host to the guest, and from the guest to the host. The copy works both ways as long as you create a read/write shared folder.

Note that by default a directory such as /mnt/solaris is likely going to be read-only for most users. You probably will want to use a directory under your home directory or change the owner/group of the /nmt/solaris directory.

The /mnt/host on the guest system has no bearing on the permission to read or write files. It is just a mount point.

Ultra Confused While Running

While running, a shared folder name cannot really be changed. You may create it, then mount it, and then it is pretty much like a read-only information.

I tried to even delete all the shared folders, re-creating a new one, and then rebooting, the wrong path is still used!

To fix such problems, turn off your virtual box, enter the settings, click on Shared Folder (last option at this time) and fix your shared folders there. Once done, reboot your virtual box and all should work like a charm.

 
Syndicate content

Diverse Realty

Diverse Realty Team

Want a New Home?
Want to Sell Your House?

Call Alex at
+1 (916)
220 6482

Alexis Wilke, Realtor
Salesperson
Lic. # 02024063

Cory Marcus, Broker
Lic. # 01079165

     

Terms of Site Index

Find the page/content you are looking for with our index.