Table of Contents

VirtualBox

Installation

apt-get install virtualbox

Auto start a virtual machine

Start a vm with

VBoxManage startvm <vm>

Shut down a virtual machine

Enter the following at Command::

VBoxManage controlvm <vm> acpipowerbutton

For this to work, you need to modify /etc/acpi/powerbtn-acpi-support.sh:

#!/bin/sh
/sbin/shutdown -h -P now "Power button pressed"

Alternatively, set up SSH access to all virtual machines and send the shutdown command through SSH.

Shared folders

Introduction

This explains how to share files and folders (directories) between host and guest. (Files are shared over a network, in other words, you access remote files. For virtual machines, the network between host and guest is virtual since they are on the same real machine. But the steps you take are similar to setting up file sharing over real networks.)

Required: Virtualbox Guest Additions

Before sharing folders, you must install the Guest Additions in the host, if they are not already installed.

# apt-get update
# apt-get install virtualbox-guest-additions-iso

Make sure the iso image will get mounted with exec options. To do this, modify the default fstab entry for the cdrom and add exec after user.

/dev/sr0   /media/cdrom0   udf,iso9660 user,noauto,exec   0   0

Check how your file systems are mounted with

cat /proc/mounts

Creating a shared folder

  1. Create a folder on the host that you would like to share, for example ~/VirtualShare
  2. Boot the Guest operating system in VirtualBox.
  3. Select Devices → Shared Folders…
  4. Choose the 'Add' button.
  5. Select ~/VirtualShare
  6. Optionally select the 'Make permanent', 'Auto mount', and 'Read only' options
  7. Reboot the guest system
  8. Access to the shared folder on /media/sf_VirtualShare
  9. Fix permissions to access the folder, for example for the apache user
    usermod -a -G vboxsf www-data

Prepare the folder

Linux

With a shared folder named share, the folder can be mounted as the directory ~/host with either of the following commands:

sudo mount -t vboxsf share ~/host # root only
sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) share ~/host # UID & root

Windows

On the Windows Guest, run

net use x: \\vboxsvr\share

Now anything placed in this folder should be visible from the host in the ~/share folder.

See HOWTO: Use Shared Folders

Troubleshooting

This can be done more generically with the following:

sharename="whatever.you.want.to.call.it"; 
sudo mkdir /mnt/$sharename
sudo chmod 777 /mnt/$sharename
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename
ln -s /mnt/$sharename $HOME/Desktop/$sharename

raw disks