Wednesday, November 2, 2016

How to Install VirtualBox Guest Additions on Debian

VirtualBox Guest Additions provides many features, yet it may not be easy to install on Debian system. Here is how to install Guest Additions on Debian guest machine.

In the guest Debian system, insert Guest Additions image by selecting Devices->Insert Guest Additions CD Image from VirtualBox menu. This will insert the image into the guest machine. 

The Debian system will automatically mount the image to /media/cdrom folder. Let's run it:
$ su -
Password:
# cd /media/cdrom
# ./VBoxLinuxAdditions.run
-su: ./VBoxLinuxAdditions.run: Permission denied

This is rather interesting. Permission denied even for root. By the way if you want to run sudo command instead of su in Debian, refer to this tutorial.

The reason for this is actually because the Guest Additions image has been mounted with noexec flag.

# mount | grep cdrom
/dev/sr0 on /media/cdrom0 type iso9660 (ro,nosuid,nodev,noexec,relatime,user)

As clearly seen, the Guest Additions CD image has been mounted with noexec flag set. That is why you couldn't run it even as root. Let's mount it again without noexec flag.

# cd / && mount -t iso9660 /dev/sr0 /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
# mount | grep cdrom
/dev/sr0 on /media/cdrom0 type iso9660 (ro,relatime)

OK. The Guest Additions image has been mounted successfully. Let's run the install script;
# /media/cdrom/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.8 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.

Well, let's examine the log file:
# cat /var/log/VBoxGuestAdditions.log
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed..

As the log file states, we need to install some necessary packages first, because it needs to compile the Guest Additions from sources.
# apt-get update
# apt-get install -r gcc make linux-hearders-$(uname -r)

Finally, we are ready to install Guest Additions:
# /media/cdrom/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.8 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.8 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.
vboxadd.sh: Starting the VirtualBox Guest Additions.

You may need to restart the the Window System (or just restart the guest system)
to enable the Guest Additions.
# reboot

You may want to reboot for this to take effect. Enjoy virtual Debian system!

2 comments:

  1. E: Unable to locate package linux-header-4.6.0-kali1-amd64
    E: Couldn't find any package by glob 'linux-header-4.6.0-kali1-amd64'
    E: Couldn't find any package by regex 'linux-header-4.6.0-kali1-amd64'
    how can i fix it

    ReplyDelete
    Replies
    1. This may be helpful to you:
      http://unix.stackexchange.com/questions/266871/cannot-find-linux-headers-4-3-0-kali-amd64

      Delete