https://www.virtualbox.org/manual/ch04.html#idp46691715827040
The VirtualBox Guest Additions for Linux are provided on the same virtual CD-ROM file as the Guest Additions for Windows described above. They also come with an installation program guiding you through the setup process, although, due to the significant differences between Linux distributions, installation may be slightly more complex.
Installation generally involves the following steps:
-
Before installing the Guest Additions, you will have to prepare your guest system for building external kernel modules. This works similarly as described in Section 2.3.2, “The VirtualBox kernel module”, except that this step must now be performed in your Linux guest instead of on a Linux host system, as described there.
Again, as with Linux hosts, we recommend using DKMS if it is available for the guest system. If it is not installed, use this command for Ubuntu/Debian systems:
sudo apt-get install dkms
or for Fedora systems:
yum install dkms
Be sure to install DKMS before installing the Linux Guest Additions. If DKMS is not available or not installed, the guest kernel modules will need to be recreated manually whenever the guest kernel is updated using the command
rcvboxadd setup
as root.
-
Insert the
VBoxGuestAdditions.iso
CD file into your Linux guest's virtual CD-ROM drive, exactly the same way as described for a Windows guest in Section 4.2.1.1, “Installation”. -
Change to the directory where your CD-ROM drive is mounted and execute as root:
sh ./VBoxLinuxAdditions.run
For your convenience, we provide the following step-by-step instructions for freshly installed copies of recent versions of the most popular Linux distributions. After these preparational steps, you can execute the VirtualBox Guest Additions installer as described above.
-
In order to fully update your guest system, open a terminal and run
yum update
as root.
-
Install DKMS and the GNU C compiler using
yum install dkms
followed by
yum install gcc
-
Reboot your guest system in order to activate the updates and then proceed as described above.
https://www.virtualbox.org/manual/ch04.html#sharedfolders
With the "shared folders" feature of VirtualBox, you can access files of your host system from within the guest system. This is similar how you would use network shares in Windows networks -- except that shared folders do not need require networking, only the Guest Additions. Shared Folders are supported with Windows (2000 or newer), Linux and Solaris guests.
Shared folders must physically reside on the host and are then shared with the guest, which uses a special file system driver in the Guest Addition to talk to the host. For Windows guests, shared folders are implemented as a pseudo-network redirector; for Linux and Solaris guests, the Guest Additions provide a virtual file system.
To share a host folder with a virtual machine in VirtualBox, you must specify the path of that folder and choose for it a "share name" that the guest can use to access it. Hence, first create the shared folder on the host; then, within the guest, connect to it.
There are several ways in which shared folders can be set up for a particular virtual machine:
-
In the window of a running VM, you can select "Shared folders" from the "Devices" menu, or click on the folder icon on the status bar in the bottom right corner.
-
If a VM is not currently running, you can configure shared folders in each virtual machine's "Settings" dialog.
-
From the command line, you can create shared folders using VBoxManage, as follows:
VBoxManage sharedfolder add "VM name" --name "sharename" --hostpath "C:\test"
See Section 8.29, “VBoxManage sharedfolder add/remove” for details.
There are two types of shares:
-
VM shares which are only available to the VM for which they have been defined;
-
transient VM shares, which can be added and removed at runtime and do not persist after a VM has stopped; for these, add the
--transient
option to the above command line.
Shared folders have read/write access to the files at the host path by default. To restrict the guest to have read-only access, create a read-only shared folder. This can either be achieved using the GUI or by appending the parameter --readonly
when creating the shared folder with VBoxManage.
Starting with version 4.0, VirtualBox shared folders also support symbolic links (symlinks), under the following conditions:
-
The host operating system must support symlinks (i.e. a Mac, Linux or Solaris host is required).
-
Currently only Linux and Solaris Guest Additions support symlinks.
-
For security reasons the guest OS is not allowed to create symlinks by default. If you trust the guest OS to not abuse the functionality, you can enable creation of symlinks for "sharename" with:
VBoxManage setextradata "VM name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/sharename 1
4.3.1. Manual mounting
You can mount the shared folder from inside a VM the same way as you would mount an ordinary network share:
-
In a Windows guest, shared folders are browseable and therefore visible in Windows Explorer. So, to attach the host's shared folder to your Windows guest, open Windows Explorer and look for it under "My Networking Places" → "Entire Network" → "VirtualBox Shared Folders". By right-clicking on a shared folder and selecting "Map network drive" from the menu that pops up, you can assign a drive letter to that shared folder.
Alternatively, on the Windows command line, use the following:
net use x: \\vboxsvr\sharename
While
vboxsvr
is a fixed name (note thatvboxsrv
would also work), replace "x:" with the drive letter that you want to use for the share, andsharename
with the share name specified withVBoxManage
. -
In a Linux guest, use the following command:
mount -t vboxsf [-o OPTIONS] sharename mountpoint
To mount a shared folder during boot, add the following entry to /etc/fstab:
sharename mountpoint vboxsf defaults 0 0
-
In a Solaris guest, use the following command:
mount -F vboxfs [-o OPTIONS] sharename mountpoint
Replace
sharename
(use lowercase) with the share name specified withVBoxManage
or the GUI, andmountpoint
with the path where you want the share to be mounted on the guest (e.g./mnt/share
). The usual mount rules apply, that is, create this directory first if it does not exist yet.Here is an example of mounting the shared folder for the user "jack" on Solaris:
$ id uid=5000(jack) gid=1(other) $ mkdir /export/home/jack/mount $ pfexec mount -F vboxfs -o uid=5000,gid=1 jackshare /export/home/jack/mount $ cd ~/mount $ ls sharedfile1.mp3 sharedfile2.txt $
Beyond the standard options supplied by the
mount
command, the following are available:iocharset CHARSET
to set the character set used for I/O operations. Note that on Linux guests, if the "iocharset" option is not specified then the Guest Additions driver will attempt to use the character set specified by the CONFIG_NLS_DEFAULT kernel option. If this option is not set either then UTF-8 will be used. Also,
convertcp CHARSET
is available in order to specify the character set used for the shared folder name (utf8 by default).
The generic mount options (documented in the mount manual page) apply also. Especially useful are the options
uid
,gid
andmode
, as they allow access by normal users (in read/write mode, depending on the settings) even if root has mounted the filesystem.
Starting with version 4.0, VirtualBox can mount shared folders automatically, at your option. If automatic mounting is enabled for a specific shared folder, the Guest Additions will automatically mount that folder as soon as a user logs into the guest OS. The details depend on the guest OS type:
-
With Windows guests, any auto-mounted shared folder will receive its own drive letter (e.g.
E:
) depending on the free drive letters remaining in the guest.If there no free drive letters left, auto-mounting will fail; as a result, the number of auto-mounted shared folders is typically limited to 22 or less with Windows guests.
-
With Linux guests, auto-mounted shared folders are mounted into the
/media
directory, along with the prefixsf_
. For example, the shared foldermyfiles
would be mounted to/media/sf_myfiles
on Linux and/mnt/sf_myfiles
on Solaris.The guest property
/VirtualBox/GuestAdd/SharedFolders/MountPrefix
determines the prefix that is used. Change that guest property to a value other than "sf" to change that prefix; see Section 4.7, “Guest properties” for details.Note
Access to auto-mounted shared folders is only granted to the user group
vboxsf
, which is created by the VirtualBox Guest Additions installer. Hence guest users have to be member of that group to have read/write access or to have read-only access in case the folder is not mapped writable.To change the mount directory to something other than
/media
, you can set the guest property/VirtualBox/GuestAdd/SharedFolders/MountDir
. -
Solaris guests behave like Linux guests except that
/mnt
is used as the default mount directory instead of/media
.
To have any changes to auto-mounted shared folders applied while a VM is running, the guest OS needs to be rebooted. (This applies only to auto-mounted shared folders, not the ones which are mounted manually.)