Virtualbox linux shared folder path

Introduction

This explains how to share files and folders (directories) between host and guest. (Files are shared over a network, in other words, you access remote files. For virtual machines, the network between host and guest is virtual since they are on the same real machine. But the steps you take are similar to setting up file sharing over real networks.)

Required: Virtualbox Guest Additions

Before sharing folders, you must install Guest Additions. For instructions on how to do this, see Guest Additions.

Creating a shared folder

  • Create a folder on the Host computer (ubuntu) that you would like to share, for example ~/share
  • Boot the Guest operating system in VirtualBox.
  • Select Devices -> Shared Folders.
  • Choose the ‘Add’ button.
  • Select ~/share
  • Optionally select the ‘Make permanent’ option

Prepare the folder

Linux

With a shared folder named share, as above, the folder can be mounted as the directory ~/host with the command

sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) share ~/host

Windows

Now anything placed in this folder should be visible from the host in the ~/share folder.

Troubleshooting

This can be done more generically with the following:

sharename="whatever.you.want.to.call.it"; sudo mkdir /mnt/$sharename sudo chmod 777 /mnt/$sharename sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename ln -s /mnt/$sharename $HOME/Desktop/$sharename

For the above command if you get the following error:

mount: unknown filesystem type 'vboxsf'

Then just change the vboxsf to vboxfs

If you want to have it mount automatically upon each boot, put the mount command in /etc/rc.local Debian distros (e.g. Ubuntu 10.04 and later) HOWTO Use Shared Folders

See Section 4.4 «Folder Sharing» in the VirtualBox documentation.

Note: if you want to mount the directory as owned and writable only by root, omit the -o uid=1000,gid=1000 option to the mount command

/sbin/mount.vboxsf: mounting failed with the error: Protocol error

The above error could be one of the following.

The name was not valid

Make sure you specified the right name on the bash commands. If the guest machine is expecting «share» (as we did in the Prepare Host section) and you wrote

sharename="donotshare" sudo mkdir /mnt/$sharename sudo chmod 777 /mnt/$sharename sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename ln -s /mnt/$sharename $HOME/Desktop/$sharename

Ubuntu 10.04 host

Note: Running on Ubuntu 10.04 host and Mint 14 as virtual system, the system would not accept a ~/share. It complained that it was not an absolute address. I entered /home/jim/share and it worked fine.

  • Create a folder on the Host computer (ubuntu) that you would like to share, for example ~/share
  • Boot the Guest operating system in VirtualBox.
  • Select Devices -> Shared Folders.
  • Choose the ‘Add’ button.
  • Select ‘/home//share‘ for Folder Path
  • Select ‘share’ for Folder Name
  • Optionally select the ‘Make permanent’ option

VirtualBox/SharedFolders (последним исправлял пользователь dyn005202 2014-09-26 15:49:59)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Читайте также:  What is linux server version

Источник

How to mount a shared folder in VirtualBox

Feature image for the article about how to mount a shared folder in VirtualBox

Ever needed to access a file inside your virtual machine, which resides on your host operating system? With the help of VirtualBox’s shared folders feature, you can select a folder on your host OS to share. Inside your VirtualBox virtual machine you can then mount this shared folder. Once configured, you can easily exchange files between the host and guest OS. In this article you’ll learn how to configure and mount a shared folder on your Linux based VirtualBox virtual machine.

Background

VirtualBox comes with a feature called shared folders. As the name implies, a shared folder enables file sharing between the host and the guest operating systems. With the host operating system I mean the operating system, where you installed the VirtualBox program itself. The guest operating system is the one you run inside a VirtualBox virtual machine.

Illustration that visually explains what a VirtualBox shared folder is.

When you work with virtual machines, sooner or later you run into a situation where a file resides on the host OS and you want to access it on the guest OS, or the other way around. Some example scenarios:

  • While trying out a new Linux distribution in a virtual machine, you want to configure the desktop environment the exact same way as on your host OS. This includes the background image. Through the use of a shared folder, you can quickly copy the background image to the guest OS.
  • You took a few screenshots inside a guest OS. You want to insert these screenshot images in a document you are writing on your host OS. With the help of the shared folder, you can easily copy the screenshot image files to your host OS.
  • You cloned one of your GitHub repositories inside your guest OS. After fixing or improving some code, you want to push the changes back to the remote repository. You need the correct SSH keys on the guest OS, for write access to your GitHub repository. Thanks to the shared folder feature, you can simply copy the SSH keys from your host OS to your guest OS.

This article shows you step-by-step how to configure and mount a shared folder for your Linux based guest OS, running as a VirtualBox virtual machine.

Shared folder alternatives

What if you do not want to use shared folders? In this case you can can use alternative methods for exchanging files:

Exchange files with a USB Stick

With VirtualBox you can access a USB stick, inserted into the host OS, on the guest OS. This article provides details on how to manually mount a USB stick from the terminal. To virtually insert the USB stick into the guest OS, right-click the little USB icon on your virtual machine’s status bar. A menu pops up where you can select which USB device to connect to the guest OS:

This screenshot shows how to attach a USB stick to a virtual machine.

Copy files via SSH

In case you do not have a USB stick lying around, you can exchange files the way you typically do with a Linux server: good old SSH. This does require that you have an SSH server installed and running on your guest OS. For improved convenience and security, you could use SSH keys for accessing the guest OS. Refer to this article for details on how to copy files via SSH.

Читайте также:  How to create shortcut in linux

What do you need

The explanation presented in this article, assumes that you have a Linux based VirtualBox virtual machine. So for starters, you need a VirtualBox virtual machine, where you already installed Linux. The type of Linux distribution and desktop environment doesn’t really matter. Choose whatever you prefer.

In order to mount a shared folder inside your VirtualBox virtual machine, the VirtualBox Guest Additions should already be installed in the guest OS. This article explains how to do this for a Debian or Ubuntu based virtual machine.

Throughout this article I’ll use my Linux laptop, currently running Debian 10, as the host OS. It has VirtualBox installed. I already created a VirtualBox virtual machine based on openSUSE Leap 15.2. This virtual machine serves as the guest OS.

Configuring the shared folder

As a first step, we configure the shared folder. We do this from the VirtualBox user interface. Here’s a screen animation on how to configure the shared folder, followed by a description of each step:

  1. Select your virtual machine and open its settings dialog.
  2. Locate the Shared Folders category and click the little folder icon with the green plus-sign on it.
  3. On the Add Share dialog select the folder on the host OS that you want to share with the guest OS.
  4. I typically share my user’s Desktop folder, but you can change this to whatever directory you prefer.
  5. As a final step, check the Auto-mount check box. Click the OK button and start the virtual machine.

Permissions for accessing the shared folder

When the virtual machine of your guest OS finished booting, you can open your file manager. There, you’ll see a new device entry for the shared folder that VirtualBox automatically mounted for you. However, if you try to access the shared folder, you’ll notice that your user misses the necessary permissions to access the shared folder:

No worries, because we can easily fix this VirtualBox shared folder permission problem. Note though that the error message did tell us, where VirtualBox automatically mounted the shared folder to:

Let’s find out which user and group owns the mounted shared folder. Run the following command from the terminal on the guest OS:

Terminal screenshot that shows the shared folder owner and permissions. Here you can see that you need to either be the root user or be part of the vboxsf group. Otherwise you cannot access the shared folder.

From the command output we can deduce that:

  1. The root user owns the folder.
  2. Everyone in the vboxsf group has read, write and execute permissions.

With other words, we just need to add our own user to the vboxsf group. You can add your user to the vboxsf group by issuing this command from the terminal on the guest OS:

sudo usermod -a -G vboxsf $USER

Screenshot that show how you can add your user to the vboxsf group. The issued command is

For group changes to take effect, you should reboot your virtual machine. Afterwards, your user has full access to the shared folder, which VirtualBox automatically mounted to /media/sf_Desktop .

Specifying a specific mount point

As we saw in the previous section, VirtualBox automatically mounted the shared folder to:

In our case, the was set to Desktop, resulting in the /media/sf_Desktop mount point. What if you don’t want to use that particular folder as the mount point? Well, we can easily configure a different folder for the mount point. Only two minor steps are involved:

  1. Make sure the folder for the new mount point actually exists on the guest OS.
  2. Change the mount point in the Shared Folder settings.
Читайте также:  Подключение ntfs раздела linux

Let’s assume we want /mnt/shared as the mount point for our shared folder. Open up the terminal in the guest OS and make sure this folder exists:

Terminal screenshot that shows you how to create a directory that can then be used as a mount point.

Next, shut down the virtual machine of the guest OS. After that, go to the Shared Folder settings of the virtual machine to specify our preferred mount point of /mnt/shared :

Screenshot of the

If you now start up the virtual machine of the guest OS, you’ll notice that VirtualBox mounted the shared folder to /mnt/shared , instead of the default /media/sf_Desktop .

Manually mounting the shared folder

In the previous examples, VirtualBox automatically mounted the shared folder for us, during system boot. Convenient, but not always wanted. This section shows you how to manually mount (and unmount) a VirtualBox shared folder.

Why would you not want to automatically mount a shared folder? Let’s say that you use the shared folder for backup purposes. So for backing up data from the guest OS, to your host OS. In this situation you should only mount the shared folder right before you run a backup. Then when the backup operation completed, you should unmount the shared folder. Otherwise the guest OS can always access the shared folder with backup data and potentially corrupt it if something goes wrong.

Disable the auto-mount feature

First we need to disable the auto-mount feature. With the virtual machine turned off, access the Edit Share dialog. On this dialog, uncheck the Auto-mount check box. Also make a note of the Folder Name, which is set to Desktop in my case:

Screenshot of the

Mount a shared folder manually

After disabling the auto-mount feature, start the virtual machine. At any point in time you can manually mount the shared folder with command syntax:

sudo mount -t vboxsf -o uid=$USER,gid=vboxsf [SHARE NAME] [MOUNT POINT]

Note that [SHARE NAME] should be the Folder Name, which you saw on the Edit Share dialog. In my case, I used the following command to manually mount the shared folder:

sudo mount -t vboxsf -o uid=$USER,gid=vboxsf Desktop /mnt/shared

Terminal screenshot that shows how to manually mount the shared folder inside the VirtualBox guest OS.

The $USER part gets automatically replaced with your username, which is pragmalin on my guest OS. Your user now has full access to the shared folder.

Unmount a shared folder manually

Once you no longer need access to the shared folder, you can unmount it with this command syntax:

In the case of the previous example, run this command to unmount the share folder:

Terminal screenshot that shows how to manually unmount a shared folder.

Wrap up

After working your way through this article, you learned how to configure VirtualBox’s shared folder feature. The VirtualBox shared folder feature makes it possible for your guest OS, to mount a directory from the host OS. Once configured, you can easily exchange files between the host OS and the guest OS.

This article demonstrated three different approaches:

  1. Automatically mount a shared folder to a mount point assigned by VirtualBox. This is typically somewhere inside the /media directory on your guest OS.
  2. Automatically mount a shared folder to a mount point of your choosing. We used /mnt/shared in the examples.
  3. Manually mount (and unmount) a shared folder to a mount point of your choosing.

Just keep in mind that the VirtualBox shared folder feature only works, if you installed the VirtualBox Guest Additions on your guest OS.

PragmaticLinux

Long term Linux enthusiast, open source software developer and technical writer.

Источник

Оцените статью
Adblock
detector