Posts Tagged ‘copy paste virtualbox linux’

Copy Paste Virtualbox enable between Linux Host and Guest Virtual Machine

Thursday, September 6th, 2018

enable-copy-paste-between-linux-host-and-guest-OS-virtual-machine-virtualbox-vbox-logo

Copy / Pasting has become a vital part of our digital lifes, not having it in our days is insane, most of our System Administration jobs / Programmer or Office (Secretary) stuff daily without Copy / Paste is a unthinkable.

Lately I have been playing with Virtual Machines as I need to test some Dev Ops related stuff I install Jenkins write and test scripts and tools inside a VM, for that to happen I needed a working VM and because I am a Free Software supporter my VM of choice is usually Virtualbox. Even though Virtualbox is not the best and most performance efficient Virtual Machine out there for a small tasks and home usage dev / testing it does a great job, I have faced a problem with Copy / Pasting not working in VBox between the VM -> Guest OS, that's why I decided to write this step by step guide to help people who face the same issue.

For people who are starting with Oracle VirtualBox and you just have Created a New Virtual Machine and installed GNU / Linux or FreeBSD one common set back problem you will experience is the the Copy / Paste functionality between the VM Host Machine and the Guest won't be working out of the box. That's pretty much annoying thing and since usually one installs different Virtual Machines with different Operating Systems as a test bed for Software installs on top of various versions of OSes the lack of Copy, Paste functionality which is not there by default makes copy / pasting programming code / commands etc. between your local Desktop notebook or remote  server Machine and the VBox Virtualized Guest mostly unusuable …

Besides that integration (sharing resources / improved VM performance) between the Host (which is for example your Desktop notebook or PC) and the Virtualized Operating system be it some kind of UNIX (FreeBSD) etc. is not optimal until you enable an extra integration between VirtualBox and your (Host OS – that in my case is Debian 9 GNU / Linux but it can be Microsoft Windows XX as well or any other *nix like OS).In order for this Integration between your Host OS and Guest OS and Copy / Paste features between the two to work you need to Enable Guest Additions CD image (Software) that is part of VirtualBox installation on the Host OS and once enabled to mount (Attach the Vbox provided Virtual CD) from within the Guest OS (that in my case is another Debian 9 Stretch Linux that is installed inside the VM) and run a script that will install the necessery VirtualBox software inside the Guest OS Linux.
 

This is done in 3 easy steps:

STEP 1: Enable Vbox (Guest Additions CD Image)


virtualbox-VM-enable-insert-guest-additions-CD-image-menu-screenshot-debian-linux

 

Devices -> Insert Guest Additions CD image

 


2. Enable Shared Clipboard and Drag and Drop from the Virtual Machine

virtualbox-VM-enable-devices-shared-slipboard-bidirectional-menu-screenshot-debian-linux
 

Devices -> Shared Clipboard -> Bidirectional

 

 

virtualbox-VM-enable-devices-drag-and-drop-bidirectional-menu-screenshot-debian-linux
 

Devices -> Drag and Drop -> Bidirectional


3. Install development packages that are required by VBoxLinuxAdditions.run script

a) First thing is to use Virtual Box program interface menu and enable Insert Guest Additions CD Image option (assuming that you have the Linux Guest OS running).

virtualbox-VM-enable-insert-guest-additions-CD-image-menu-screenshot-debian-linux
 

Devices -> Insert Guest Additions CD image


https://www.pc-freak.net/images/virtualbox-virtual-machine-guest-os-settings

You can do it also from main VirtualBox interface (without having a Virtual machine running) by clicking over the desired Guest OS or pressting CTRL + S key combination

b) Next step is to mount the Virtual CD Guest Additions inside the Guest OS VM

To mount the Virtual content provided by the just ticked VBOX "Insert Guest Additions CD" menu, inside the Guest OS Linux, you have to run simple mount command:

 

 

root@debian:~# mount /media/cdrom1
mount: /dev/sr1 is write-protected, mounting read-only

 

c) Install necessery packages that VBoxLinuxAdditions.run will use

Further on VBoxLinuxAdditions.run (additions script) that adds the integration between the Host operating system and the Guest OS depends on some essential tools necessery for building (compiling) / developing software on Linux, this are:

1.) build-essential – a meta package that will install the following set of packages:

 

dpkg-dev fakeroot g++ g++-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl libfakeroot libfile-fcntllock-perl libstdc++-6-dev


which are necessery for creation .deb packages, compiling code and other various activitions. a) build-essential is a very important Debian based distro package and if you happen to be new to Linux or just starting learning how to develop programs on Linux, you will soon realize you will need it installed across almost all Linux OS hosts you maintain or develop on …

VirtualBox-VBoxLinuxAdditions-run-script-missing-headers-gcc-perl-how-to-fix

 

root@debian:~# apt-get install –yes build-essential linux-headers-$(uname -r) gcc perl make

 


2.) The linux-headers package in my case that it is is linux-headers-4.9.0-7-amd64 is important as it provides kernel header files that are necessery when compiling and integrating kernel modules VBoxLinuxAdditions.run script depends on it as it builds a kernel module that adds the integration (that enables Copy / Paste and performance inprovements) between the Host VM machine and Guest OS

3.) gcc perl packages this two provides the C compiler and perl scripting programming language interpreter which are also used by VBoxLinuxAdditions.run script.


Now run VBoxLinuxAdditions.run:

As you see in above screenshot the

root@debian:~#
root@debian:/media/cdrom1# sh VBoxLinuxAdditions.run
Verifying archive integrity… All good.
Uncompressing VirtualBox 5.2.18 Guest Additions for Linux……..
VirtualBox Guest Additions installer
Removing installed version 5.2.18 of VirtualBox Guest Additions…
Copying additional installer modules …
Installing additional modules …
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.  This may take a while.
VirtualBox Guest Additions: Running kernel modules will not be replaced until the system is restarted
VirtualBox Guest Additions: Starting.

 


If everything is fine you should get command output like above.

Above are the steps given to follow on current latest Debian Linux 9.5 (Stretch) as a Guest OS (this tutorial should be working also on Ubuntu / Mint and other deb package based distributions for RPM package based Linuxes Fedora / CentOS check out my previous toturial how to enable Linux Guest Virtualbox Addition on Redhat based distos.)

P. S.

What about Mac OS X since it is based on FreeBSD and it includes a lot of GNU licensing programs?

If you wonder whether on Mac OS X you don't need to run guest additions script such as (VBoxLinuxAdditions.run) on Mac Host -> Guest OS integration is done only by enabling the feature from VBox GUI interface via:
 

Devices -> Insert Guest Additions CD Image

What about enabling Copy / Paste on Linux Host VirtualBox hosting a Windows Guest OS?

 

 

Enabling Copy / Paste on a Windows Virtual Machine (I wrote about it earlier here), follows the same steps as in this tutorial.
The only difference is instead of running the VBoxLinuxAdditions.sh you have to navigate to the CD from Windows Explorer and run the appropriate .exe file depending on your architecture (X86 or 64 bit), the files to run on the virtual CDROM are one of the 3:

1. VBoxWindowsAdditions-amd64.exe
2. VBoxWindowsAdditions.exe
3. VBoxWindowsAdditions-x86.exe

virtualbox-vm-guest-additions-autoplay-web-on-windows-os

Follow the click through interface and you will have the Copy / Paste between your Linux -> Windows OS working.

Happy Copy / Pasting ! 🙂