Virtualbox

From 太極
Revision as of 10:35, 9 September 2019 by Brb (talk | contribs) (→‎Back up ova)
Jump to navigation Jump to search

Windows Host

Uninstall

Error In supR3HardenedWinReSpawn

I got this error when I installed Virtualbox 4.3.30 and 5.0.4 on my office Windows machine.

It may be caused by Anti-virus software. See http://superuser.com/questions/791352/virtual-box-error-after-creating-new-vm

It seems the error cannot be resolved on Windows machine. Try VMWare player.

The problem of cannot upgrading VirtualBox on my Windows desktop is I cannot run or import Windows 10 guest machines.

NOTE: I got the error when I try to install the guest addition on NIH computers. The solution is to run VirtualBox as an elevated account and then go to the Preferences to install the guest addition. After that, it works.

Ubuntu Host

http://www.ubuntugeek.com/virtualbox-4-3-8-released-and-ubuntu-installation-instructions-included.html

Upgrade from 5.2 to 6.0

Need to uninstall 5.2 extension pack and then uninstall Virtualbox.

Install 6.0 and then launch existing guest machines. It may complain USB compatibility. After disable USB, it works.

I also follow Install VirtualBox Extension Pack on VirtualBox 6.0 May 2019.

Install VirualBox using Oracle’s repository: automatic update

How to Install VirtualBox on Ubuntu [Beginner’s Tutorial]

Install virtual machines from non-root users

Yes, it works.

Install on a headless server, phpVirtualBox

Uninstall

sudo apt-get remove virtualbox-\*

Check if hardware (CPU) supports virtualization

egrep -c '(vmx|svm)' /proc/cpuinfo
  • If 0 it means that your CPU doesn't support hardware virtualization.
  • If 1 (or more) it does - but you still need to make sure that virtualization is enabled in the BIOS.

If your CPU does not supports hardware virtualization, you can only install 32-bit virtual machines (not 64-bit).

Virtualization in the host machine

Note that even the host machine is 64-bit, if the vT is not available/enabled in the BIOS, we cannot install 64-bit OS in the guest machine.

A caution about Ubuntu guest machine

Compiz

The regular Ubuntu OS uses 'compiz' which takes too much CPU power (50% to 100%) in virtual machine. Better to use others like xubuntu or lubuntu.

Language Pack

One step in the installation is to download language packs. It may a long time to do that. So it is better to hit the 'Skip' button once it is in this step.

VirtualBox guest addition

See http://www.virtualbox.org/manual/ch04.html for the instruction for different OS.

Installation In Ubuntu, Linux Mint, Debian And Fedora (updated for VB 6.0)

For any Linux guest machine, we need to install dkms package BEFORE installing guest addition.

sudo apt-get install virtualbox-guest-dkms

Virtualbox guest additions common errors

Virtualbox guest additions common errors. Eg for Permission denied, In /etc/fstab, change this: /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0 to this: /dev/sr0 /media/cdrom0 udf,iso9660 user,exec 0 0.

Debian

Install guest addition for virtualbox on Debian See an instruction here.

The instruction is helpful on Debian w/o a graphical desktop.

  1. Login as root; Or type 'su' and the required password to log in as root.
  2. Update your APT database with apt-get update;
  3. Install the latest security updates with apt-get upgrade;
  4. Install required packages with apt-get install build-essential module-assistant;
  5. Configure your system for building kernel modules by running m-a prepare;
  6. Click on Install Guest Additions… from the Devices menu. If the Debian has no graphical desktop, then run mount /media/cdrom0.
  7. Run sh /media/cdrom0/VBoxLinuxAdditions.run, and follow the instructions on screen.

We can check the extension pack version or if it was installed by going to the File -> Preferences -> Extensions.

Unfortunately the guest addition does not work with the current version of Debian (8.1.0) for some reason: Building the share folder support module fail!

Check installed Guest Additions version

modinfo vboxguest
# or
lsmod | grep -io vboxguest | xargs modinfo | grep -iw version

Centos

vi /etc/sysconfig/network-scripts/ifcfg-enp0s3  #  to set ''ONBOOT'' to yes.
yum -y install epel-release
yum install dkms
yum groupinstall "Development Tools"
yum install kernel-devel
# insert guest additions cd image and run Linux executable
# reboot

Reference: https://wiki.centos.org/HowTos/Virtualization/VirtualBox/CentOSguest

virtual machine software benchmark

Trouble Shooting

Forum

Software Rendering Mode

Shut down the Linux VM. Edit the VM settings in VirtualBox. Click "Display -> Enable 3D Acceleration".

Black screen or fuzzy screen

The problem happened when I installed Ubuntu 16.04 for example.

Try to increase the display memory and enable 3D (emulate GPU, useful for a Desktop instead of Server environment). ** But this has to be done before installing Ubuntu virtual machines. ** This post contains a screenshot of the problem and a different solution on Ubuntu 14. This post from http://askubuntu.com/ provides another solution.

Host+F1 and Host+F7 method works on my Ubuntu 16.04 and Lxle 16.04 guest. If my host is already Ubuntu, I want to use RightCtrl + F1 and RightCtrl + F7 to switch between the terminal and the graphical desktop (the fuzzy screen will disappear and the normal installation screen will appear). If my host is Windows OS, I can use Ctrl + Alt + F1 and Ctrl + Alt + F7 to switch.

Sometimes it is the grub menu problem. Press F6 and selected nomodeset.

Upgrade Difficulty

When it is impossible to find a solution for some unknown errors when installing a new build of VB, it is worthy to go back to install an old build of VB.

The old build & extension pack of VB can be downloaded from https://www.virtualbox.org/wiki/Download_Old_Builds.

For example, I always got an error 'supR3HardenedWinReSpawn'. The following screenshot shows an error when I tried to upgrade from v4.3.12 to v5.0

Vbox5.png

The log file shows something like

13d8.c54: supR3HardenedMonitor_LdrLoadDll: error opening 'C:\Windows\system32\wintab32.dll': 0 (NtPath=\??\C:\Windows\system32\wintab32.dll; Input=C:\Windows\system32\wintab32.dll)

The only solution is to install an old version of VB.

the headers of the current running kernel were not found

sudo apt-get install dkms build-essential linux-headers-$(uname -r)
dpkg --get-selections | grep linux-headers

For some reason when the above is run and /media/$USER/VBOXADDITIONS_w.x.y_z/VBoxLinuxAdditions.run is run, the header becomes old and we have to run it again to get new headers??

If this has not solved the problem, another try is to run

sudo apt-get install virtualbox-guest-dkms
# install dkms virtualbox-guest-utils virtualbox-guest-x11

See

Unfortunately the above methods do not solve the issue.

The only solution is to create the desired virtual machine (eg Ubuntu 14.04) on another host computer which has a newer version of Virtualbox and a working Guest Addition function. Then export the virtual machine from that host and import the virtual machine into my host with an old version of Virtualbox.

virtualbox failed to create the host-only network

Virtualbox (*.deb) was downloaded from virtualbox website. However, when I want to create a host-only network, I have to execute

sudo /etc/init.d/vboxdrv setup
sudo apt-get install dkms build-essential linux-headers-$(uname -r)

This also solves the error "Kernel driver not installed (rc=-1908)".

How To Fix “Kernel driver not installed (rc=-1908)” VirtualBox Error In Ubuntu 18.04.

Error 0x000000C4 & Windows 8.1 guest machine

The problem happened on my Xeon CPU Windows & Ubuntu machines, but not my Pentium cpu Ubuntu machine.

The solution is to run the following line (remove the path if it is run under Linux) first before installing Windows 8.1.

“c:\Program Files\Oracle\VirtualBox\VBoxManage.exe” setextradata “<Virtual Machine Name Here>” VBoxInternal/CPUM/CMPXCHG16B 1

Check the guest machine version

From the guest machine

ls /opt/
# VBoxGuestAdditions-5.0.10

/opt/VBoxGuestAdditions-5.0.10/bin/VBoxControl -v
# 5.0.14r105127

VERR_PDM_DEVHLPR3_VERSION_MISMATCH

Mismatch of the vbox and extension

Log file

$HOME/VirtualBox VMs/{machinename}/Logs. See Manual

No internet access on Centos guest machine

Follow Install a CentOS 7 Minimal Virtual Machine with VirtualBox and modify the file /etc/sysconfig/network-scripts/ifcfg-enp0s3 to set ONBOOT to yes.

Mac host

Error unsupported version 6 of data unit 'hda'

I use VB 5.1.x. When I upgrade VB to 6.0.4, I cannot open (Saved) Windows 10 virtual machine.

Solution 1: Use Import Appliance method. Solution (works!) 2. Downgrade VirtualBox to 5.2.x or 5.1.x.

Use VirtualBox

Host key

Right control key. It is shown on the right bottom corner of the virtual machine.

Download virtual disk images

The 3 Best Sites to Download Virtual Disk Images for VirtualBox

Hard disk file type & splitting

Difference of file types really only matters if you're planning to use the same virtual hard disk with another virtualization provider.

You can switch to the Expert mode where it allows to split the image into files of less than 2GB (VMDK file type only). It seems splitting has an advantage for backing up and also for the FAT32 partition/network share file size restriction. As for performance, splitting has no advantage.

See Should I split VMware virtual disk into multiple files or not?

VDI (virtual disk image)

Default

VHD (virtual hard disk)

Used by Microsoft VirtualPC

VMDK (virtual machine disk)

Used by VMWare.

How to Open a VMDK File in VirtualBox

HDD

Compatibility with Mac parallels.

QCOW

QEMU Copy-On-Write

QED

QMU enhanced disk

How to Convert Between Fixed and Dynamic Disks

https://www.howtogeek.com/312456/how-to-convert-between-fixed-and-dynamic-disks-in-virtualbox/

Virtual networks

See diagrams on https://blogs.oracle.com/fatbloke/entry/networking_in_virtualbox1

  1. NAT: Network Address Translation (NAT) service works in a similar way to a home router. It groups systems using it into a network and prevents outside systems from directly accessing those inside, while letting systems inside communicate with each other and outside systems using TCP and UDP over IPv4 and IPv6.
  2. Bridge
  3. Host Only: Host can access guest, but not the other direction. Outside cannot access guests. Good for running a test web server.
  4. Internal Network: Guests can access each other but host still cannot access guests. This is good for testing when you need a separate, clean network, and you can create sophisticated internal networks with vm's that provide their own services to the internal network. (e.g. Active Directory, DHCP, etc).

Speed consideration

  • Bridged adapter connection is faster than the default (NAT) network. See p25 here.

Host-Only

First of all, click File > Host Network Manager... Click the 'Create' button to create a new network. By default, its name is "vboxnet0", IPV4 Address/Mask is 192.168.56.1/24 and DHCP Server is enabled. Now the name "vboxnet0" will appear in the "Name" of the dropdown list of the Host-only Adapter.

The 'Adapter' tab has the following values

  • IPv4 address: 192.168.56.1 (seen from running 'ifconfig' in the host machine)
  • IPv4 network mask: 255.255.255.0

The 'DHCP Server' tab has the following values

  • check Enable Server
  • Server Address: 192.168.56.100
  • Server mask: 255.255.255.0
  • Lower address bound: 192.168.56.101
  • Upper address bound: 192.168.56.254

Note that the virtual machine can ALWAYS ssh to the host by ssh [email protected] even though the ifconfig command does not show 192.168.56.* address. But if host-only is enabled in the VM, host can ssh to VM.

To create a static IP on the guest machine, modify /etc/network/interfaces so it looks like (Hint: use ip add to check the ip information)

auto enp0s3
iface enp0s3 inet static
address 192.168.56.5
network 192.168.56.0
netmask 255.255.255.0
dns-nameservers 8.8.8.8 192.168.56.1

If I repeatly create & delete a VM with a host-only network, I found the IPV4 may be missing from the VM. I play a trick by adding another network which solved the problem.

Articles how to make use of host-only network

Internal Network

The Ip address for internal network is ipv6 (at least seen from Ubuntu guest machine).

inet6 addr: fe80::a00:27ff:fecb:966c/64

We can test it by pinging it from another machine (say Windows). Note that even it first shows Destination host unreachable, the 3 replies lines shows the pinging is successful.

C:\Users\brb>ping fe80::a00:27ff:fecb:966c

Pinging fe80::a00:27ff:fecb:966c with 32 bytes of data:
Destination host unreachable.
Reply from fe80::a00:27ff:fecb:966c: time=1ms
Reply from fe80::a00:27ff:fecb:966c: time<1ms
Reply from fe80::a00:27ff:fecb:966c: time<1ms

Ping statistics for fe80::a00:27ff:fecb:966c:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms


C:\Users\brb>netstat -rn
===========================================================================
Interface List
 20...08 00 27 62 8c 1c ......Intel(R) PRO/1000 MT Desktop Adapter #2
 11...08 00 27 86 6d 29 ......Intel(R) PRO/1000 MT Desktop Adapter
  1...........................Software Loopback Interface 1
 12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
 13...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
 14...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0         10.0.2.2        10.0.2.15     10
         10.0.2.0    255.255.255.0         On-link         10.0.2.15    266
        10.0.2.15  255.255.255.255         On-link         10.0.2.15    266
       10.0.2.255  255.255.255.255         On-link         10.0.2.15    266
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
      169.254.0.0      255.255.0.0         On-link    169.254.200.31    266
   169.254.200.31  255.255.255.255         On-link    169.254.200.31    266
  169.254.255.255  255.255.255.255         On-link    169.254.200.31    266
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link         10.0.2.15    266
        224.0.0.0        240.0.0.0         On-link    169.254.200.31    266
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link         10.0.2.15    266
  255.255.255.255  255.255.255.255         On-link    169.254.200.31    266
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    306 ::1/128                  On-link
 11    266 fe80::/64                On-link
 20    266 fe80::/64                On-link
 20    266 fe80::28f6:df10:9926:c81f/128
                                    On-link
 11    266 fe80::48bc:2c38:765d:f88f/128
                                    On-link
  1    306 ff00::/8                 On-link
 11    266 ff00::/8                 On-link
 20    266 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

Network Adapter Types

The default is 'PCnet-PCI II'. Change to other adapter type like 'PCnet-FAST III' or 'Paravirtualized Network (virtio-net)'. See this post

Share folders

Suppose we want to share some folder from host to guest. Assume in Virtualbox, we use "Downloads" as the folder name in Share Folders dialog.

It is best to change the share folders settings when the guest machine is off. Otherwise we still need to restart the machine for the change of settings to be effective. The shared folder is under /media/ (just like external USB drive) with sf_ as prefix.

Method 1: Use Auto-mount option built in VirtualBox. But I get a permission denied error (This location could not be displayed). The reason is the shared folder is mounted with 770 permissions with root user and vboxsf as the group. We can switch to root user to access the folder (sudo su) or we can add the current user to vboxsf group by using the usermod command.

sudo usermod -aG vboxsf $USER
# OR
sudo adduser $USER vboxsf

Then reboot the system.

We can then use

id USERNAME

to verify you are in the vboxsf group.

Method 2: (Manual mount) We can use the following method to get an access to Downloads folder for this session only. See also howtogeek.com.

sudo mkdir /mnt/Downloads
# Suppose we use the VirtualBox's Settings to add a new shared folder called 'Downloads' which
# will be accessed from an existing directory /media/downloads. 
sudo mount -t vboxsf Downloads /mnt/Downloads

Method 3: We can use the following method for a permanent solution (why do we want to do that since Method 1 works well already).

sudo nano /etc/fstab
sudo mkdir /mnt/Downloads
# Add a new line
# Downloads /mnt/Downloads/ vboxsf defaults 0  0  
sudo mount -a

PS: There is a bug in virtualbox 4.3.10 which results an error

mount: wrong fs type, bad option, bad superblock on hostshare,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail or so

The solution is to run

sudo rm /sbin/mount.vboxsf
sudo ln -sf /usrs/lib/x86_64-linux-gnu/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf

Windows guest machine + file sharing

In the File Explorer, one needs to check 'Turn on network discovery and file sharing' in order to use see the shared folder in the File Explorer (called File sharing in Windows). The shared folder is under Network > VBOXSVR directory.

Limitations

If we try to extract a tarball containing symbolic links files to a shared folder (mounted external drive formatted as an EXT3 partition or even one folder from the host machine running Ubuntu), these files cannot be extracted to the shared folder.

2nd hard drive

For some applications on Windows guest machines, the share folder does not work. We need to create a 2nd hard drive.

Create another SATA vdi is easy in virtual machine's setting. After it is created, go to the Administrative Tools -> Computer Management -> Disk Management to format it for use in Windows.

Seamless mode

If we want to run the app from guest machine on host machine (to hide the guest machine desktop) so the app looks like from the host machine, we can head to View->Switch to Seamless Mode in VirtualBox.

Snapshots

If we are installing a sketchy program, we can take a snapshot, install the program, then revert to your snapshot if things go wrong.

http://www.howtogeek.com/150258/how-to-save-time-by-using-snapshots-in-virtualbox/

Create a snapshot

  1. Create a clean machine.
  2. There are two ways:
    • (When the VM is off) Switch from 'Details' to 'Snapshots' on the right-hand side of the VB window. Right click 'Current State' and click 'Create Snapshot'.
    • (When the VM is on) Machine > Take a snapshot. Give it an intuitive name and description. Shutdown the current machine (This seems to be a good practice every time after we create a VM).

After we open an original snapshot and do not nothing, when we shutdown the VM, the VM status is 'changed'.

Restore a snapshot

  1. Select the Virtual machine from the list and switch over to the snapshots view (top-right corner). Right click a snapshot and choose 'Restore snapshot'. Uncheck the option of 'Create a snapshot of the current machine state'. Click 'Restore'.
  2. You should see the "Current State(changed)" will become "Current State" the same as the snapshot you selected to restore to.
  3. If we have a snapshot called original at the top, and a child snapshot, then running restore a snapshot on the root will move the "Current State" from under the child snapshot to the root snapshot. That is we have two children snapshots now (one of them is 'Current State').

Note that

  • There is only one 'Current State' no matter how many snapshots we have created.
  • If we stop the mouse at any snapshot and double click to run the VM, it still pick the 'Current State' to run. The title bar on the virtual machine will show which snapshot it is running.
  • When we right click 'Restore snapshot' and choose 'Create a snapshot of the current machine', it will create a snapshot under the image we have selected. See the next plot

VBoxsnapshot1.png

  • If we run the VM on snapshot1 and use apt-get to install eg gfortran package, the current state will be changed. Now if we shutdown the machine and right click 'Restore snapshot' & check 'Create a snapshot of the current machine state'. A snapshot named 'Snapshot 2' will be created nested under 'Snapshot 1'.

VBoxSnapshot.png

  • Again if we run the VM (may be through right click 'Restore Snapshot' if we want to run the VM based on a specific snapshot), the title bar on the virtual machine will show which snapshot it is based on. For example, if the Current State is nested under 'Snapshot 1', then the image is based on 'Snapshot 1'.

VBoxsnapshot2.png

  • If we do not try to take snapshot on 'Current State', anything we have done on a 'Current State' based on whatever snapshot could be lost after the VM is shutdown.

Clone

It will give an option of 'Full Clone' and 'Linked clone'. After that, it will give an option to choose which parts of the snapshot tree should be cloned with the machine: 'Current machine state' and 'Everything'.

See the screenshots.

Clone vs Import/Export appliance

Clone will create a new VM directory (including *.vdi) on the same machine.

Import/Export appliance (*.ova) allows to transport the appliance to a new machine.

  1. The appliance will not be touched on the new machine.
  2. The storage space cannot be adjust when we import an appliance.
  3. The .ova file can be opened in VMware Play.

Export to ova vs ovf

  • ova file is only 1 file. This will create a problem when we want to back up or transfer a large ova file. OVA is a tar archive containing the OVF package files.
> tar xvf my.ova
my.ovf
my.mf
my.vmdk
  • ovf: several files will be written. An OVF is a collection of items in a single folder. Most commonly this is a description file (.ovf) a manifest file (.mf), and virtual machine state files (*.vhd or *.vmdk). These files must then reside in the same directory for VirtualBox to be able to import them. PS. vmdk file is about the same size of ova. So the ovf method has no advantage over ova.

Back up ova

vboxmanage list vms

# export
vboxmanage export UBUNTUSERVER164 -o ubuntu_server_new.ova
# import
vboxmanage import ubuntu_server_new.ova

Import vmdk

How to Open a VMDK File in VirtualBox. Note: if you move the location of the VMDK file the VirtualBox machine will no longer boot until the VMDK file is located again.

Clonezilla: Transfer the VM to an actual computer

Install Ubuntu with Clonezilla & VirtualBox pp23-25.

Take the VDI file and decompress it into a directory. The files need to be transferred to the target computer.

Clonezilla allows us to boot up a system to be cloned and then make a copy/image of its hard drive (virtual machine in our case).

Once the image has been made, the target computer can be boot up from Clonezilla and the image restored to the target hard drive.

Some experiences:

  • On my lenovo lynx tablet, Clonezilla only shows its figure without texts.
  • On my hp stream 8 tablet, Clonezilla does not take 'Enter' key when I use my Anker's wireless keyboard.

Change screen resolution

VBoxManage controlvm "Your VM" setvideomodehint 1366 768 32  # inexpensive tablets, chromebooks, notebooks
VBoxManage controlvm "Your VM" setvideomodehint 1280 800 32       
VBoxManage controlvm "Your VM" setvideomodehint 1280 960 32

See Screen resolution? Aspect ratio? What do 720p, 1080p, 1440p, 4K and 8K mean? for a list of some common screen resolutions.

  • 4:3 aspect ratio resolutions: 640×480, 800×600, 960×720, 1024×768, 1280×960, 1400×1050, 1440×1080 , 1600×1200, 1856×1392, 1920×1440, and 2048×1536.
  • 16:10 aspect ratio resolutions: - 1280×800, 1440×900, 1680×1050, 1920×1200 and 2560×1600.
  • 16:9 aspect ratio resolutions: 1024×576, 1152×648, 1280×720, 1366×768, 1600×900, 1920×1080, 2560×1440 and 3840×2160

Take a screenshot

  • Method 1. Use 'snipping tool' in Windows 7 to make a screenshot of a desired region to a clipboard. When the 'New' button is clicked, the whole Windows desktop will be less clear. Users can use the mouse to select a region. When we select a rectangle region, the region will become clear. After we release the mouse, the region will be shown on the snipping tool application. In fact, the region will also be on Windows clipboard. So if the VirtualBox has enabled shared clipboard for both directions, we can access the clipboard on Ubuntu host OS.
  • Method 2. Use the command line in the host machine to take a screenshot of the whole guest OS. See http://www.dedoimedo.com/computers/virtualbox-screenshot.html
VBoxManage controlvm <VM_NAME> screenshotpng <FILENAME>

To copy the image to the clipboard, I open the file in gthumb program. Then using Edit -> Copy the image to copy the image to the clipboard. If I leave the gthumb program open, it will update the image when I use the same file name to make a new screenshot on the command line.

  • Method 3. Use the keyboard short Host + E in the VirtualBox. It will ask a file name to save the screenshot. Not that convenient if my purpose is to copy the image to the clipboard.

Port forward

If you’d like to run server software inside a virtual machine, you’ll probably want to set up port forwarding so the server software is reachable from outside of the virtual machine. You’ll find this option in the Network settings pane, under Advanced.

If we change to use the 'Bridged' network, we don't need to use port forward. We use 'port forward' if we use the default 'NAT' network.

  1. GUI method: http://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/
  2. Command line method: http://www.linuxjournal.com/content/tech-tip-port-forwarding-virtualbox-vboxmanage.
$ # Set up incoming NAT connections to an ssh server in the guest; 
$ # 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"
$ # The number after --natpf denotes the network card
$ # The name guestssh is purely descriptive and will be auto-generated if omitted.
$
$ # To remove this forwarding rule again
$ VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"

There are some limitations of NAT port forwarding. For example, forwarding host ports lower than 1024 impossible. See section 6.3.3 on the VirtualBox Manual for more information.

Mouse in virtual consoles (not desktop environment)

How To Configure Mouse Support For Linux Virtual Consoles

Remote Desktop Connection

Guest: ubuntu 14.04. Client: Windows/Ubuntu

Method 1: use guest machine IP. (not preferred)

  1. Make sure the guest machine has a bridge network. In my case, my host machine is using a wireless adapter so I pick Name='wlan0' in the Adapter2. The 'ipconfig' command shows my eth1 adapter has an address 192.168.1.244.
  2. The guest machine needs to install vnc software. On my ubuntu 14.04 Unity, I follow the instruction on this to install xrdp, xfce4 and others.
  3. On the Virtual machine -> Settings -> Display -> Remote Display, check the option 'Enable Server' and click OK. (note that the port number is 3389).
  4. On my Windows desktop, open Remote Desktop Connection client (mstsc.exe), type 192.168.1.244:3389 and then in the next screen type the username and password of the Ubuntu 14.04.

We shall be able to see the xfce4 desktop on Windows machine.

Method 2: use host machine IP.

nmap command shows port 3389 is open on the host machine.

So both the guest machine and Windows client can control the same desktop.

For some reason, method 1 stopped working. However, if I use the host machine ip and port 3389 to connect. I will see the exact desktop environment (Unity) as the guest machine.

I can also test the connection from the Ubuntu host machine. In Remmina, I type localhost:3389 with username/password. It works. Note that the Protocol has to be RDP - Remote Desktop Protocol; VNC will not work.

One problem I met is I got a message Because of an error in data encryption, this session will end. Please try connecting to the remote computer again. after a while.

Increase the guest machine space

Boot virtual machines from USB drives

http://www.howtogeek.com/187721/how-to-boot-from-a-usb-drive-in-virtualbox/

Start virtual machine when the system boots up

Windows guest machine screen/display resolution

The available selection of the display resolution:

  • 1600 x 1200 (win10)
  • 1280 x 1024 (win10)
  • 1152 x 864
  • 1024 x 768
  • 800 x 600 (win7)

Fix Virtualbox Windows HiDPI Mac Retina Display Blurry Text

Hackintosh

PCI passthrough via OVMF

It is now possible to pass through a graphics card using qemu and KVM. It offers the VM native graphics performance which is useful for graphic-intensive tasks. See https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF

Manage virtual machines

VBoxManage

VBoxManage list

# list all virtual machines
VBoxManage list vms 

# lists all currently running virtual machines
VBoxManage list runningvms 

# displays all VirtualBox extension packs currently installed
VBoxManage list extpacks

VBoxManage createvm

This command creates a new XML virtual machine definition file.

VBoxManage startvm

This command starts a virtual machine that is currently in the "Powered off" or "Saved" states

VBoxManage startvm <vm>

VBoxManage controlvm

VBoxManage controlvm <vm> savestate # Use VBoxManage startvm <vm> to start up again

VBoxManage controlvm <vm> acpipowerbutton

VBoxManage controlvm <vm> poweroff

VBoxManage showvminfo

VBoxManage showvminfo "Windows XP"

VBoxManage modifyvm

This command changes the properties of a registered virtual machine which is not running.

vagrant

Vagrant boxes

Why vagrant

Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.

To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.

Tested on an Ubuntu host machine

$ sudo dpkg --install vagrant_1.7.1_x86_64.deb 
[sudo] password for mli: 
Selecting previously unselected package vagrant.
(Reading database ... 209831 files and directories currently installed.)
Unpacking vagrant (from vagrant_1.7.1_x86_64.deb) ...

$ vagrant init hashicorp/precise32  # No 'sudo' is needed
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

$ cat Vagrantfile

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise32' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise32'
    default: URL: https://atlas.hashicorp.com/hashicorp/precise32
==> default: Adding box 'hashicorp/precise32' (v1.0.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/hashicorp/boxes/precise32/versions/1.0.0/providers/virtualbox.box
==> default: Successfully added box 'hashicorp/precise32' (v1.0.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: Downloads_default_1420231386363_57276
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /home/mli/Downloads

$ vagrant destroy

More

$ vagrant box add ubuntu/trusty64
$ vagrant up
$ vagrant ssh
$ vagrant destroy
$$ ls /vagrant

# Web server
$ nano bootstrap.sh
$ nano Vagrantfile # add provision
$ vagrant --provision
$ vagrant ssh
$ nano Vagrantfile # add port forward
$ vagrant reload

# Share
$ vagrant login
$ vagrant share
Ctrl + C

# Teardown
$ vagrant suspend
$ vagrant halt
$ vagrant destroy

# Provider
$ vagrant up --provider=vmware_fusion

Install on a Windows machine

Note: If we want to use Vagrant with Virtualbox, we need to install Virtualbox separately. Vagrant does not include Virtualbox in its installer. Vagrant's installer (~150MB) only installs itself.

Go to the Download page to download Windows version (no separate 32 or 64-bit versions). The program will be installed onto C:\HashiCorp directory.

I can install Virtualbox and Vagrant on a virtual Windows 7 guest machine. This is a great advantage of vagrant over docker in that I cannot run (installation is fine) dock2boot on a Windows 7 guest machine (Docker requires a real Windows to work). But it is perfect OK to install and run docker on an Ubuntu guest machine.

After installing virtualbox & vagrant, vagrant will be available on a global environment. That said, we can open a command window and start to run 'vagrant'.

C:\Users\brb>vagrant init hashicorp/precise32
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

C:\Users\brb>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: brb_default_1421961025717_91472
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
...
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/brb

C:\Users\brb>
C:\Users\brb>vagrant ssh
`ssh` executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use your favorite SSH client with the following
authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/brb/.vagrant/machines/default/virtualbox/private_key

C:\Users\brb>

The next step is to use Putty to connect to the virtual machine. We can follow the instruction at https://github.com/Varying-Vagrant-Vagrants/VVV/wiki/Connect-to-Your-Vagrant-Virtual-Machine-with-PuTTY. However, the private key used for conversion is not the one as described in the article. We should uses the private key indicated in the above message (C:/Users/brb/.vagrant/machines/default/virtualbox/private_key in this case).

Note that when we run 'vagrant up', we will see a new VM was created in VirtualBox and once we run 'vagrant destroy', the VM will be deleted.

If we run 'vagrant destroy' and then 'vagrant up' again, the old private key will not work in the new guest machine.

Sharing a Windows/host folder in Vagrant vm

See the tutorial video on youtube. In this example, an apache is created in vm. The goal is to install Apache in the vm and use a folder on Windows/host system as the DocumentRoot.

First we edit Vagrantfile, uncomment 'config.vm.network' line, and modify ip as anything you want. After we modify Vagrantfile, we can issue 'vagrant reload' to make the change effective immediately.

Now use 'vagrant ssh' to ssh to the vm and install apache2, ... and start apache2.

The interesting thing is if we create a new subfolder (/vagrant/www) in the vm, this folder will appear in the Windows/host system as well. If we change /etc/apache2/sites-available/default file AND modify DocumentRoot to /vagrant/www, <Directory> to /vagrant/www, and AllowOverwrite to None, we will be able to use the www subdirectory from the Windows/host system as the DocumentRoot for the Apache in the vm.

Use vagrant with Docker (instead of VirtualBox) provider

Use vagrant to run a VM remote desktop with desktop environment

How to setup a LAMP/Web Stack development environment

However, I got an error complaining password in the configuration. See this post for help. A simple way to get rid of the error is to comment out the username and password lines.

The post tells us 1) how to create a lamp server using Vagrantfile and a shell script, 2) how to save the box for future use.

The <Vagrantfile> file looks like

Vagrant.configure(2) do |config|
config.vm.box = "precise32"
  # Mentioning the SSH Username/Password:
  # config.ssh.username = "vagrant"
  # config.ssh.password = "vagrant"
  # Begin Configuring
  config.vm.define "lamp" do|lamp|
    lamp.vm.hostname = "lamp" # Setting up hostname
    lamp.vm.network "private_network", ip: "192.168.205.10" # Setting up machine's IP Address
    lamp.vm.provision :shell, path: "script.sh" # Provisioning with script.sh
  end
end

and the <script.sh> file looks like

#!/bin/bash

# Updating repository
sudo apt-get -y update

# Installing Apache
sudo apt-get -y install apache2

# Installing MySQL and it's dependencies.
# Also, setting up root password for MySQL as it will prompt to enter the password during installation
sudo debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password password rootpass'
sudo debconf-set-selections <<< 'mysql-server-5.5 mysql-server/root_password_again password rootpass'
sudo apt-get -y install mysql-server libapache2-mod-auth-mysql php5-mysql

# Installing PHP and it's dependencies
sudo apt-get -y install php5 libapache2-mod-php5 php5-mcrypt

We can verify the apache is working by browsing the address http://192.168.205.10. Note that the host-only network IPv4 address is 192.168.205.1 (not sure if this is coincidence).

Configuring a single Ubuntu installation as a dual-boot option and a VirtualBox appliance

https://www.howtoforge.com/tutorial/configuring-a-single-ubuntu-installation-as-a-dual-boot-option-and-a-virtualbox-appliance-under-windows-10/

OSBoxes

OSBoxes provides ready-to-use VirtualBox/VMware Linux/Unix guest operating systems

Security

10 new VM escape vulnerabilities discovered in VirtualBox

Meltdown & Spectre

  • After I upgrade the kernel to 4.4.0-109-generic & install the latest VirtualBox (5.2.6) on Ubuntu 16.04, VB cannot be launched
brb@t420s:~$ virtualbox
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (4.4.0-109-generic) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

         You will not be able to start VMs until this problem is fixed.

The error has been reported. https://bugs.launchpad.net/linuxmint/+bug/1742832

Other visualization software

Hypervisor/Virtual machine monitor

There are two types of Hypervisor (wikipedia)

  1. Type 1: native or bare-metal hypervisors. These hypervisors run directly on the host's hardware to control the hardware and to manage guest operating systems. Examples include Oracle VM Server for SPARC, Oracle VM Server for x86, the Citrix XenServer / XenClient, VMware ESX/ESXi and Microsoft Hyper-V 2008/2012.
  2. Type 2: hosted hypervisors. These hypervisors run on a conventional operating system just as other computer programs do. Type-2 hypervisors abstract guest operating systems from the host operating system. VMware Workstation and VirtualBox are examples of type-2 hypervisors.

However, the distinction between these two types is not necessarily clear. Linux's Kernel-based Virtual Machine (KVM) and FreeBSD's bhyve are kernel modules[1] that effectively convert the host operating system to a type-1 hypervisor. At the same time, since Linux distributions and FreeBSD are still general-purpose operating systems, with other applications competing for VM resources, KVM and bhyve can also be categorized as type-2 hypervisors.

See also the youtube videos Hyper-V Course from itfreetraining.

Red Hat Enterprise 7.3

支援OpenStack與container,紅帽推出第4代商用KVM

KVM vs. Xen vs. VirtualBox Virtualization Performance

QEMU

KVM: Kernel-based Virtual Machine

sudo apt-get install qemu-kvm libvirt-bin virt-manager virt-viewer

Xen

Xen for Beginners from youtube

This article compares KVM and Xen. Xen is more difficult compared to KVM thought it is technically superior to KVM.

What virtualization software does Amazon use

Amazon Elastic Compute Cloud (EC2) uses Xen virtualization according to wikipedia.

What hypervisor software does Google Compute Engine use

Google Compute Engine uses KVM as the hypervisor according to wikipedia.

VMware vSphere bare-metal Hypervisor/ESXi (free)

Trouble shooting

VMware Player

Download

After experiencing frustration with upgrading Virtualbox on Windows host, I decide to use Vmware player.

The download link is here.

The installation does not require an admin right. It does require an email when the program is launched the first time (non-commercial use). I am testing VMware-player-12.0.0-2985596.exe (70MB) released on 2015-08-24.

The default virtual machine location is C:\Users\$USERNAME\Documents\Virtual Machines\ while my favorite location is E:\Virtual Machines\ from the VirtualBox.

I can click an .ova file exported from VirtualBox in order to import it to VMware player. Importing ova does take a long time.

Note only the pro version can (comparison)

  • Export to ova
  • Map virtual disks
  • Advanced CPU settings
  • Snapshot

Release mouse cursor from VM

Ctrl + Alt.

VMware tools

This is like VirtualBox guest additions. It is mounted on a DVD drive. We need to run setup.exe or setup64.exe to install it.

Once VMware tools is installed on the guest machine, go to Manage -> Virtual Machine Settings.

What is working:

  • the screen resolution is adjustable
  • share folder function is working.
  • copy/paste (automatical)
  • number of cpu (need to change when the os is off)
  • memory (need to change when the os is off)

Install Vmware tools in Ubuntu guest

Instruction for Ubuntu 14.04

sudo apt-get update
sudo apt-get install build-essential module-assistant
sudo m-a prepare
cd Downloads
# Go to the VMware Workstation Player menu -> Player -> Manage -> VMware Tools installation
tar xzvf "/media/brb/VMware Tools/VMwareTools-10.0.0-2977863.tar.gz"
cd vmware-tools-distrib
sudo ./vmware-install.pl
[Accept all default]
sudo shutdown -r now

Go to Player -> Manager -> Virtual Machine Settings -> Options -> Shared folders.

The shared folders will be under /mnt/hgfs in the guest machine. One good thing about the share folder with VMware is we can create new share folders while the virtual machine is on. If we check the mount points, we will see

brb@ubuntu:~$ mount | grep host
.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)

Instruction for Ubuntu 16.04.1

# NOT to follow the yellow pop-up at the bottom of the VMware (e.g. clicking 'Install Tools'). 
# It's OK to receive the message 'the VirtualBox Kernel service is not running' 
sudo apt-get update
sudo apt-get install open-vm-tools-desktop

and reboot your VM.

Shared Folder

We may need to reinstall VMware tools (see the above section) for the shared folders function to work. It works when I tested on Unity and LXDE ubuntu.

Sound

By default there is no sound (audio device). Follow here to add a sound device.

Import an ova file

After we import an ova file exported from VirtualBox, VMware will generate a vmware virtual disk files (*.vmdk) under the new folder (folder name is the new virtual machine name). So we can delete the ova file.

Convert between vmdk and ova format

See this article in howtogeek.com

Proxmox Virtual Environment

Proxmox vs. ESXi

oVirt

Parallels

Remote Application Server

Emulation vs virtualization

Virtualization allows users to configure virtual machines outfitted with similar hardware and processors as the host system, whereas emulation simulates different hardware and processor configurations in software.

Emulators are what allow you to run old Commodore 64 or NES games on a PC, for example.

How Do You Safely Run an Untrusted Executable File on Linux

Firejail. See this post.

8個DevOps好用工具大介紹

http://www.ithome.com.tw/news/99307

Puppet

http://www.ithome.com.tw/news/99285

Chef

http://www.ithome.com.tw/news/99304

Jenkins

http://www.ithome.com.tw/news/99305

Ansible

http://www.ithome.com.tw/news/99306