Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active May 3, 2024 08:08
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save magnetikonline/1e7e2dbd1b288fecf090f1ef12f0c80b to your computer and use it in GitHub Desktop.
Save magnetikonline/1e7e2dbd1b288fecf090f1ef12f0c80b to your computer and use it in GitHub Desktop.
Install VirtualBox 6.1/6.0/5.2/5.1 guest additions on Ubuntu server guest.

Install VirtualBox guest additions onto Ubuntu server guests

Have tested these steps successfully with Ubuntu guest of:

  • 22.04LTS
  • 18.04LTS
  • 16.04LTS

using VirtualBox editions of 6.1, 6.0, 5.2 and 5.1 as host.

Install steps

  • Create Ubuntu server instance under VirtualBox (obviously).

  • Start VM, goto Devices - Insert Guest Additions CD image to mount the ISO image.

  • From the terminal, run the following commands:

     $ sudo su
     $ apt install gcc make
     $ mkdir --parents /media/cdrom
     $ mount /dev/cdrom /media/cdrom
     $ /media/cdrom/VBoxLinuxAdditions.run
     $ reboot
  • After reboot:

     $ modinfo vboxguest
     $ sudo usermod --append --groups vboxsf -- "$USER"
     $ cat /etc/group | grep "$USER"
  • Host shares should now be mounted in Ubuntu guest under /media via the installed VBoxService service, set to start on system boot-up.

  • All done.

Note: the above steps can be repeated on an existing VM image for guest addition upgrades, VBoxLinuxAdditions.run will handle the uninstall and reinstall process automatically.

Mount with guest/host permissions matched

By default with auto mounted shares, VirtualBox will set an interesting set of ownership and file/directory permissions for the guest which (for me at least) is sub-optimal.

To correct this behavior and correctly mirror permissions between host and guest we can do the following:

  • Shut down the guest (if not already) and ensure "Auto-mount" is disabled.

  • Restart the guest.

  • From the shell, determine the umask and uid/gid of the host user:

     $ umask
     0022
     $ id
     uid=1000(USERNAME) gid=1000(USERNAME) groups=1000(USERNAME),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)
  • Now mount the share as follows, inserting UMASK, UID, GID and SHARE_NAME:

     $ mkdir --parents /path/to/share
     $ sudo mount.vboxsf -o umask=UMASK,uid=UID,gid=GID SHARE_NAME /path/to/share
  • If this works, we can now add a permanent entry to /etc/fstab, again inserting UMASK, UID, GID and SHARE_NAME:

     SHARE_NAME /path/to/share vboxsf umask=UMASK,uid=UID,gid=GID 0 0
    
  • Remount all file systems

     $ sudo mount -a
  • All done.

Allow symlink creation for shared folders

By default symlink creation by a VirtualBox guest against a shared/host filesystem is not allowed. To unlock run the following:

$ vboxmanage setextradata VBOX_GUID VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARED_FOLDER_NAME 1

A list of active/valid VBOX_GUID's can be returned via:

$ vboxmanage list vms

Reference

@mosabua
Copy link

mosabua commented Oct 27, 2016

Or you could just do

apt-get install virtualbox-guest-utils

;-)

@magnetikonline
Copy link
Author

@mosabua you could, but that won't be the latest and greatest version of the Guest tools 😉

@bajosega
Copy link

bajosega commented Nov 1, 2017

Muchas Gracias !!.

@fibsifan
Copy link

fibsifan commented Feb 7, 2018

Will these additions automatically rebuild, if I upgrade to the latest and greatest version of the kernel? I have dkms installed, but I can't see the kernel modules there.

@magnetikonline
Copy link
Author

Not sure @fibsifan - from memory i've done kernel upgrades on VirtualBox Linux VM's and the disk sharing features did keep working - so I'll say "yes" 👍

@ekinsipahi
Copy link

or you could just mount the cd in and do ./autorun.sh inside that dir

@fibsifan
Copy link

@ekinmanyak123 autorun.sh depends on a graphical terminal like konsole or gnome-terminal afaik. This is usually not an option on a server system.

@mchikka1
Copy link

Just used the instructions for the "Install Steps" section above, works for Ubuntu 22.04 LTS server.

@magnetikonline
Copy link
Author

Champion - thanks @mchikka1 for reporting back 👍 I'll update the notes.

@mjakovina
Copy link

mjakovina commented Jul 21, 2023

Should simple copy/paste (of simple text) between host and giest work after this?
For me, it does not work (from Windows 10 host to Ubuntu 22.04 guest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment