This comes, once again, from the department of “Should be working out of the box.” Have you ever needed to type out a long string of text, a line of code, URL, or paragraph, into your VirtualBox guest–knowing said text is sitting there, waiting patiently, on your host? You want to simply copy and paste it, but the action never seems to work.
What if you could make that feature actually work? Better yet, what if you could enable the action so that it would work both ways (from host to guest and guest to host)? That would make working with VirtualBox significantly easier. Well, it’s time you made that a reality. And I’m going to show you how.
Install Guest Additions
This is the sticking point. Without the Guest Additions installed, copy and paste will not work. I’m going to walk you through the process of installing the Guest Additions that should work on any Linux distribution (you will have to modify the installation command to suit your distribution’s package manager). This process will be similar on a Windows host, only you shouldn’t have to mount the drive, and you can simply double-click the .exe installer file.
For installing the Guest Additions on Linux, here’s what to do:
- Start VirtualBox.
- Start the host in question.
- Once the host has booted, click Devices | Insert Guest Additions CD Image.
- Open up a terminal window in the guest.
- Mount the CD-ROM with the command sudo mount /dev/cdrom /mnt.
- Change into the mounted directory with the command cd /mnt.
- Install the necessary dependencies with the command sudo dnf install -y dkms kernel-devel kernel-devel-$(uname -r).
- Change to the root user with the command sudo su.
- Install the Guest Additions package with the command ./VBoxLinuxAdditions.run.
- Allow the installation to complete.
If you’re working with a Ubuntu-based guest, the command to install the necessary dependencies is sudo apt-get install -y dkms build-essential linux-headers-generic linux-headers-$(uname -r).
One the installation is finished, reboot the guest operating system.
Enable copy and paste
At this point, copy and paste (from either guest to host or host to guest) can be enabled. Start the VM, and once it’s booted, click Devices | Shared Clipboard | Bidirectional (Figure A).
You can now copy and paste from guest to host and host to guest. No more having to retype lines of code or URLs and no more wondering why the feature wasn’t working.
A bonus feature that still doesn’t work
One nice bonus to this is that adding the Guest Additions also allows the enabling of Drag and Drop. Or it should. To enable the feature, click Devices | Drag and Drop | Bidirectional. There is one caveat to this, in that Drag and Drop doesn’t work with every desktop or every file manager. The feature will not work with Elementary OS, or most desktops that depend upon Wayland. The chances Drag and Drop will not work for you are slim. If so, you’ll need to make use of Shared Folders (until the developers work out the associated Drag and Drop bugs).