VirtualBox

How do I enable copy and paste between VirtualBox and host?

While working in a VirtualBox and its virtual machines, it is often needed to copy and paste some content between the Virtual machine and the host. In other words, if we use real technical terms, we need to share the clipboard between guest and host. For sharing the clipboard, all you need to do is install the Guest Additional Image in your Virtual Machine and enable the sharing of the clipboard.

Installation of VirtualBox Guest Addition Image

To install guest additional image in your Virtual Machine, follow the procedure given below:

Open up the Virtual box and select the machine in which you want to enable the clipboard sharing feature, and start the machine.

Once the machine is started, open the terminal of the Operating system and execute the command provided below to install some necessary packages for installing Guest Addition Image:

For Ubuntu or Debian based operating systems:

$ sudo apt install build-essential dkms linux-headers-$(uname -r)

For CentOS or RHEL based operating systems:

$ sudo dnf install gcc kernel-devel kernel-headers dkms make bzip2 perl

After installing the required packages as well, insert the Guest Addition CD image by clicking on the “Devices” in the menu bar of the Virtual machine and selecting “Insert Guest Addition CD image” from the “Devices” menu:

The installation will complete in a while.

Once it is completed, it will ask to reboot the system. So, shut down the machine and go to the settings of that machine by right-clicking on the machine and selecting the settings icon or select the machine and click on the settings icon as shown in the screenshot attached below:

In the settings window of the machine, go to the “General” tab from the left sidebar and select the “Advanced” tab as shown in the picture given below:

In the “Advanced” tab, you can see the two dropdowns named “Shared Clipboard” and “Drag’n’Drop.”

Select each dropdown menu and choose the “Bidirectional” option to enable the machine’s clipboard sharing and drag-drop features.

After changing both options, click the “ok” button shown in the bottom right corner of the settings window to save all the settings done.

Now, just start the machine to enable copy and paste between VirtualBox and host.

But if it is not working for you, then it means that the guest Addition Image is not inserted successfully. You have to insert it manually.

Insert Guest Addition CD Image Manually

First, create a new /mnt/cdrom directory:

$ sudo mkdir -p /mnt/cdrom

After creating, mount the image to the /mnt/cdrom:

$ sudo mount /dev/cdrom /mnt/cdrom

Change directory to the /mnt/cdrom and execute the “VBoxLinuxAddition.run” script:

$ cd /mnt/cdrom

$ sudo sh ./VBoxLinuxAdditions.run --nox11

Once the script has finished the execution. Reboot the system using the command mentioned below:

$ sudo shutdown -r now

After rebooting the machine, retry to copy and paste something between the host and Virtual machine. It will definitely work perfectly fine now.

Enable Shared Clipboard Option

There is another way to enable the shared clipboard option to bidirectional by going to the “Devices” in the menu bar, “shared Clipboard,” and clicking on the “Bidirectional” option as shown in the screenshot provided below:

After enabling it, you can easily copy and paste anything between host and Virtual Machine

Conclusion

This post has covered all the basic to pro-level concepts and methods to install the Guest Addition CD Image to enable the copy and paste between VirtualBox and host. We have learned to share the clipboard between the host and the virtual machine and enable the drag-drop features between them by installing the Guest Addition Image in the virtual machine using the simple method and manually from the terminal.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.