1. Installation environment

First, start the virtual machine and prepare the installation environment by executing the following commands.

Sudo apt update -y && apt upgrade sudo apt update -y && apt upgrade Sudo apt install DKMS Linux-headers -$(uname -r) build-essentialCopy the code

2. Obtain the mirror of Guest Additions

  1. Download from the official website;
  2. For Mac systems Guest Additions are located in the VirualBox installation directory (generally/Application/VirualBox) under the./Contents/MacOS/VBoxGuestAdditions.iso, copy the file to an alternate directory.

3. Mount the vboxGuestExtrared. iso image to the virtual DVD-ROM drive

  1. Open the VirualBox Manager, select the VM, and choose Settings > Storage >IDE. If no virtual DVD-ROM drive is available, add a virtual DVD-ROM drive. If you have a CD/DVD drive, select the CD/DVD drive and click 💿 to select a virtual CD/DVD file. Then select the vboxGuestExtracting. iso virtual CD/DVD file you just copied.
  2. After the CD is inserted, the device file is/dev/cdrom, the device will be automatically mounted to/media/cdrom0. You can mount it to any directory with the mount command, which is not described here.

4. Start the installation script

After all the above preparations, we can officially proceed with the installation.

sudo sh /media/cdrom0/VBoxLinuxAdditions.run
Copy the code

If no error occurs, the following log is generated:

Verifying archive integrity... All Good. Uncompressing VirtualBox 6.0.8 Guest Additions for Linux........ Installer Removing VirtualBox Guest Additions Installer Removing Installed Version 6.0.8 of VirtualBox Guest Additions... Update-initramfs: Generating /boot/initrd.img-4.19.0-5- AMd64 Copying Additional Installer modules... Installing additional modules ... VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Building the modules for kernel 4.19.0-5-amd64. update-initramfs: Generating /boot/initrd.img-4.19.0-5- AMd64 VirtualBox Guest Additions: Running kernel modules will not be replaced until the system is restartedCopy the code

As described in the log, we need to reboot and reload the compiled kernel module.

sudo reboot
Copy the code

5. Create a shared folder

Start the VirualBox manager, select the VM, choose Settings > Shared Folder > Add Shared Folder, and select the path of the shared folder on the host. The name of the shared folder is specified by yourself. In this example, Share is used. Auto mount, select Yes. Click OK to create the shared folder.

6. Mount the shared folder

  1. The newly created Share folder is automatically mounted to the VM/mediaIn the directory, the name issf_<ShareDirName>Where our Share folder will be mounted as:/media/sf_Share.
  2. Of course, you can mount the shared folder to the specified directory
sudo mount -t vboxsf  <ShareDirName>  YourDirName
Copy the code

In this example, mount Share to ~ /Share and check the UID and GID of the user. Assume that the uid and GID are 1000 and 1000

mkdir ~/Share
sudo mount -t vboxsf -o uid=1000,gid=1000 Share  ~/Share
Copy the code