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.
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.
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.
- In the VirtualBox Manager, select your guest machine and click on “Settings”.
- Navigate to the “Shared Folders” section.
- Click on the “+” icon to add a new shared folder.
- In the “Add Share” window, select the folder path on your host machine that you want to share.
- Choose a name for the shared folder.
- Make sure to check the “Auto-mount” option. This ensures that the shared folder is automatically mounted every time you start the guest machine.
- 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:
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.
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.
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.
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.
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.
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.
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.