All notes



Guest Additions

The Guest Additions are designed to be installed inside a virtual machine after the guest operating system has been installed. They consist of device drivers and system applications that optimize the guest operating system for better performance and usability.

The VirtualBox Guest Additions for all supported guest operating systems are provided as a single CD-ROM image file which is called VBoxGuestAdditions.iso.

To install the Guest Additions for a particular VM, you mount this ISO file in your VM as a virtual CD-ROM and install from there.

The features provided include:


For reference, find the "Host Key customization" section in VirtualBox manual.

Right Ctrl: HOME

With HOME+(Key), (Key) could be:


# Disable the full screen mode as well as the seamless mode
VBoxManage setextradata global GUI/Input/MachineShortcuts "FullscreenMode=None,SeamlessMode=None"

# Redefine or disable certain host key actions
VBoxManage setextradata global GUI/Input/MachineShortcuts "FullscreenMode=F,...."


Connect host directly to guest, host-only network

Host-Only networking is a good solution, which makes host and all the guests talk to each other. See Ubuntu Forum for installation guide. In short,

  1. Add a new host-only network. From the main menu, select File - Preferences (Ctrl+G) - Network - Host-only Networks, add a new host-only network, which is named as "vboxnet0" by default. WcfNOTE: NOT the settings of a single vm.
  2. Now add the host-only network for each guest VM.
  3. Ifconfig on both host and guest. By default, the new IP for host is, and guest starting from
  4. On host: ssh

Dynamic storage not allocated

On my archLinux guest OS, when I compiled with GCC, it complaint about not enough space. However, the virtual size is 16G which was enough while the actual size is 1.8G which was not. Create some big file to trigger the dynamic allocation of virtual box's VDI:

dd if=/dev/zero of=testFile bs=1M count="size in megabytes"

Install guest additions on CentOS


sudo yum install epel-release
sudo yum install dkms
sudo yum install gcc kernel-devel make

# reboot...
# Click Devices/Install Guest Additions...
# Mount the ISO image.

sudo mkdir /mnt/cdrom
sudo mount /dev/cdrom /mnt/cdrom

sudo /mnt/cdrom/

# Now the shared folder "virShare" could be found at:
ls /media/sf_virShare

# Always mount
mkdir ~/virShare
mount -t vboxsf virShare ~/virShare

Use arch as guest

arch wiki: virtualbox.

# dkms is preferred and recommended.
pacman -S linux-headers virtualbox-guest-dkms
# Another way is the modules directly.
# pacman -S virtualbox-guest-modules-arch

# Load the modules manually.
modprobe -a vboxguest vboxsf vboxvideo

# Install this. It will create a group vboxsf.
pacman -S virtualbox-guest-utils

# Add me to this group.
sudo usermod -aG vboxsf me

# Add the shared folder to guest.
sudo mount -t vboxsf -o ro,uid=1000,gid=1000 sharedName ~/works/

Networking network.

Port forwarding

VirtualBox listens to certain ports on the host and resends all packets which arrive there to the guest, on the same or a different port.

# All TCP traffic arriving on port 2222 on any host interface will be forwarded to port 22 in the guest.
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

# Direct from localhost:2222 to guest's 22.
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"

NAT service

VBoxManage natnetwork add --netname natnet1 --network "" --enable --dhcp on

# Add a DHCP server to the network after creation:
VBoxManage natnetwork modify --netname natnet1 --dhcp on
# To disable it again
VBoxManage natnetwork modify --netname natnet1 --dhcp off

# To start the NAT service
VBoxManage natnetwork start --netname natnet1
# Stop
VBoxManage natnetwork stop --netname natnet1
# Delete
VBoxManage natnetwork remove --netname natnet1

# Port-forwarding
VBoxManage natnetwork modify --netname natnet1 --port-forward-4 "ssh:tcp:[]:1022:[]:22"
# This adds a port-forwarding rule from the host's TCP 1022 port to the port 22 on the guest with IP address Host port, guest port and guest IP are mandatory.
# Delete
VBoxManage natnetwork modify --netname natnet1 --port-forward-4 delete ssh

# It's possible to bind NAT service to specified interface:
VBoxManage setextradata global "NAT/win-nat-test-0/SourceIp4"

# To see the list of registered NAT networks, use:
VBoxManage list natnetworks