Whonix ™ for KVM
|About this KVM Page|
What is KVM?
For an openly developed, free and open-source software (FOSS), GPL licensed hypervisor that can run Whonix, it is recommended to use Kernel Virtual Machine (KVM) that comes with the GNU/Linux OS. KVM combined with the VirtualMachineManager front-end should provide a familiar, intuitive and easy-to-use GUI. KVM uses libvirt.
For a detailed view on KVM's security merits read the audit report issued by an independent security auditing firm.
Why Use KVM Over VirtualBox?
The VirtualBox developer team have recently taken the decision to switch out the BIOS in their hypervisor. However, it now comes with one that requires compilation by a toolchain that does not meet the definition of Free Software as per the guidelines of the Free Software Foundation. This move is considered problematic for free and open source software projects like Debian, on which Whonix ™ is based.
The issues of the Open Watcom License are explained in this thread on the Debian Mailinglist. More references can be found here. In summary, there are issues surrounding the contradictory language of the license, the assertion of patents against software that rely upon it, and the placing of certain restrictions on software uses. For these reasons, those who care about running FOSS and appreciate its ethical views are recommended to avoid running VirtualBox; also see avoid non-freedom software.
Besides this licensing issue, a more tangible reason to avoid VirtualBox is the security practices of Oracle who produce the software. Events and news in recent years (like the Snowden leaks) demonstrate there is an urgent need for increased transparency and verifiable trust in the digital world. Oracle is infamous for their lack of transparency in disclosing the details of security bugs, as well as discouraging full and public disclosure by third parties. Security through obscurity is the flawed modus operandi at Oracle. 
Not going public with the details of vulnerabilities only leads to laziness and complacency on behalf of the company that fields the affected products. One example is this historical 0day vulnerability reported privately to Oracle in 2008 by an independent security researcher. Over four years later, the vulnerability remained unfixed, exhibiting Oracle has a history of failing to provide timely patches to customers so they can protect themselves.
On the VirtualBox bugtracker, ticket VirtualBox 5.2.18 is vulnerable to spectre/meltdown despite microcode being installed indicates non-responsiveness and non-progress by upstream. Users must patiently wait for VirtualBox developers to fix this bug.
VirtualBox also contains significant functionality that is only available as a proprietary extension, such as USB / PCI passthrough and RDP connectivity. Based on Oracle's unfriendly track record with the FOSS community in the past -- examples include OpenSolaris and OpenOffice -- it would be unsurprising if users were charged for these restricted features in the future, or if the project was abandoned due to insufficient monetization.
KVM Setup Instructions
Refer to the Computer Security Education chapters here and apply relevant steps.
If you are using Debian stable (currently: bullseye), click on Expand on the right.
Setup sudoers. Add the operating system user account to sudoers.
Update package lists.
For Debian bullseye+ on Intel / AMD you need to install:
For Debian bullseye+ on PowerPC you need to install:
If you are using Ubuntu, click on Expand on the right.
Add your user to KVM Groups (1 of 2).
Add your user to KVM Groups (2 of 2).
If you are using Arch Linux, click on Expand on the right.
Update the package lists and install the following packages.
If you are using a Linux distribution that is not documented above, click on Expand on the right.
The qemu-kvm and libvirt-bin packages are necessary. virt-manager is also required in order to use a graphical user interface (which most users want). It is most likely this software can be installed using the usual distribution's package manager.
If any of the following errors appear while later using.
Then a more recent version of libvirt and kvm is likely needed.
Readers are welcome to add detailed instructions for other distributions here!
- As of March 2019, it has been reported that the blkio throttling feature appears to be missing/unsupported on the latest Arch version. This causes a failure during VM start up. The VM also fails to start up on Ubuntu 20.04 with a "blkio" error. The current work around is to remove the feature for now.
- The pvspinlock feature is reported to not be supported and the issue was resolved when edited out of the VM config.
In order to be able to manage virtual machines as a regular (non-root) user, that user must be added to the
libvirt and the
kvm groups. The following command will work in Debian and assumes the simple scenario whereby KVM will be utilized with the current logged in user. For older Ubuntu versions, note that the group names vary and libvirt may be called libvirtd instead. For Ubuntu 20.04, libvirt works.
If another distribution is in use, then first refer to the distribution manual. For example, a necessary reference for Arch users is the Arch Linux libvirt wiki page.
Note: A reboot is required after:
- KVM is installed.
- Users are added to groups.
Build from Scratch
Advanced users are encouraged to build Whonix ™ images for high security assurance.
Download and Extract
It is strongly recommended to read and apply the steps outlined in this section. By applying a known and tested configuration, this will provide better convenience and security.
Be sure to use the qcow2 images that are provided by the Whonix ™ project instead of rolling your own  because they contain important performance optimizations.  The only exception is if images were created from source. 
If Whonix ™ libvirt images already exist, then consider a Cleanup first.
For simplicity the Whonix ™ images should be downloaded and stored in the home folder (/home/<your user name>) so the following commands can be copied/pasted without changes.
Download Whonix ™
|Verify images using this Signing Key|
Verify the Whonix ™ Images
1. Ensure the tarball is in the user home folder before applying these steps.
2. Do not use
unxz! Extract the images using gnu
3. Use gnu
tar to decompress the archive.
Optional: XML Modification
This section describes XML modifications before importing a virtual machine. For virtual machines that were already imported, see: Editing an Imported Machine's XML Configuration.
Modifying a machine's XML file provides more fine-grained control over its settings than what is exposed through the virt-manager GUI. Unless you are knowledgeable about this process, editing configuration defaults is neither recommended nor necessary.
Whonix-Gateway*.xml in a text editor of your choice as a regular, non-root user.
Whonix-Workstation*.xml in a text editor of your choice as a regular, non-root user.
It is possible to edit the XML files later on if this is necessary, see: Editing an Imported Machine's XML Configuration.
Importing Whonix ™ VM Templates
The first step after extracting the archive is to import the supplied XML files. They serve as a description for libvirt and define the properties of the Whonix ™ VMs and the networking they should have.
Moving Whonix ™ Image Files
The XML files are configured to point to the default storage location of
/var/lib/libvirt/images. The following steps move the images there so the machines can boot.
Note: Changing the default location may cause conflicts with SELinux, which will prevent the machines from booting.
It is recommended to move the image files instead of copying them.
Copying Whonix ™ Image Files
Whonix ™ disk images are sparse files, meaning they expand when filled rather than allocating their entire size (100GB outright). Sparse files require special commands when they are copied to ensure they do not lose this property, otherwise they will occupy all of the actual space. Higher privileges (sudo) are required because the copying is to a privileged location in the system.
Manipulating QCOW2 Images
Use qemu-img to interact with KVM disk images. This software can resize virtual disks, convert virtual disks to other formats, and more. It is not necessary nor recommended to change the official images, so proceed cautiously and only if the procedure is understood.
For more commands, refer to the qemu-img manual.
It is possible to run image files from encrypted containers. sVirt protections are confirmed to be in effect for image files at alternative locations.
Change the permissions on the container mount point directory so virtual machine manager can access the image. In Zulucrypt, containers are mounted under
After importing Whonix ™, it is advised to delete the archives (.libvirt.xz files) and the temporarily extracted folders, or to move them into a custom location. This is useful to avoid conflicts and confusion if a new version of Whonix ™ is later downloaded.
To delete the archives and temporary folders, run.
If Virtual Machine Manager is familiar, there is nothing special about starting Whonix ™ VMs compared to starting other VMs. First start Whonix-Gateway ™, then start Whonix-Workstation ™.
Graphical User Interface (GUI)
Start Virtual Machine Manager.
Start Menu →
Virtual Machine Manager
Start Whonix-Gateway ™.
click on Whonix-Gateway →
click open →
click the play symbol
Repeat the steps for Whonix-Workstation ™.
Command Line Interface (CLI)
On the host.
To start Whonix-Gateway ™, run.
To start Whonix-Workstation ™, run.
To interact with the Whonix-Workstation ™ via serial console, run.
To disable startup of the included Desktop Environment regardless of how much RAM is assigned to the VM, configure RAM Adjusted Desktop Starter package settings.
Adjust Display Resolution
Whisker Menu →
select resolution 
Save and then take a snapshot.
GUI Console →
Scale Display →
Check: Always + Auto resize VM with window. Every new session, a reboot is needed while the VM's GUI console is open and maximized to activate display resize.
Read and apply the Post Installation Security Advice.
If you want to remove Whonix ™ KVM VMs, Whonix ™ network and Whonix ™ images, click on Expand on the right.
KVM Upgrade Instructions
It is strongly recommended to uninstall older Whonix ™ versions and always run the stable release. Note that Whonix ™ supports in-place APT upgrades too.
Multiple Whonix-Gateway ™
Testing Upcoming Versions
- Rename the test Whonix ™ images to something unique, preferably by appending the version number to the name.
- Edit the XML templates and change the VM names.
- Import the images by following the Importing Whonix installation steps. Keep in mind the full name of the new images must be used and do not import the Network templates.
Convert Libvirt Templates to QEMU Commands
- First export the VM template as a file: sudo virsh dumpxml Whonix-Gateway > Whonix-Gateway.xml
- Convert it to the QEMU command: sudo virsh domxml-to-native qemu-argv Whonix-Gateway.xml > Whonix-Gateway.args
- Repeat for the Whonix-Workstation. Replace
Whonix-Workstationin above commands.
Magic SysRq Keys
Magic SysRq keys are useful when the guest is unresponsive, especially in cases where VMs are running headless and a GUI console is not available for forcing them to shut off on the host.
Libvirt provides built-in DHCP functionality via a custom install of the minimalist Dnsmasq DNS/DHCP daemon.  This is useful when running multiple Workstations concurrently that are attached to the same Gateway, and for custom Workstations running Android x86.
For privacy and traffic leak purposes Dnsmasq does not resolve DNS as implemented in Libvirt.   DNS is not explicitly enabled for guests unless it is added to a network’s configuration.   Even when DNS is enabled, the way Libvirt uses it does not increase the host's attack surface (by using raw sockets for example) nor does DHCP because it is bound to a specific NIC in this case.  Trying to edit the Dnsmasq configuration files directly will fail as settings are rewritten and are enforced through Libvirt by design. 
If the VM has snapshots that you wish to preserve, the snapshot xml-files of the source VM should be dumped with the following commands. 
Nested KVM Virtualization
It is possible to create nested KVM VMs on KVM hosts. As root...
Check the current setting on the host. If the result is
[Y], then it is okay.
For AMD systems use
If the result is [N], run the following command and reboot the system.
For Intel systems:
For AMD systems:
Host CPU instructions that include the
vmx extensions are passed through to the Workstation by default.
Compressing Disk Images
Some users find it easier to move the sparse image files when they are compressed in a tarball.
To re-compress files, run.
The pinning parameter
cpuset='1' must be removed in the
vcpu tag in the XML settings to allow adding more cores to a VM, otherwise performance issues and lockups will occur. CPU pinning is done to safeguard processes in other VMs that run cryptographic operations from side-channel attacks in case of a vulnerability in a cryptographic library.
To add more vcpus, increase the number in between the opening and closing
vcpu tags. Alternatively, use the hardware 'Details' pane in virtual Machine Manager.
If preserving cpu pinning while increasing core count is desired, pin the vcpus to different numbered ones compared to other sensitive VMs. Map them in a 1:1 ratio to avoid over committing cores (which leads to performance problems).
3D Graphics Acceleration
Not yet functional as of Debian
buster but this has been fixed upstream. Future enhancements for performance and security are planned. Will revisit in Bullseye.
Follow these steps to move data between the guest and host. It is recommended to create/assign a unique directory per snapshot to keep shared content belonging to different security domains separate.
Mandatory Access Control
Note: If your system is configured to use a Mandatory Access Control framework then it might be necessary to configure exceptions to allow the confined guests to communicate with the shared folder on the host.
Tests with Apparmor have shown it operates transparently with shared folders, without the need for a manual exception configuration.
On the host, chmod must be applied to the shared folder's contents to access the files.
Replace user name
user with your actual user name.
If SELinux is disabled then everything should be functional. If SELinux is enabled, it is necessary to add a policy for files under the shared folder on the host. SELinux will not allow this folder to be shared until it is labeled
svirt_image_t. To achieve this add the following policy on the host using semanage. Note that these steps must be re-applied every time something is transferred.  
Setting permissions on the user folder itself as follows may be necessary for the guest to start up without a permission error.
If you are using the command line instead of virt-manager to edit the vm's device settings, add this next section to the xml.
<filesystem type='mount' accessmode='mapped'> <source dir='/home/user/shared'/> <target dir='shared'/> </filesystem>
Libvirt supports passing through a computer's integrated webcam or any other USB devices.   Debian contributors have disabled USB auto-redirection by default to prevent the accidental passthrough of trusted USB devices to untrusted guests,   so they must be reverted temporarily. Once finished, change them back to safe defaults by going through the steps in reverse order.
Limitations: These steps apply to USB storage devices only. Portable devices such as phones and tablets are problematic and may not be successfully auto-redirected.
The USB drive will only be isolated so long as the Whonix-Workstation ™ is running. Do not close the VM GUI window or the device will be reassigned to the host. The VM window must be in focus (either mouse grabbed or in fullscreen mode just to be safe) when initially plugging in the device. The VM window can be minimized after it is detected in the guest. It is unnecessary to wait for the VM to completely boot.
Editing an Imported Machine's XML Configuration
Eventually configure your favorite editor to make changes. Set visual as your favorite editor -- the relevant software must be installed, such as kwrite, leafpad, kate, vi, nano, vim and so on.
In more recent versions of virt-manager, there is a second way available:
Virtual Machine Manager ->
Enable XML Editing
Details view for a VM, a new XML tab in the GUI is visible, allowing editing and saving directly from the VM viewer.
Enable Microphone Input
Microphone input to guests is a nice feature for VoIP, but it is dangerous to have on by default. It is good practice to disable the microphone on your host system through sound settings when it is not in active use.
The shipped configuration only includes a speaker by default (without a microphone) to prevent malware in the VM from eavesdropping on the user. To enable microphone input for select guests, edit the configuration and change
<codec type='output'/> ->
Creating Multiple Internal Networks
Open the Whonix ™ network XML file and change the name attribute to something different than the internal network that is currently running, for example 'Whonix-Internal2', 'Whonix-Internal3' and so on. The default network name in use is 'Whonix-Internal'.
Libvirt can support a variety of containment mechanisms. Currently supported mechanisms include KVM on the x86_64 platform and QEMU, but more configurations might be added at a later date. If hardware virtualization extensions are available, always use the KVM one.
To use another configuration, import its XML file with virsh.
How to Leave KVM when no X is Running
In the hypothetical situation whereby a user is "trapped" in a virtual console inside a VM without graphical desktop environment (X Window System) ("
sudo service lightdm stop"), it is still possible to switch back to the host.
In other words, should the graphical desktop environment crash or be terminated, the user may be "trapped" inside a black VM window. It is possible to exit this.
The emulated tablet device handles this by not allowing the mouse to be captured by the guest, however this is still possible:
Ctrl_L & Alt_L
Setting up gdb to work with qemu-kvm via libvirt
In order to debug a Linux kernel that is running as a KVM guest, the
-s parameter must be specified for the command line of qemu-kvm. Unfortunately there is no (easy) way to do this when libvirt and virt-manager are used to manage your virtual machines (instead of using KVM directly). In this case it is necessary to change the XML configuration of the virtual machine so that the
-s parameter is passed on to qemu-kvm.
The features below have serious security implications and should not be used. This applies to all hypervisors in general.
QCOW2 virtual disk images are the recommended and default storage format for KVM. LVM or any other storage mechanism must be avoided for security and privacy. LVM misconfiguration has serious security consequences and exposes the host filesystem to the processes running on the guest. 
In the event a virtual disk is no longer used -- where the low-level view of the storage can be controlled -- data created by VMs can easily be recovered and exfiltrated by malicious forensics tools run in a VM at a later time. This is extremely dangerous and can expose all kinds of information originally created in a VM of higher trust level. This leads to deanonymization, past session linking and theft of sensitive information and keys.   This setting is disabled in cloud tenancy environments.
THP/Hugepages aid rowhammer attacks  and memory de-duplication attacks (see KSM below) and therefore must be disabled for the guest and on the host. Research suggests that Debian hosts do not enable this feature and it is also disabled in cloud tenancy environments.
Memory ballooning can potentially be abused by malicious guests to mount rowhammer attacks on the host. 
SPICE allows accelerated graphics and clipboard sharing. The clipboard is disabled by default for security reasons:
- To prevent the accidental copying of a link to a website that was visited anonymously to the non-anonymous host browser (or vice versa).
- To stop malware in Whonix ™ Workstation from pilfering sensitive info from the clipboard.
If you still want to enable it, edit the VM config file and then change
<clipboard copypaste='no'/> to 'yes', then save and restart.
KSM is a memory de-deuplication feature that conserves memory by combining identical pages across VM RAM, but it is not enabled by default. Enabling this feature is dangerous because it allows cross-VM snooping by a malicious process.  It is capable of inferring what programs/pages are being visited outside the VM.  This feature is disabled in cloud tenancy environments and can also allow attackers to modify/steal APT keys and source lists of the host.  
Similar to KSM memory dedupe, filesystem dedupe introduces data leaks that violate hypervisor boundaries. The presence of certain files can be confirmed. These may develop into more advanced attacks on security in the future just like KSM related attacks have. ZFS and Btrfs have dedupe features but they are not enabled by default and should be avoided for high security environments.
Both USB and PCI device passthrough permit advanced attackers to flash the firmware of those devices and infect the host or other VMs. 
For more information on settings, please refer to the Libvirt manual.
- Did you reboot after installing KVM?
- Did you reboot after adding users to groups?
Please add this information if making a support request.
Unable to connect to libvirt
If the following error appears.
Unable to connect to libvirt. Verify that the 'libvirtd' daemon is running. Libvirt URI is: qemu:///system
Unable to open a connection to the libvirt management daemon
If the following error appears.
Unable to open a connection to the libvirt management daemon. Libvirt URI is: qemu:///system Verify that: - The 'libvirtd' daemon has been started
Check the KVM installation.
The output should show.
0 [ ok ] Restarting libvirt management daemon: /usr/sbin/libvirtd. 0 Running guests on default URI: no running guests. 0
In this case, it could be a permissions problem.
hda-duplex not supported in this QEMU binary
If this error appears you might be a member of thegroup, but lack membership of the group.
In this case, it helps to change.
process exited while connecting to monitor: ioctl(KVM_CREATE_VM) failed
If the following error appears.
Error starting domain: internal error: process exited while connecting to monitor: ioctl(KVM_CREATE_VM) failed: 16 Device or resource busy failed to initialize KVM: Device or resource busy
Then it is not possible other non-KVM VMs (such as VirtualBox VMs) might already be running, since two concurrent hypervisor instances is not supported by KVM / VirtualBox.
invalid argument: could not find capabilities for domaintype=kvm
Add Version Numbers to Support Request
If problems are experienced, be sure to note what versions of libvirt-bin, qemu-kvm and virt-manager are in use as part of the support request. If you are using Debian, the following command will determine the software versions.
Check the output of following command.
The output of the previous command is expected to be something like
user or your linux user account name. Should not be
Whonix ™ KVM maintainer availability is mostly limited to User Help Forum.
Questions on telegram, matrix, IRC, reddit, incomplete list will most likely not get attention by Whonix ™ KVM maintainer.
See also Support.
User Help Forum
For alternative installation guides contributed by community members, see: Installation Screenshots.
- There are also other platforms.
- What is "security through obscurity":
The basis of STO has always been to run your system on a "need to know" basis. If a person doesn't know how to do something which could impact system security, then s/he isn't dangerous. ... Nowadays there is also a greater need for the ordinary user to know details of how your system works than ever before, and STO falls down a as a result. Many users today have advanced knowledge of how their operating system works, and because of their experience will be able to guess at the bits of knowledge that they didn't "need to know". This bypasses the whole basis of STO, and makes your security useless.
- If this action is taken, sudo can be used as outlined below and elsewhere. Otherwise, it is necessary to manually switch to root and/or use su as per About#Based_on_Debian.
By default Debian does not use
sudo, so groups can be added with
usermod. If your user is
foothe following commands will work.usermod -a -G libvirt fooAnd.usermod -a -G kvm foo
- Manually converting images from .ova to .qcow2 is no longer recommended, since .qcow images can be downloaded from the Whonix ™ project.
- As per build-steps.d/2400_convert-img-to-qcow2, these are "-o cluster_size=2M" and "-o preallocation=metadata".
- Because the same performance optimizations are present.
- It does not matter if the bulk download is done over an insecure channel if software signature verification is used at the end.
- The command line can also be used to make sure the VM has been shut down.
On linux host servers, libvirtd uses dnsmasq to service the virtual networks, such as the default network. A new instance of dnsmasq is started for each virtual network, only accessible to guests in that specific network.
- Dnsmasq is visible to a nmap scan from the Workstation but not much else. Manual test: sent a DNS request with this result:
dig microsoft.com @10.152.152.0 ; <<>> DiG 9.11.5-P4-3-Debian <<>> microsoft.com @10.152.152.0 ;; global options: +cmd ;; connection timed out; no servers could be reached
So I can see an open TCP port. However it responds as if it’s “tcpwrapped”. That implies if you connect over a different interface from virbr0 , dnsmasq closes the connection without reading any data. So data you send to it doesn’t matter; it can’t e.g. exploit a classic buffer overflow.
- The file sharing mode mapped is just an example, using squash or passthrough is possible by selecting them from the drop down menu. Mapped is recommended for security.
- Dedup Est Machina: Memory Deduplication as an Advanced Exploitation Vector
- Flip Feng Shui: Hammering a Needle in the Software Stack
For example, if one was to use
sudo su(i.e. doing it as
root) before running
sudo addgroup "$(whoami)" libvirtand
sudo addgroup "$(whoami)" kvmthat would not work. That is because when executing commands under user
user. Hence not add the user to the required groups.