All notes
Virtualbox

Virtualbox

Concepts

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:

Shortcuts

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

Right Ctrl: HOME

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

Commandlines


# 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,...."

FAQ

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 192.168.56.1, and guest starting from 192.168.56.101.
  4. On host: ssh 192.168.56.101.

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

Ref.


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/VBoxLinuxAdditions.run

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

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

Networking

virtualbox.org: 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,127.0.0.1,2222,,22"

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

NAT service


VBoxManage natnetwork add --netname natnet1 --network "192.168.15.0/24" --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:[192.168.15.5]:22"
# This adds a port-forwarding rule from the host's TCP 1022 port to the port 22 on the guest with IP address 192.168.15.5. 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" 192.168.1.185

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