Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Script to Install Virtual Guest Additions from CD

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
makh
Posts: 651
Joined: 2011-10-09 09:16

Script to Install Virtual Guest Additions from CD

#1 Post by makh »

Objective:
To install the virtualbox guest additions in the Debian, as Guest OS, inside Virtualbox, after inserting the guest additions CD.

:idea: Reason to create a script:
It makes using linux faster.
:arrow: Creating the script:

Code: Select all

# nano /root/myvboxguestadditions.sh
Caution:

Code: Select all

It creates and uses the path "/mnt/cdrom", please edit the script if you have something else mounted on directly on /mnt
Theres no responsibility for any damage caused, in any way by this script.
Make it executable:

Code: Select all

# chmod a+x myvboxguestadditions.sh
How to run as root:

Code: Select all

# ./myvboxguestadditions.sh
For other details:
Please refer to the Official Documentation of Virtualbox.
Running OK on other Linux (right now):

Code: Select all

1. Devuan
2. Linux Mint
3. Open suse Tumbleweed
4. Ubuntu
The bash script:
# cat myvboxguestadditions.sh

Code: Select all

#!/bin/bash
#
# Author: Khurram M. <makhmct@hotmail.com>
# Script Version: 1.0
# Script type: Opensource
# Licensed: GPL v3 
# Created on: 24 November 2017
# Last edited: 27 November 2017
#
# Tested to work on: VirtualBox 5.2, 64-bit
# Host: Arch Linux, kernel ver 4.13.12-1
# Guests: Debian 9.2, Devuan Ascii, Linux Mint 18.2, OpenSuse Tumbleweed 4.14,  
# Not Tested on Guest OS: MacOS, Android, BSD, others
#

echo 'Checking if run as Root...'
if [[ $EUID -ne 0 ]]
	then
		echo "[ERROR] This script must be run as root." 
		echo "Exiting ..."
		exit 1
	else
		echo "[OK] This script is run by the root."
fi

echo

echo 'Checking mount point...'
file1="/mnt/cdrom"
if [ ! -f "$file1" ]
	then
		echo "File $file1 does not exist."
		echo 'Creating the Mount point...'
		mkdir -pv /mnt/cdrom && echo '[OK] Mount point created ...'
	else
		echo "[OK] Mount point $file1 exists..."
fi

echo

echo 'Mounting the disk...'
mount -v /dev/sr0 /mnt/cdrom && echo '[OK] Disk Mounted ...'

echo

echo 'Installing the guest addition modules...'

echo

sh /mnt/cdrom/VBoxLinuxAdditions.run && echo '[OK] Guest additions installed ...'

echo

echo 'Umounting disk...'
umount -v /dev/sr0 && echo '[OK] Umount of disk is successful'

echo '[OK] Exiting the script ... Have a nice day! :) ... '

exit 1
Do give a good suggestion, if you have, I may put changes to this script. But I dont intend to add unneccessary complexity(s).

Hope you enjoyed this script.

Thankyou
:)

Edit:
1. Works fine currently, on Debian 10/Buster. Hope there are no issues at your end, too. :)

2. See my 4th post, below for Debian only, where it is added to cross check and add dependencies. :arrow:

3. Tested Ok for Ubuntu also.

4. This does not applies to Desktop Linux: For CLI/TUI Linux (ie you are using no X windows on this machine), edit the code to:

Code: Select all

sh /mnt/cdrom/VBoxLinuxAdditions.run --noX11
5. Correction(s).
Last edited by makh on 2017-12-21 19:45, edited 3 times in total.
ThinkPad E14: Arch, Debian Stable
GUI: Xfce

For new: Try MX Linux, Linux Mint; later join Debian Stable

User avatar
Ardouos
Posts: 1075
Joined: 2013-11-03 00:30
Location: Elicoor II
Has thanked: 1 time
Been thanked: 4 times

Re: Script to Install Virtual Guest Additions from CD

#2 Post by Ardouos »

makh wrote: Do give a good suggestion, if you have, I may put changes to this script. But I dont intend to add unneccessary complexity(s).
If I wanted to run the script, I would want to run it as soon as I have installed a minimal system. The problem is that virtualbox guest additions requires headers and various other packages.

It'll be great if you could add a line for apt to check and install all the necessary dependencies.
There is only one Debian | Do not break Debian | Stability and Debian | Backports

⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Script to Install Virtual Guest Additions from CD

#3 Post by Dai_trying »

Ardouos wrote:It'll be great if you could add a line for apt to check and install all the necessary dependencies.
I was thinking something along the same lines, and if I recall, the package build-essential brings in all that is usually required but it has been a while since I last installed a VM so there could possibly be other requirements.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Script to Install Virtual Guest Additions from CD

#4 Post by Head_on_a_Stick »

makh wrote:Do give a good suggestion, if you have
Stop using Virtualbox and switch to KVM (with QEMU) instead:

https://wiki.debian.org/KVM

No need to install any silly "guest additions" with the open-source solution and in my experience it's even quicker than VB.

EDIT: simpler guide here:

https://forums.bunsenlabs.org/viewtopic.php?id=1546
deadbang

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: Script to Install Virtual Guest Additions from CD

#5 Post by stevepusser »

Dai_trying wrote:
Ardouos wrote:It'll be great if you could add a line for apt to check and install all the necessary dependencies.
I was thinking something along the same lines, and if I recall, the package build-essential brings in all that is usually required but it has been a while since I last installed a VM so there could possibly be other requirements.
build-essential only brings in compilers, so the kernel headers are another matter. Perhaps you could take a look at how module-assistant handles the same job with the "prepare" target, as in "m-a prepare".
MX Linux packager and developer

User avatar
makh
Posts: 651
Joined: 2011-10-09 09:16

Re: Script to Install Virtual Guest Additions from CD

#6 Post by makh »

Hi

@Ardouos: It was just a small fun project.If I am using a few scripts, then that is for a specific purpose. Your point is definitely doable, but then I have to modify for Opensuse and many others, in case I am testing, that would be complicated, as these server managing guys:
https://unix.stackexchange.com/question ... ell-scriptseem to have a hard time.
2. then the complication of non-debian and non-rpm based and others, the packages differ. :?
3. But an option can be added for Debian/Devuan/Mint only... I will try if I get time. :idea:

@Dai_trying: Thankyou. :)

@Head_on_a_Stick: Sir! you are asking a very tough question... it was my first VM experience, as I recall... :wink: One cannot forget his first love... :roll: :lol:
My first DE were KDE of opensuse and Gnome of Ubuntu. I didnt used opensuse for long, as "KDE of opensuse" didnt run on next upgrade on my old computer, back then... so I became the Gnome Guy, until gnome startled me out... today I use either of Openbox, xfce or Cinnamon... :cry:
...
Personally, I am more impressed by XEN. I read somewhere, it allows the use of the drivers of Guest OS to access the hardware, ... it seems par to Virtualbox. But for a user of my level, ... to run a VM is pretty much faster... with a fully featured GUI experience. But then still for some tasks, the CLI based programs are par to GUI
onces. But still some CLI programs arent easy to use. :wink:

@Stevepusser: Thankyou.

Thankyou

Edit: corrections...
ThinkPad E14: Arch, Debian Stable
GUI: Xfce

For new: Try MX Linux, Linux Mint; later join Debian Stable

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Script to Install Virtual Guest Additions from CD

#7 Post by Head_on_a_Stick »

makh wrote:But for a user of my level, ... to run a VM is pretty much faster... with a fully featured GUI experience. But then still for some tasks, the CLI based programs are par to GUI
onces. But still some CLI programs arent easy to use
My guide is command-line based but only because that it what I prefer.

KVM can also be used with virt-manager — this provides a nice, friendly, point-and-click GUI interface that is quite similar to VirtualBox.
makh wrote:XEN
Xen is a full hypervisor solution and is _much_ more difficult to configure than QEMU/KVM and isn't really intended for simple virtualisation tasks in the same way that VB & virt-manager are.
deadbang

User avatar
makh
Posts: 651
Joined: 2011-10-09 09:16

Re: Script to Install Virtual Guest Additions from CD

#8 Post by makh »

Head_on_a_Stick wrote:
makh wrote:XEN
Xen is a full hypervisor solution ...
Hi,
Thats the beauty of Xen over others. But, I didnt search for similar projects, maybe exist or not.
... :)
ThinkPad E14: Arch, Debian Stable
GUI: Xfce

For new: Try MX Linux, Linux Mint; later join Debian Stable

User avatar
makh
Posts: 651
Joined: 2011-10-09 09:16

Re: Script to Install Virtual Guest Additions from CD

#9 Post by makh »

@Ardouos

Hi,
I rechecked it. In the current version of Virtualbox, the guest additions program itself, informs the user for any missing dependencies. I just ran slax to confirm that. So there doesnt seem to be any need to add that part.

Thankyou

Edit 1: Adding for the dependency checking... for Debian Stretch only:

I checked and found that the only dkms was an additional dependency for the Stretch, for the xfce install.

Taking guidance from:
https://stackoverflow.com/questions/129 ... if-its-not

You just simply add the following lines at the start of the script:
if [dpkg-query -W -f='${Status}' dkms 2>/dev/null | grep -c "ok installed"] -eq 0
then
apt update
apt install dkms
fi
It should work for any frest debian stretch/v9 xfce4 installation, I didnt test it on a fresh install. Hope this helps you. Thankyou. :)
Last edited by makh on 2017-11-29 19:49, edited 1 time in total.
ThinkPad E14: Arch, Debian Stable
GUI: Xfce

For new: Try MX Linux, Linux Mint; later join Debian Stable

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Script to Install Virtual Guest Additions from CD

#10 Post by Dai_trying »

stevepusser wrote:build-essential only brings in compilers, so the kernel headers are another matter. Perhaps you could take a look at how module-assistant handles the same job with the "prepare" target, as in "m-a prepare".
Yes it would likely be a better choice, but after checking I noticed header files were installed during my OS installation (using Xfce Live-cd) so it might be an unnecessary concern, although I don't know if this is the case for all install mediums.

User avatar
makh
Posts: 651
Joined: 2011-10-09 09:16

Re: Script to Install Virtual Guest Additions from CD

#11 Post by makh »

Hi

With repsect to a minimal install, using Debian Stretch Xfce installation CD (while not selecting the xfce and the desktop components), which I just tried, one needs to install these packages:
  • gcc
    make
    perl
    header files
For any one new a one liner:

Code: Select all

apt install gcc make perl  linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,')
The above script can be changed to, (for Debian Stretch only):

Code: Select all

#!/bin/bash
#
# Author: Khurram M. <makhmct@hotmail.com>
# Script Version: 1.2
# Script type: Opensource, Debian 9/Stretch
# Licensed: GPL v3
# Created on: 24 November 2017
# Last edited: 22 December 2017
#
# Tested to work on: VirtualBox 5.2, 64-bit
# Host: Arch Linux, kernel ver 4.13.12-1
# Guests: Debian 9.2, 
#

echo 'Checking if run as Root...'
if [[ $EUID -ne 0 ]]
   then
      echo "[ERROR] This script must be run as root."
      echo "Exiting ..."
      exit 1
   else
      echo "[OK] This script is run by the root."
fi

echo "Testing the dependencies..."

if [dpkg-query -W -f='${Status}' dkms 2>/dev/null | grep -c "ok installed"] -eq 0; then apt update; apt install dkms; fi
if [dpkg-query -W -f='${Status}' gcc 2>/dev/null | grep -c "ok installed"] -eq 0; then apt update; apt install gcc; fi
if [dpkg-query -W -f='${Status}' make 2>/dev/null | grep -c "ok installed"] -eq 0; then apt update; apt install make; fi
if [dpkg-query -W -f='${Status}' perl 2>/dev/null | grep -c "ok installed"] -eq 0; then apt update; apt install dkms; fi
if [dpkg-query -W -f='${Status}' linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,') 2>/dev/null | grep -c "ok installed"] -eq 0; then apt update; apt install linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,'); fi

echo "[OK] All the dependencies are met. Good to go."

echo

echo 'Checking mount point...'
file1="/mnt/cdrom"
if [ ! -f "$file1" ]
	then
		echo "File $file1 does not exist."
		echo 'Creating the Mount point...'
		mkdir -pv /mnt/cdrom && echo '[OK] Mount point created ...'
	else
		echo "[OK] Mount point $file1 exists..."
fi

echo

echo 'Mounting the disk...'
mount -v /dev/sr0 /mnt/cdrom && echo '[OK] Disk Mounted ...'

echo

echo 'Installing the guest addition modules...'

echo

sh /mnt/cdrom/VBoxLinuxAdditions.run && echo '[OK] Guest additions installed ...'

echo

echo 'Umounting disk...'
umount -v /dev/sr0 && echo '[OK] Umount of disk is successful'

echo '[OK] Exiting the script ... Have a nice day! :) ... '

exit 1
Thankyou

Edit:
1. Corrections.
ThinkPad E14: Arch, Debian Stable
GUI: Xfce

For new: Try MX Linux, Linux Mint; later join Debian Stable

Post Reply