Software & AppsOperating SystemLinux

How To Share a Directory in VirtualBox Between Host and Guest Machines on Ubuntu 18.04

Ubuntu 10

In this tutorial, we will guide you through the process of sharing a directory between a host machine and a guest machine using VirtualBox on Ubuntu 18.04.

Quick Answer

To share a directory between a host machine and a guest machine on Ubuntu 18.04 using VirtualBox, you need to install VirtualBox Guest Additions on the guest machine, configure shared folders in VirtualBox, add the user to the ‘vboxsf’ group, create a mount point in the guest OS, and mount the shared folder.

Prerequisites

Before we begin, ensure that you have VirtualBox installed on your Ubuntu 18.04 host machine. If not, you can download it from the official VirtualBox website.

Step 1: Install VirtualBox Guest Additions on the Guest Machine

The first step is to install VirtualBox Guest Additions on the guest machine. This software package enhances the functionality of the guest machine, including improved video support and better shared directory capabilities.

To install Guest Additions, start your guest machine and click on the “Devices” menu in the VirtualBox window. Select “Insert Guest Additions CD image” and follow the on-screen instructions to install the software.

Step 2: Configure Shared Folders in VirtualBox

Next, you need to configure the shared folders in VirtualBox.

  1. In the VirtualBox Manager, select your guest machine and click on “Settings”.
  2. Navigate to the “Shared Folders” section.
  3. Click on the “+” icon to add a new shared folder.
  4. In the “Add Share” window, select the folder path on your host machine that you want to share.
  5. Choose a name for the shared folder.
  6. Make sure to check the “Auto-mount” option. This ensures that the shared folder is automatically mounted every time you start the guest machine.
  7. Click “OK” to save the settings.

Step 3: Add User to the ‘vboxsf’ Group

In order for the shared folder to be accessible, your user on the guest machine needs to be part of the ‘vboxsf’ group.

Open a terminal in the guest OS and run the following command:

sudo adduser $USER vboxsf

This command adds the current user (represented by $USER) to the ‘vboxsf’ group. The ‘sudo’ command is used to run the command with root privileges.

Step 4: Log Out and Log Back In

For the group changes to take effect, you need to log out and log back into the guest OS.

Step 5: Create a Mount Point

Next, you need to create a directory in the guest OS where you will mount the shared folder.

For example, you can create a directory called “host” in your home directory using the following command:

mkdir ~/host

Step 6: Mount the Shared Folder

Finally, you can mount the shared folder using the following command:

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

In this command:

  • ‘sudo’ runs the command with root privileges.
  • ‘mount’ is the command to mount file systems.
  • ‘-t vboxsf’ specifies the type of the file system. In this case, it’s ‘vboxsf’, which is the file system type for VirtualBox shared folders.
  • ‘-o uid=$UID,gid=$(id -g)’ sets the owner of the files in the shared folder to the current user and group.
  • ‘share’ is the name of the shared folder you created in step 2.
  • ‘~/host’ is the directory where you want to mount the shared folder.

If you encounter any errors, make sure that you have followed all the steps correctly and that the mount point directory exists. You can also try running sudo chmod 777 /home/atinesh/host in the guest OS to ensure proper permissions.

Conclusion

By following these steps, you should now be able to share directories between a host machine and a guest machine in VirtualBox on Ubuntu 18.04. This can be very useful for transferring files between the two machines, or for sharing resources in a development environment.

How can I access the shared folder from the guest machine?

Once the shared folder is mounted, you can access it from the guest machine by navigating to the mount point directory. In this tutorial, the mount point directory is "~/host". So, you can access the shared folder by opening a file explorer and navigating to the "~/host" directory.

Can I share multiple folders between the host and guest machines?

Yes, you can share multiple folders between the host and guest machines. In step 2, when configuring shared folders in VirtualBox, you can add multiple shared folders by clicking on the "+" icon and following the same process for each folder. Each shared folder will have its own name and mount point in the guest machine.

Can I change the name or location of the shared folder on the host machine?

Yes, you can change the name or location of the shared folder on the host machine. To do this, you need to modify the shared folder settings in VirtualBox. Go to the "Settings" of your guest machine, navigate to the "Shared Folders" section, and edit the existing shared folder. You can change the folder path to a different location on your host machine and also update the name of the shared folder.

Can I access the shared folder from the host machine?

Yes, you can access the shared folder from the host machine. The shared folder is mounted in the guest machine, but it can also be accessed from the host machine through the VirtualBox shared folders feature. By default, the shared folder is located at "/media/sf_share" on the host machine. You can navigate to this location in the file explorer of your host machine to access the shared folder.

Do I need to repeat the mount command every time I start the guest machine?

No, you do not need to repeat the mount command every time you start the guest machine. By checking the "Auto-mount" option in step 2, the shared folder will be automatically mounted every time you start the guest machine. This ensures that the shared folder is always accessible without manually running the mount command.

Leave a Comment

Your email address will not be published. Required fields are marked *