Skip to content

Instantly share code, notes, and snippets.

@norswap
Last active June 16, 2016 12:25
Show Gist options
  • Save norswap/611f38a76a00262c27dc72230a530124 to your computer and use it in GitHub Desktop.
Save norswap/611f38a76a00262c27dc72230a530124 to your computer and use it in GitHub Desktop.

As VirtualBox Guest

Networking

In the VM properties, make two connections: a "NAT" for regular internet connectivity, and a "host-only" for ssh connectivity between host and guest with a predictable IP. For this to work, both a NAT adapter and a host-only adapter have to be created in the host via the VirtualBox global preferences.

To connect via SSH, create a new network interface on the guest:

sudo nano /etc/network/interfaces

Add the following lines. You can pick another number for the last part of the address, but not 1 (which is the host). If you have multiple VMs, you should give them different numbers, or SSH will complain (even if they're not running concurrently).

# The VirtualBox host-only interface
auto eth1
iface eth1 inet static
    address 192.168.56.100
    netmask 255.255.255.0

Bring the interface up:

sudo ifup eth1

To ssh from the host (you can also add the the IP to your /etc/hosts file):

ssh <YOUR_USERNAME>@192.168.56.101

Shared Folders

In the VM properties, add a shared folder and select "auto-mount". "make permanent" should also be ticked in the option of the shared folder. This option is only visible when the VM is running.

With the VM running, insert the guest additions CD via the menu (this produces an error, but it seems to work okay afterwards), then do:

sudo mount /dev/cdrom /media/cdrom
sudo /media/cdrom/VBoxLinuxAdditions.run

!! You need to redo this when VirtualBox updates.

Reboot, and the shared folder will be mounted under /media/sf_<FOLDER_NAME>. To access it as a user, use sudo adduser <YOUR_USERNAME> vboxsf. You need to relog for changes to take effect.

You can create new shared folder while the VM is running. Mounting them is slightly tricky:

sudo mount -t vboxsf -o gid=vboxsf,group,dmode=0770,fmode=0770 <SHARE> <MOUNT_POINT>

Somehow, if dmode and fmode are not present to change the permissions on all directories/files, we won't be able to access the shared folder even though we are in the vboxsf group. In fact, what it does is dumbly copy the permissions from the host (on OSX at least), even though the users are of course not the same.

To enable creating symlinks in a VirtualBox shared folder on the guest side, run this on the host, as a single line:

VBoxManage setextradata <VM_NAME>
    VBoxInternal2/SharedFoldersEnableSymlinksCreate/<FOLDER_NAME> 1

In this case:

VBoxManage setextradata ubuntu VBoxInternal2/SharedFoldersEnableSymlinksCreate/shared 1

Note that on Mac OS X, forwarding of the locale by SSH causes problems. To fix the issue, add this to your .bash_profile:

export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment