Configure the VirtualBox shared folder on the Ubuntu Server 22.04 virtual machine

Introduction: This article will introduce how to configure the VirtualBox shared folder on the Ubuntu Server 22.04 virtual machine to realize file sharing between the host and the virtual machine.

text:

VirtualBox is a popular open-source virtualization software that can run various virtual machines on a host operating system. This article will guide you to install the VirtualBox enhancement package (Guest Additions) on the Ubuntu Server 22.04 virtual machine and configure the shared folder to realize file sharing between the host and the virtual machine.

Install the VirtualBox Enhancement Pack

Before you start configuring shared folders, make sure you have the VirtualBox Enhancement Pack installed on your virtual machine. Here are the steps to install the Enhancement Pack on an Ubuntu Server 22.04 virtual machine:

  1. Update the system to the latest version. Open a terminal on the virtual machine and run the following command:
sudo apt update
sudo apt upgrade
  1. Install the necessary dependencies so that the Enhancement Pack can be compiled and installed correctly. Run the following command:
sudo apt install build-essential dkms linux-headers-$(uname -r)
  1. On the VirtualBox menu bar, click Devices > Install Enhancement Pack. This will simulate a disc inserted in the virtual machine.

  2. In Terminal, create a new directory, and mount the ISO image file to that directory. Run the following command:

sudo mkdir /media/cdrom
sudo mount /dev/cdrom /media/cdrom
  1. Change to the CD directory and run the Enhancement Pack installer. Run the following command:
cd /media/cdrom
sudo ./VBoxLinuxAdditions.run
  1. Once the installation is complete, restart the virtual machine for the changes to take effect:
sudo reboot

Configure shared folders

After installing the Enhancement Pack, you can start configuring shared folders. Follow the steps below:

  1. Set up the shared folder correctly in VirtualBox's virtual machine settings. In the Shared Folders tab, check the following:
    • Is the path of the shared folder correct?
    • Whether the options "Automount" and "Permanent" are selected.
    • Take note of the name of the shared folder, we will use it later in the virtual machine.
  2. In the terminal of the virtual machine, create a directory where the shared folder will be mounted. For example, you can create a directory called /media/shared-folder. Run the following command:
sudo mkdir /media/shared-folder
  1. Manually mount the shared folder with the following command:
sudo mount -t vboxsf shared_folder_name /media/shared-folder

Replace shared_folder_name with the shared folder name you wrote down in step 1.

  1. If the shared folder is successfully mounted, you should see the files in the host operating system in the /media/shared-folder directory. In order for the mount to take effect on every boot, add the mount command to the /etc/fstab file. Edit the /etc/fstab file with your favorite text editor such as nano or vim:
sudo nano /etc/fstab

Add the following at the end of the file:

shared_folder_name /media/shared-folder vboxsf defaults 0 0

Replace shared_folder_name with the shared folder name you wrote down in step 1. Save and close the file.

  1. Finally, restart the virtual machine for the changes to take effect:
sudo reboot

After completing these steps, you should be able to see and access the host operating system's shared folders in the /media/shared-folder directory.

in conclusion

With the guideline in this article, you have successfully configured a VirtualBox shared folder on an Ubuntu Server 22.04 virtual machine. Now you can easily share files between hosts and virtual machines, increasing productivity and streamlining workflows. If you have any questions, please feel free to leave a message in the comment area.

Guess you like

Origin blog.csdn.net/kaka_buka/article/details/130413579