Table of Contents

Virtualbox

Issues

Discard machine "starting" state

VBoxManage list vms
VBoxManage discardstate aab57b2d-566b-4d63-bca1-2a8ae74cd213
 
VBoxManage: error: The machine '...' is already locked for a session (or being unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 1247 of file VBoxManageMisc.cpp
 
rm /tmp/.vbox-john-ipc/lock

Edit .vbox file and remove aborted=“true”.

Error -610 in supR3HardenedMainInitRuntime!

cannot run virtualbox on ubuntu 16.04

Windows 10 guest - RDP login freeze

Introduced in Windows 10 version 1903 Solution: deativate the WDDM-Display Driver by group policy.

Local Computer Policy
 -> Computer Configuration
  -> Administrative Templates
   -> Windows Components
    -> Remote Desktop Service
     -> Remote Desktop Session Host
      -> Remote Session Environment
       -> Use WDDM graphics display driver for Remote Desktop Connections

Tips & Tricks

Virtualization in VBox

TAG: nested virtualization VBox doesn't support nester virtualization.

Boot from USB

There is no option to boot from USB. You need to use helper bootloader. Download plop and extract ISO from zip.

optimize for Intel

VBoxManage modifyvm Windows --vtxvpid on --largepages on

Autostarting

https://askubuntu.com/questions/57220/start-vboxheadless-vm-at-startup

$ VBoxManage modifyvm <vmname> --autostart-enabled on
$ VBoxManage modifyvm <vmname> --autostop-type acpishutdown

Systemd based way

Classic way

There is a script /usr/lib/virtualbox/vboxautostart-service.sh which is called by /lib/systemd/system/vboxautostart-service.service Script is calling binary VBoxAutostart. Script is sourcing following configration files:

And using following variables:

systemctl enable vboxautostart-service.service
Single service per VM
etc/systemd/system/vboxvmservice@.service
[Unit]
Description=VBox Virtual Machine %i Service
Requires=systemd-modules-load.service
After=systemd-modules-load.service
 
[Service]
User=user <-- modify
Group=vboxusers
ExecStart=/usr/bin/VBoxHeadless -s %i
ExecStop=/usr/bin/VBoxManage controlvm %i savestate
TimeoutSec=5min
TimeoutStopSec=5min
 
 
[Install]
WantedBy=multi-user.target
systemctl enable vboxvmservice@vm_name.service
systemctl start vboxvmservice@vm_name.service

Unlock "Guru Meditation"

Find PID of VirtualBox process and kill it.

Compacting VDIs

On guest system fill all empty space with zeros:

zeroswap.reg
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]
"ClearPageFileAtShutdown"=dword:00000001

Shutdown guest system and compact .vdi image:

Resizing VDIs

To resize disc image (size is in MB!):

Resizing VDIs with snapshot is tricky:

You can resize a VM which has snapshots, but you must resize the right thing.
Resizing the first snapshot (more accurately the base image) only affects that one. It doesn't magically change anything else.
So what you need to do is to identify the diff image which is associated with “Current State”, i.e. what is attached to the VM. This image needs to be resized.

To resize all snapshoots from Linux:

for x in Snapshots/*.vdi; do vboxmanage modifyhd $x --resize 20000; done

Enable SSD and trim

When TRIM is issued to vdi disc, disc size is reduced. It is very slow but it seems to be only one method to compact snapshots' VDIs.

Enabling from commandline:

VBoxManage storageattach "Debian clean" --storagectl "SATA" --port 0 --discard on --nonrotational on
VBoxManage storageattach "Debian clean" --storagectl "SATA" --port 1 --discard on --nonrotational on

or manually in config file (but can be overwritten by Virtualbox manager):

machine.vbox
<AttachedDevice nonrotational="true" discard="true" type="HardDisk" port="0" device="0">
   <Image uuid="{fdd4f1a4-36ff-4944-aee8-e35b5503e87c}"/>
</AttachedDevice>
<AttachedDevice nonrotational="true" discard="true" type="HardDisk" port="0" device="1">
   <Image uuid="{95baed2d-0aa7-437d-9bff-534af4036ce3}"/>
</AttachedDevice>

NOTE: order of XML attribs are importand. Add discard=“true” after “nonrotational=“true”''

Additionally increase SATA timeout:

echo -n 180 > /sys/block/sda/device/timeout
echo -n 180 > /sys/block/sdb/device/timeout
echo -n 180 > /sys/block/sdc/device/timeout

Disabling TRIM support from commandline:

VBoxManage storageattach "Windows10" --storagectl "SATA" --port 0 --discard off

NOTE: Enabling TRIM support will kill your rotational drive :). Every data delete will cause VDI image to trim to its data size (like compacting) and it is very slow!

To disable TRIM in Windows10, run administator shell (WIN+X) and:

fsutil behavior query disabledeletenotify
fsutil behavior set DisableDeleteNotify 1

Mount shared folder

/etc/fstab
sharedfolder		/mnt/myfolder	vboxsf		noauto,uid=1000,gid=1000	0	0

change UUID of VDI

VBoxManage internalcommands sethduuid virtualdisk.vdi

convert RAW image to VDI

Convert raw disc image (like iso,bin, raw) into vdi:

# from RAW to VDI
VBoxManage convertdd bootable.bin testdisc.vdi
 
# From VDI to RAW
VBoxManage convertdd bootable.vdi testdisc.bin

draft

Add your user to following groups:

To access real hard drive from VirtualBox, it is needed to crate raw VMDK:

VBoxManage internalcommands createrawvmdk -filename ./raw_dev_sdc.vmdk -rawdisk /dev/sdc

It is possible to emulate SSD drives and emulate TRIM support:

VBoxManage storageattach My_Linux_VM --storagectl "SATA" --port 3 --discard on --nonrotational on --type hdd
VBoxManage modifyhd raw_dev_sdc.vmdk settype writethrough

REMARK: Enabling virtual disc to be detected as SSD disc has nothing to real SSD installed in host system. With TRIM support enabled the dynamic VDI file is shrink when TRIM command is issued to controller.

Windows XP

change IDE to AHCI

First install drivers. Do not touch existing IDE controllers.Add new AHCI controller with some temporary disc.

change HAL to multiprocessor

rundll32 syssetup,SetupInfObjectInstallAction ACPIAPIC_MP_HAL 128 %windir%\inf\hal.inf

move real machine into vbox

On Windows XP - create new hardware profile:

On Windows XP - change IDE controller to generic one:

NTFS compression

VDI was compacted. VDI files with +c attribute (BTRFS compression). Tests on C:\WINDOWS folder. Windows shows 2,46 GB data and 1.65GB on disc.

2nd test:

3rd test:

4rd test:

Conclustions

Better is to use BTRFS compression - periodically recompress .vdi file.