Accessing Mac OS X harddrive from Ubuntu in VirtualBox via shared folders
I installed Ubuntu in a VirtualBox machine on OS X (pretty easy and straightforward), but to access a Mac harddrive from Ubuntu was slightly more complicated.
Updated on January 19, 2011: updates based on helpful comments :) thanks
Updated on September 7, 2011: clearer instructions for the automatic mounting
Updated on January 3, 2012: please check also the last comments for the latests updates
I. Install Guest Additions
Firstly, it is necessary to install the VirtualBox’s Guest Additions to the host system:
-
Choose in the VitualBox’s menu:
Devices
->Install Guest Additions
…
It mounts a new ISO for the host system. -
A new CD appears in Ubuntu (or mount it). Run as root the
VBoxLinuxAdditions-x86.run
installation script (because it is an Intel based Mac) in a Terminal window:cd /media/cdrom sudo VBoxLinuxAdditions-x86.run
- Probably you will be asked to restart Ubuntu.
Installing the Guest Additions has many advantages such as adopting screen resolution (your window size is the system resolution, i.e. no scrollbars), easy mouse mode (no need to press the left command button to release the mouse cursor) and, what we are looking for, shared folders.
II. Create Shared Folder
The goal is to access a shared folder, what is an easier way than to use sshd or Samba.
-
Choose in the VitualBox’s menu:
Devices
->Shared Folders...
- Click on the Add new shared folder button.
-
Choose a Folder Path – a folder on your Mac harddrive, e.g.
/Users/ondrej/Pictures
.
Choose a Folder Name – a name that identifies this shared folder in Ubuntu (as a host system), e.g.pictures
.
Select Make Permanent – if you would like to persist this shared folder definition.
Click on OK. - Click OK to close the list of shared folders.
III. Mount Shared Folder
Mount the created shared folder into a folder with permissions for your user. Let’s open a Terminal window on Ubuntu and:
- Create a folder where will be the shared folder mounted. (Skip this step if have already a folder for this.)
mkdir DIR
e.g. (in
/tmp
)mkdir share
- Get your user
uid
:id
The result will be something like:
uid=1000(ondrej)gid=1000(ondrej)groups=4(adm),20(dialout),24(cdrom), 46(plugdev),112(lpadmin),119(admin),120(sambashare),1000(ondrej)
so uid of my user is 1000.
- Mount the shared folder
SHARED_FOLDER_NAME
into folderMOUNTED_FOLDER
with ownership for user with uidUSER_ID
as root:sudo mount -t vboxsf -o uid=USER_ID SHARED_FOLDER_NAME MOUNTED_FOLDER
e.g.
sudo mount -t vboxsf -o uid=1000 pictures /tmp/share
Specifying the
uid
parameter enables writing to the shared folder for your user. - The mounted folder
MOUNTED_FOLDER
(e.g./tmp/share
) contains files from the shared folder on your Mac harddrive. It is possible to write to the share folder as well. - Optionally, a shared folder can be automatically mounted on the virtual machine start.
Add the following line to the/etc/fstab
file (as root, e.g.sudo vim /etc/fstab
):SHARED_FOLDER_NAME /PATH/TO/MOUNTED/FOLDER vboxsf uid=1000,gid=1000 0 0
e.g.
pictures /tmp/share vboxsf uid=1000,gid=1000 0 0
where the
uid
andgid
values can be find in the output of theid
command (see the step 2 for detailed example).
The shared folder will be available also after a restart of the virtual machine.
Enjoy :)