Installing VirtualBox Guest additions using the command line

[Commands used were against VirtualBox version 4…]

Sometimes you don’t want to use a lot of disk space on your VirtualBox for install software or any ‘temporary’ need of space.

Adding shared folders from your host to your VirtualBox guest is a good option to use. If you have a Windows guest and a GUI based Host, it it’s very easy; click, click, done.

But if you are using a command line based guest and/or host, it a bit more complex. Use this post as a guideline, Linux knowledge is assumed…

Manually installing VBoxGuestAdditions [windows guest]

[host] # vboxmanage guestcontrol updateadditions "<vbox_name>" --source /usr/share/virtualbox/VBoxGuestAdditions.iso --verbose

To easy… from the host command line, the guest additions are installed automagically on the Windows host machine.

Manually installing VBoxGuestAdditions [linux guest]


0. Guest: Common Errors
1. Host: ‘Putting the Additions in the DVD drive’
2. Guest: Mount the DVD
3. Guest: Install Additions (in case of errors, see 0.)
4. Guest: Unmount the DVD

0. Common Errors: Make sure GCC, MAKE and KERNEL-DEVEL (headers) are installed…

[guest] # yum install gcc make <kernel-devel...>
(or similar package command for your distribution)

If not installed, you might run into next trouble:

[guest] # cat /var/log/vboxadd-install.log
Makefile:23: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again..  Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

To see what went wrong run ‘/etc/init.d/vboxadd setup’:

[guest] # /etc/init.d/vboxadd setup
Removing existing VirtualBox DKMS kernel modules           [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install <kernel-devel...>                              [FAILED]

Your system does not seem to be set up to build kernel modules.
Look at /var/log/vboxadd-install.log to find out what went wrong.
Once you have corrected it, you can run /etc/init.d/vboxadd setup to build them.
Doing non-kernel setup of the Guest Additions              [  OK  ]

Correct what went wrong and run ‘/etc/init.d/vboxadd setup’ again:

[guest] # yum install gcc make <kernel-devel...>
(yada yada yada)
[guest] # /etc/init.d/vboxadd setup
Removing existing VirtualBox DKMS kernel modules           [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Your guest system does not seem to have sufficient OpenGL support to enable
accelerated 3D effects (this requires Linux 2.6.27 or later in the guest
system).  This Guest Additions feature will be disabled.
Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
Starting the VirtualBox Guest Additions                    [  OK  ]

1a. Find the IDE Controller device numbers

[host] # vboxmanage showvminfo "<vbox_name>" | grep "Storage Controller Name"
 Storage Controller Name (0):            IDE controller

1b.Get the port and device numbers

[host] # vboxmanage showvminfo "<vbox_name>" | grep "IDE controller"
 IDE controller (1, 0): Empty

1c. If not found, add it

[host] # vboxmanage storagectl "<vbox_name>" --name "IDE controller" --add ide

1d. Attach the VBoxGuestAdditions.iso as dvddrive

Port and device numbers needed here!

[host] # vboxmanage storageattach "<vbox_name>" --storagectl "IDE controller" \
--port 1 --device 0 --type dvddrive \
--medium /usr/share/virtualbox/VBoxGuestAdditions.iso

2. Mount the DVD drive on Guest OS

[guest] # mkdir /mnt/dvd
[guest] # mount -t iso9660 -o ro /dev/dvd /mnt/dvd

3. Install VBoxLinuxAdditions

[guest] # cd /mnt/dvd
[guest] # ./

If you encounter errors here, see: ‘0. Common Errors‘.

4. Done? Unmount and remove

[guest] # umount /dev/dvd
[host] # vboxmanage controlvm "<vbox_name>" poweroff
[host] # vboxmanage storageattach "<vbox_name>" --storagectl "IDE controller" \
--port 1 --device 0 --type dvddrive --medium emptydrive

Uninstall VBoxGuestAdditions

[guest] # /opt/VBoxGuestAdditions-4.0.8/

Adding/removing shared folders to VirtualBox

Adding shared folders without a VirtualBox GUI is done like this, “vbox_name” is the name of your virtual machine, “–name install” is the name of the vboxsf name in the guest, “–hostpath /install” is the folder on your host system.

[host] # vboxmanage sharedfolder add "<vbox_name>" --name install --hostpath /install --automount
[host] # vboxmanage sharedfolder remove "<vbox_name>" --name install

On the guest it’s automounted to ‘/media/sf_install’, otherwise mount (again) with:

[guest] # mount -t vboxsf install /mnt/install

VirtualBox downloads

Done… Happy sharing!

Tagged , . Bookmark the permalink.

4 Responses to Installing VirtualBox Guest additions using the command line

  1. Pingback: Share folders with Virtual machine using Virtualbox « code's life

  2. Wolfgang Trinkwitz says:

    Hi Ian,
    – guest OS based on linuxmint-201303-mate-dvd-64bit.iso runs correctly
    – installing VBoxGuestAdditions does not work
    Unfortunately I was not so successful solving the problem.
    After having tested a lot of proposals without effort, I used the vboxmanage command above. The result seems to be the same as when I used the way via “Devices >> Install Guest Additions” in the running guest VM (see error messages attached).
    Forced unmount of the guest OS iso-file and performing the vboxmanage command again results in NO error messages, But the menus in the guest VM disappeared and the guest remains inaccessible for further actions.
    The only way seems to directly download the VBoxGuestAdditions_4.2.10 from “download/” and run, hoping that this works as using /usr/share/……?

    host: Kubuntu 12.04.1 64bit
    VBoxGuestAdditions.iso from /usr/share/virtualbox/VBoxGuestAdditions.iso

    result of vboxmanage as proposed above:.
    wolfgang@pcneu:~$ vboxmanage storageattach linuxmint-64 –storagectl IDE –port 1 –device 0 –type dvddrive –medium /usr/share/virtualbox/VBoxGuestAdditions.iso
    VBoxManage: error: Could not mount the media/drive ‘/usr/share/virtualbox/VBoxGuestAdditions.iso’ (VERR_PDM_MEDIA_LOCKED)
    VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Console, interface IConsole, callee nsISupports
    VBoxManage: error: Context: “MountMedium(Bstr(pszCtl).raw(), port, device, pMedium2Mount, fForceUnmount)” at line 731 of file VBoxManageStorageController.cpp

  3. Wolfgang Trinkwitz says:

    Hello Ian,

    Thank you for your reply.
    Obviously something went wrong during first installation of linuxmint as guest. The problem could be solved by a complete new installation of linuxmint and running manually using “devices >> install guestadditions – dialog” of VM.


Leave a Reply to Ian Hoogeboom Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.