# VirtualBox/Guest Additions/Ubuntu

Here we install the Guest Additions on an Ubuntu guest system running inside Virtualbox.
This chapter assumes you already have Ubuntu installed in a VirtualBox virtual machine, perhaps using the process described in VirtualBox/Setting up a Virtual Machine/Ubuntu.
(This was tested on Ubuntu Desktop 20.04 LTS as a guest in VirtualBox-6.1 on a Windows 10 host. Other versions and other hosts should work similarly.)
* Go back to the host operating system. At the top of the "testUbuntu20 [Running] - Oracle VM VirtualBox" window, choose Devices >> "Insert Guest Additions CD image..."
* (VirtualBox simulates inserting a CD into the simulated optical drive of the VM, and Ubuntu auto-mounts that CD under "/media/a/").
* When Ubuntu gives the "VBox... Would you like to run it?..." pop-up window, hit "run".
* Hey, remember that password we wrote on a sticky note earlier? Type it in and hit the Authenticate button.
* Ubuntu pops up a new terminal window and takes a minute to install and start up "VirtualBox Guest Additions".
** At this point, with a fresh Ubuntu 20.04 LTS install, it typically says "This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution." If that happens,
*** Inside the Ubuntu 20 VM, open up a terminal with Ctrl+Alt+T . Inside that terminal run: sudo apt update sudo apt install build-essential reboot (What is build-essential? see https://superuser.com/questions/151557/what-are-build-essential-build-dep )
**** (Earlier advice also recommended installing "dkms" and perl, but apparently that is no longer necessary).
**** (Earlier advice also recommended installing gcc and make, but apparently they are already included with build-essential).
*** When the VM starts up again, right-click the CD image on the desktop (if you don't see it, look in the left bar, at the bottom), and Eject.
*** Install the Guest Additions again from the beginning.
* When there are no errors and the last line of that terminal window says "Press Return to close this window...", click inside that window and press Return.
* Go back to the host operating system. At the top of the "testUbuntu20 [Running] - Oracle VM VirtualBox" window, most people find it convenient to enable Devices >> Shared Clipboard >> Bidirectional.
* Shut down the virtual machine from the tiny triangle icon in the upper right corner, the power icon, "Power Off" >> Power Off >> Power Off.
* Open up the Oracle VM VirtualBox manager. The "testUbuntu20" VM currently has the "Powered Off" icon, right? Select the VM, and hit the green arrow "start" icon.
* (Now when you look under "/media/a/", the "Guest Additions CD image" is still there -- do I need to do something to "take it out of the (virtual) drive"? If so, how?)
* (optional) To automagically resize the size of the virtual monitor to fill the "testUbuntu20 [Running] - Oracle VM VirtualBox" window whenever you stretch or shrink that window,
** At the top of the "testUbuntu20 [Running] - Oracle VM VirtualBox" window, choose View >> Auto-resize Guest Display.
** When you installed the Guest Additions (as described above), that option should have been enabled. There is apparently two separate bugs that can keep it greyed out even after installing the Guest Additions and rebooting:
** Some people suggest editing a "/etc/X11/xorg.conf" file, but that file apparently no longer exists in Ubuntu14.
** Some people suggest using apt-get to (re)install guest additions, uninstalling that version, and then re-install the guest additions again from the VirtualBox ISO:
*** Inside the virtual machine, open a terminal window and run "sudo apt-get install build-essential dkms virtualbox-guest-additions-iso". Hit "y" to continue.
*** Next, uninstall the guest additions: "sudo apt-get remove --purge virtualbox-guest-additions-iso". (We only installed it to pick up a bunch of dependencies; it's probably the wrong version for whatever version of VirtualBox you have running on your host).
*** At the top of the "testUbuntu14 [Running] - Oracle VM VirtualBox" window, choose Devices >> "Insert Guest Additions CD image..." and re-install it, as described above.
*** Reboot
*** wait a minute until the GUI desktop comes up
*** At the top of the "testUbuntu20 [Running] - Oracle VM VirtualBox" window, choose View >> Auto-resize Guest Display.

## References

* ↑ VirtualBox manual. "Guest Additions".
* ↑ Ask Ubuntu. "How do I install Guest Additions in a VirtualBox VM?".
* ↑ VirtualBox bug tracker. "Ticket #1591 (closed defect: fixed)": "auto-resize guest display is greyed out".
* ↑ "virtualbox resolution above 800x600".
* ↑ "Screen Resolution, VirtualBox Guest Additions, Ubuntu, and You".