Jump to content

KVM: Difference between revisions

From 太極
Brb (talk | contribs)
Brb (talk | contribs)
 
(140 intermediate revisions by the same user not shown)
Line 2: Line 2:
* [http://www.linux-kvm.org/page/Main_Page KVM] Kernel-based Virtual Machine
* [http://www.linux-kvm.org/page/Main_Page KVM] Kernel-based Virtual Machine
* https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine
* https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine
* [https://virt-manager.org/ Virtual Machine Manager] - virt-manager. It can display VNC or SPICE, and uses libvirt to lookup the graphical connection details.
* [https://virt-manager.org/ Virtual Machine Manager] - '''virt-manager'''. Two display types: '''SPICE''' or '''VNC''', and uses libvirt to lookup the graphical connection details.
** [https://ostechnix.com/how-to-manage-kvm-virtual-machines-with-virt-manager/ How To Manage KVM Virtual Machines With Virt-Manager]
** [https://ostechnix.com/how-to-manage-kvm-virtual-machines-with-virt-manager/ How To Manage KVM Virtual Machines With Virt-Manager]
** [https://www.maketecheasier.com/access-linux-virtual-machines-over-vnc/ How to Access Linux Virtual Machines Remotely Over VNC]
** [https://www.maketecheasier.com/access-linux-virtual-machines-over-vnc/ How to Access Linux Virtual Machines Remotely Over VNC]
** [https://linuxconfig.org/how-to-install-redhat-8-on-a-virtual-machine#h3-2-how-to-connect-to-your-vm-over-vnc How to Connect to Your VM Over VNC]
** [https://linuxconfig.org/how-to-install-redhat-8-on-a-virtual-machine#h3-2-how-to-connect-to-your-vm-over-vnc How to Connect to Your VM Over VNC]
** [https://fabianlee.org/2019/02/16/kvm-virt-manager-to-connect-to-a-remote-console-using-qemussh/ Connect to a remote console using qemu+ssh]
* My notes:
* My notes:
** One advantage over VB for me: No need to go to VirtualBox website for the installation and frequent updates. I can use the command line to install it.
** One advantage over VB for me: No need to go to VirtualBox website for the installation and frequent updates. I can use the command line to install it.
** The desktop screen resolution can be automatically adjusted without a need to install ''guest addition'' or ''vmware tool''. Tested Ubuntu and Pop_OS.
** The desktop screen resolution can be automatically adjusted without a need to install ''guest addition'' or ''vmware tool''. Tested Ubuntu and Pop_OS.
** It has two windows. One is virt-manager and the other is the virtual machine.
** It has two windows. One is '''virt-manager''' and the other is the virtual machine '''qemu-system-x86_64'''.
** Use Left Control + Left Alt to escape the virtual machine.  
** Use Left Control + Left Alt to escape the virtual machine.  
* https://en.wikipedia.org/wiki/QEMU
* https://en.wikipedia.org/wiki/QEMU
Line 16: Line 17:
* [http://www.thegeekstuff.com/2014/10/linux-kvm-create-guest-vm How to Install Linux KVM and Create Guest VM with Examples]. Para-virtualization, checking the virtualization support on hardware and others. It includes the usage of '''virsh''' and '''virt-install''' commands.
* [http://www.thegeekstuff.com/2014/10/linux-kvm-create-guest-vm How to Install Linux KVM and Create Guest VM with Examples]. Para-virtualization, checking the virtualization support on hardware and others. It includes the usage of '''virsh''' and '''virt-install''' commands.
* [https://linuxconfig.org/virtualization-solutions-on-linux-systems-kvm-and-virtualbox Virtualization solutions on Linux systems - KVM and VirtualBox]
* [https://linuxconfig.org/virtualization-solutions-on-linux-systems-kvm-and-virtualbox Virtualization solutions on Linux systems - KVM and VirtualBox]
* Guest additions: it seems QEUM/KVM does not have that to download.
* [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_virtualization/getting-started-with-virtualization-in-rhel-8_configuring-and-managing-virtualization#creating-vms-and-installing-an-os-using-the-rhel-8-web-console_assembly_creating-virtual-machines CHAPTER 2. GETTING STARTED WITH VIRTUALIZATION] from redhat.com
** Share clipboard. [https://askubuntu.com/a/858650 How can I copy&paste from the host to a KVM guest?] '''sudo apt install spice-vdagent''' in the guest virtual machine. had to reboot guest to be able to make it work. It works.
** [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-monitoring_in_virt_manager 2.3. Monitoring performance in virtual machine manager]
** Display resolution. The display has a resolution 1024x768. In the virtual machine window, I do 'View' -> 'Scale to Display' where I choose 'Always' and check the checkbox 'Auto resize VM with window'. It did increase the resolution. See also the command line method: [https://superuser.com/a/169243 How to increase the visualized screen resolution on QEMU / KVM?]
** Share files
*** [https://cialu.net/qemu-kvm-on-ubuntu-and-sharing-files-between-host-and-guests/ QEMU/KVM on Ubuntu and sharing files between host and guests]. It works. Modify/create a file '''/etc/rc.local''' file to automount the folder at each login. Note the share folder still belongs to the user's group. So we can actually create a soft link for this folder on the host.
*** [https://askubuntu.com/a/851565 Is there something like “VirtualBox Guest Additions” for QEMU/KVM?]
** Mouse integration. [https://ckirbach.wordpress.com/2016/01/14/kvm-mouse-pointer-integration-with-ubuntu-guest/ virt-manager KVM mouse pointer integration (client mouse mode) with Ubuntu guest]. [https://serverfault.com/a/457610 Any way to release focus on a KVM guest in virt-manager without having to click Ctrl_L + Alt_L?]
 
* [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-monitoring_in_virt_manager Monitoring performance in virtual machine manager] from redhat.com
* [http://fossboss.com/2016/08/13/use-qemu-test-operating-systems-distributions/ How To Use QEMU To Test Operating Systems & Distributions]
* [http://fossboss.com/2016/08/13/use-qemu-test-operating-systems-distributions/ How To Use QEMU To Test Operating Systems & Distributions]
* [http://www.dedoimedo.com/computers/kvm-virtualbox.html Using KVM and VirtualBox side by side] and [http://askubuntu.com/questions/413511/virtualbox-and-kvm-beside-each-other VirtualBox and KVM beside each other]
* [http://www.dedoimedo.com/computers/kvm-virtualbox.html Using KVM and VirtualBox side by side] and [http://askubuntu.com/questions/413511/virtualbox-and-kvm-beside-each-other VirtualBox and KVM beside each other]
Line 49: Line 43:
</li>
</li>
</ul>
</ul>
== Big picture ==
* '''KVM''' is the acceleration technology in the kernel.
* '''QEMU''' is the software that runs the VMs, using KVM for speed.
* '''libvirt''' is the management layer that abstracts away the complexity of KVM/QEMU.
* '''virsh''' is the command-line tool for libvirt.
* '''virt-manager''' is the GUI tool for libvirt
<pre>
+-------------------+      +-------------------+
|  Physical Host  |      |    Guest OS      |
|    (Your PC)      |      |  (e.g., Windows/Linux) |
|                  |      |                  |
| +-----------------+-----+ |  +---------------+--+
| |    Hardware    |    | |  | VM Applications  |
| |  (CPU, RAM,    |    | |  |  (Browser, IDE) |
| |    Disks, NIC)  |    | |  +------------------+
| +-------+---------+    | |
|        |              | |
|        |              | |
| +-------v---------+    | |
| |  Linux Kernel  |    | |
| | (incl. KVM module)|<----+------> Disk (Virtual)
| +-------+---------+    | |  +---------------+--+
|        ^              | |  |    Guest OS    |
|        |  (Hardware  | |  |  Kernel/Drivers|
|        |  Acceleration)| |  +------------------+
|        |              | |
| +-------+---------+    | |
| |    QEMU        |    | |
| | (User-space VM  |    | |
| |  Emulator)    |    | |
| +-------^---------+    | |
|        |              | |
|        | (Manages VMs, | |
|        |  Networks, etc.)| |
| +-------+---------+    | |
| |  libvirtd      |    | |
| |  (Daemon)      |    | |
| +-------^---------+    | |
|        |              | |
|        | (API/Calls)  | |
| +-------+---------+    | |
| |    virsh      |    | |
| |  (CLI Tool)    |    | |
| +-----------------+-----+ |
|        ^              | |
|        |              | |
| +-------+---------+    | |
| | virt-manager    |    | |
| |  (GUI Tool)    |    | |
| +-----------------+-----+ |
|                  |      |
+-------------------+      +-------------------+
</pre>
== QEMU ==
[https://www.howtogeek.com/devops/how-to-use-qemu-to-boot-another-os/ How to Use QEMU to Boot Another Operating System]
=== QEMU vs. KVM ===
[https://www.makeuseof.com/qemu-vs-kvm-which-should-you-use/ QEMU vs. KVM: Which Should You Use for Virtualization?] QEMU uses full system emulation, allowing it to emulate a complete computer system, including the processor, memory, storage, and peripheral devices. This flexibility makes QEMU an excellent choice for cross-platform virtualization since it supports a wide range of architectures.


== libvirt ==
== libvirt ==
Line 54: Line 108:
* https://libvirt.org/
* https://libvirt.org/
* Check libvirt version: sudo head -n2 /var/log/libvirt/qemu/ubuntu2004.log  # on Ubuntu 20.04 it shows 6.0.0
* Check libvirt version: sudo head -n2 /var/log/libvirt/qemu/ubuntu2004.log  # on Ubuntu 20.04 it shows 6.0.0
== "virt-install" to install or delete a VM ==
* [https://opensource.com/article/21/1/cloud-image-virt-install Set up a Linux cloud on bare metal]
* [https://www.golinuxcloud.com/virt-install-examples-kvm-virt-commands-linux/ virt-install examples | KVM virtualization commands cheatsheet]
<pre>
$ virt-install --help | grep graphics
$ osinfo-query os
$ sudo virt-install  -n ubuntu2004 --os-type=Linux  \
  --os-variant=ubuntu18.04  --ram=2096  --vcpus=2  \
  --disk size=20  \
  --network network=br0 \
  --graphics vnc,listen=0.0.0.0  \
  --location Downloads/ubuntu-20.04.1-desktop-amd64.iso
$ sudo virt-install --name=centos7server \
  --os-type=Linux \
  --os-variant=centos7.0 \
  --vcpu=2 --ram=2048 \
  --disk size=20 \
  --graphics vnc \
  --location=/tmp/CentOS-7-x86_64-DVD-2009.iso
# Running locally
$ sudo virt-install  -n ubuntu20043 --os-type=Linux  \
  --os-variant=ubuntu20.04  \
  --ram=4096  --vcpus=2  \
  --disk size=20  \
  --network network=default  \
  --cdrom ~/Downloads/ubuntu-20.04.3-desktop-amd64.iso
</pre>
NB
<ul>
<li>If we just run a live session and power off the VM, it will automatically reject the installation medium (iso file) and reboot. So eventually it showed a message "No bootable device." </li>
<li>Using the Virtual Machine Manager GUI I found after I tried to delete a VM it won't actually delete the image file created in '''/var/lib/libvirt/images'''. Be careful when deleting files there. See [https://www.cyberciti.biz/faq/howto-linux-delete-a-running-vm-guest-on-kvm/ How to delete KVM VM guest using virsh command] & [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-virsh-delete Removing and deleting a VM] from RedHat.
<pre>
$ virsh list --all
Id  Name                State
------------------------------------
39  ubuntu20043        running
$ virsh dumpxml --domain ubuntu20043 | grep 'source file'
      <source file='/var/lib/libvirt/images/ubuntu20043.qcow2' index='2'/>
$ sudo virsh destroy ubuntu20043  # SHUT DOWN
# "sudo virsh undefine ubuntu20043" WILL LEAVE qcow2
$ sudo virsh undefine ubuntu20043 --remove-all-storage
Domain 'ubuntu20043' has been undefined
Volume 'vda'(/var/lib/libvirt/images/ubuntu20043.qcow2) removed.
$ sudo ls -lt /var/lib/libvirt/images/
</pre>
</li>
</ul>
== Check if running in VM ==
[https://opensource.com/article/20/12/linux-server 9 things to do in your first 10 minutes on a Linux server]
<pre>
$ cat /sys/class/dmi/id/sys_vendor
QEMU
$ sudo dmidecode -s system-manufacturer
QEMU
</pre>
On VirtualBox + CentOS vm, it returns "innotek GmbH".
On VMware + CentOS vm, it returns "VMware, Inc".
== Guest additions ==
It seems QEUM/KVM does not have that to download.
* Share clipboard. [https://askubuntu.com/a/858650 How can I copy&paste from the host to a KVM guest?] '''sudo apt install spice-vdagent''' in the guest virtual machine. had to reboot guest to be able to make it work. It works.
** Use '''sudo dpkg-query -l | grep spice-vdagent ''' to check if the package is installed or not
* Display resolution. The display has a resolution 1024x768 (4:3). I can increase to 1600x900 (16:9) or even 1920x1080 (16:9) in the guest machine ('''scrollbar is hidden''').
** In the Virtual Machine Window, I do '''View''' -> '''Scale to Display''' where I choose '''Always''' and check the checkbox '''Auto resize VM with window'''. It did increase the resolution. See also the command line method: [https://superuser.com/a/169243 How to increase the visualized screen resolution on QEMU / KVM?]
* [https://centosfaq.org/centos/virt-manager-and-full-screen-display/ Virt-Manager And Full-screen Display]. View -> Scale Display -> Auto resize VM with window.
* Share files
** [https://cialu.net/qemu-kvm-on-ubuntu-and-sharing-files-between-host-and-guests/ QEMU/KVM on Ubuntu and sharing files between host and guests]. It works. Modify/create a file '''/etc/rc.local''' file to automount the folder at each login. Note the share folder still belongs to the user's group. So we can actually create a soft link for this folder on the host.
** [https://askubuntu.com/a/851565 Is there something like “VirtualBox Guest Additions” for QEMU/KVM?]
* Mouse integration. [https://ckirbach.wordpress.com/2016/01/14/kvm-mouse-pointer-integration-with-ubuntu-guest/ virt-manager KVM mouse pointer integration (client mouse mode) with Ubuntu guest]. [https://serverfault.com/a/457610 Any way to release focus on a KVM guest in virt-manager without having to click Ctrl_L + Alt_L?]
= Bridge network =
* [https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s2-networkscripts-interfaces_network-bridge 11.2.6. NETWORK BRIDGE] from redhat.com. It seems possible to share a NIC with one or more virtual NICs.
* [https://serverfault.com/a/846873 Libvirt: one NIC, multiple VM, all with Bridged mode]
* [https://www.linux-kvm.org/page/Networking#Private_Virtual_Bridge Configuring Guest Networking]
* (Not about bridge) [https://www.cyberciti.biz/faq/linux-kvm-libvirt-dnsmasq-dhcp-static-ip-address-configuration-for-guest-os/ KVM libvirt assign static guest IP addresses using DHCP on the virtual machine]
* [https://unix.stackexchange.com/a/245911 Configure public IP addresses in KVM VMs] (using '''brctl''')
* [https://www.cyberciti.biz/faq/debian-network-interfaces-bridge-eth0-eth1-eth2/ Debian Linux: Configure Network Interfaces As A Bridge / Network Switch] (using '''brctl''')
* [https://www.cyberciti.biz/faq/ubuntu-20-04-add-network-bridge-br0-with-nmcli-command/ Ubuntu 20.04 add network bridge (br0) with nmcli command] (using '''nmcli''')
<ul>
<li>There are different ways to configure the network in Ubuntu.
<ul>
<li>If we are using a Ubuntu server, we will use the '''Netplan''' method. </li>
<li>If we are using a Ubuntu desktop, we will use the Network manager command line '''nmcli''' method or the GUI tool '''nm-connection-editor'''. </li>
</ul>
</li>
<li>Use '''nmcli''' to add a bridge network and a bridge slave interface
<pre>
sudo nmcli con add ifname br0 type bridge con-name br0
sudo nmcli con add ifname eno1 type bridge-slave master br0
</pre>
</li>
<li>Use '''nmcli''' to bring down a wired network and bring up a bridge network
<pre>
sudo nmcli con down "Wired connection 1"
sudo nmcli con up br0
</pre>
</li>
<li>Use '''nmcli''' to delete unused bridge networks
<pre>
sudo nmcli device show
sudo nmcli con show
sudo nmcli con del "br0"
</pre>
</li>
</ul>


= Install =
= Install =
== Install on Ubuntu ==
== Install on Ubuntu ==
* https://help.ubuntu.com/community/KVM
* https://help.ubuntu.com/community/KVM
Line 64: Line 237:
<li> [https://mintguide.org/tools/340-kvm-virtualization-on-a-home-pc-with-linux-mint.html KVM virtualization on a home PC with Linux Mint] </li>
<li> [https://mintguide.org/tools/340-kvm-virtualization-on-a-home-pc-with-linux-mint.html KVM virtualization on a home PC with Linux Mint] </li>
<li> [https://www.linuxtechi.com/install-configure-kvm-ubuntu-18-04-server/ How to Install and Configure KVM on Ubuntu 18.04 LTS Server]. I skip step 4: Configure Network Bridge for KVM virtual Machines. </li>
<li> [https://www.linuxtechi.com/install-configure-kvm-ubuntu-18-04-server/ How to Install and Configure KVM on Ubuntu 18.04 LTS Server]. I skip step 4: Configure Network Bridge for KVM virtual Machines. </li>
<li> How to bring down br0 and delete it? After some messing up I need to delete br0.
<pre>
sudo ip link set br0 down  # ifconfig command is not found anymore
sudo brctl delbr br0
</pre>
</li>
<li> '''[https://www.answertopia.com/ubuntu/ubuntu-essentials/ Ubuntu 20.04 Essentials (book)]''' &rarr; [https://www.answertopia.com/ubuntu/creating-an-ubuntu-kvm-networked-bridge-interface/ Creating an Ubuntu 20.04 KVM Networked Bridge Interface]. It is based on a Ubuntu Desktop environment. The description is quite detailed. Have not tried yet! </li>
<li> '''[https://www.answertopia.com/ubuntu/ubuntu-essentials/ Ubuntu 20.04 Essentials (book)]''' &rarr; [https://www.answertopia.com/ubuntu/creating-an-ubuntu-kvm-networked-bridge-interface/ Creating an Ubuntu 20.04 KVM Networked Bridge Interface]. It is based on a Ubuntu Desktop environment. The description is quite detailed. Have not tried yet! </li>
<li>[https://www.tecmint.com/install-kvm-on-ubuntu/ How to Install KVM on Ubuntu 20.04]
<li>[https://www.tecmint.com/install-kvm-on-ubuntu/ How to Install KVM on Ubuntu 20.04]
{{Pre}}
<ul>
<li>qemu: qemu </li>
<li>qemu-kvm: ovmf, qemu-block-extra, qemu-system-common, qemu-system-data, qemu-system-gui, qemu-system-x86, qemu-utils, seabios, sharutils </li>
<li>libvritd-daemon: libvirt0, libvirt-daemon, libvirt-daemon-driver-qemu, ... </li>
<li>virt-manager: qemu-block-extra, qemu-utils, virt-viewer, virtinst, ...</li>
</ul>
<syntaxhighlight lang='sh'>
sudo apt install -y qemu qemu-kvm libvirt-daemon \
sudo apt install -y qemu qemu-kvm libvirt-daemon \
         libvirt-clients bridge-utils virt-manager
         libvirt-clients bridge-utils virt-manager
Line 72: Line 258:
# enable it to start on boot  
# enable it to start on boot  
sudo systemctl enable --now libvirtd
sudo systemctl enable --now libvirtd
# To manage virtual machines as a non-root user (without constantly typing sudo),
# you need to add your user account to the libvirt group.
sudo usermod -aG libvirt $(whoami) 
groups # check
lsmod | grep -i kvm
lsmod | grep -i kvm
ip a
ip a
# I got two new: virbr0, virbr0-nic
# I got two new: virbr0, virbr0-nic
# Click the superkey (Windows) and search/launch "Virtual Machine Manager"
# Click the superkey (Windows) and search/launch "Virtual Machine Manager"
</pre>
</syntaxhighlight>
Click the "Create a new virtual machine" button will result in an error: No active connection to install on. Rebooting does not help. But when I use the command line to create a new VM it works.
<pre>
sudo virt-install --name=ubuntu2004 \
  --os-type=Linux \
  --os-variant=ubuntu20.04 \
  --vcpu=2 --ram=2048 \
  --graphics vnc \
  --location=ubuntu-20.04.1-desktop-amd64.iso
</pre>
Add '''--network bridge:br0''' if we have added a new bridge network (''br0'') in the host (eg using '''netplan''' or '''nmcli''' or '''nm-connection-editor''' GUI Tool in Ubuntu). See some resource below.
</li>
</li>
<li>[https://www.cyberciti.biz/faq/install-kvm-server-debian-linux-9-headless-server/ How to install KVM server on Debian 9/10 Headless Server]  </li>
<li>[https://www.cyberciti.biz/faq/how-to-install-kvm-on-ubuntu-20-04-lts-headless-server/ How to install KVM on Ubuntu 20.04 LTS Headless Server].  
<li>[https://www.cyberciti.biz/faq/how-to-install-kvm-on-ubuntu-20-04-lts-headless-server/ How to install KVM on Ubuntu 20.04 LTS Headless Server].  
<ul>
<ul>
<li>IP 192.168.2.25 is the new static IP for the bridge network and 192.168.2.254 is the gateway current ethernet is using. </li>
<li>IP 192.168.2.25 is the new static IP for the bridge network (not virtual machine) and 192.168.2.254 is the gateway current ethernet is using. </li>
<li>Note according to [https://www.cyberciti.biz/faq/how-to-add-network-bridge-with-nmcli-networkmanager-on-linux/ How to add network bridge with nmcli (NetworkManager) on Linux], WiFi is not possible. It only works with Ethernet. Confirmed! The bridge network can be pinged from another computer. </li>
<li>Note according to [https://www.cyberciti.biz/faq/how-to-add-network-bridge-with-nmcli-networkmanager-on-linux/ How to add network bridge with nmcli (NetworkManager) on Linux], WiFi is not possible. It only works with Ethernet. Confirmed! The bridge network can be pinged from another computer. </li>
<li>
<li>
Line 120: Line 304:
</ul>
</ul>
</li>
</li>
<li>
os-variant list in '''virt-install'''
<pre>
$ osinfo-query os
</pre>
</li>
<li>Troubleshooting: [https://askubuntu.com/a/345263 virt-manager can't connect to libvirt]. Rebooting computer!
<li>[https://itsfoss.com/qemu-ubuntu/ Install and Use Qemu on Ubuntu] including '''spice-vdagent'''
</ul>
</ul>
* Where are image files saved: '''/var/lib/libvirt/images''' (/var/lib/docker for Docker)
 
** [https://linuxconfig.org/how-to-move-var-directory-to-another-partition How to move /var directory to another partition]
=== Where are image files saved ===
* Troubleshooting: [https://askubuntu.com/a/345263 virt-manager can't connect to libvirt]. Rebooting computer!
* '''/var/lib/libvirt/images''' ('''/var/lib/docker''' for [https://wiki.taichimd.us/view/Docker#Where_are_Docker_containers/images_stored_on_the_host:_/var/lib/docker Docker]). The "images" subdirectory contains many large '''qcow2''' files that should be deleted once I delete the VM.
* [https://linuxconfig.org/how-to-move-var-directory-to-another-partition How to move /var directory to another partition]
 
== Install on Arch/Manjaro ==
* [https://www.howtoforge.com/how-to-install-kvm-qemu-on-manjaro-archlinux/ How to Install KVM/QEMU on Manjaro/Archlinux]
 
== VNC ==
<ul>
<li>[https://blog.gtwang.org/linux/kvm-qemu-virt-install-command-tutorial/amp/ KVM/QEMU 以 virt-install 指令建立虛擬機器、VNC 顯示畫面教學]
<pre>
sudo virt-install --virt-type kvm --name ubuntu1804 --ram 2048
  --disk /home/seal/kvm/ubuntu1804.qcow2,format=qcow2
  --network network=default
  --graphics vnc,listen=0.0.0.0,password=YOUR_PASSWORD
  --noautoconsole
  --os-type=linux --os-variant=ubuntu17.10
  --cdrom=/home/seal/Downloads/ubuntu-18.10-desktop-amd64.iso
 
virsh vncdisplay ubuntu1804 #  127.0.0.1:1
                            # pay attention to the port number
                            # :0  --> 5900 in ssh
                            # :1  --> 5901 in ssh
sudo ufw disable
 
# Another machine.
# Suppose the host machine has an IP 192.168.0.3
ssh -NL 5901:localhost:5901 [email protected]
ssh -NL 5901:127.0.0.1:5901 [email protected]
 
vncviewer 127.0.0.1:1 # from a different machine
</pre>
NOTE: I have to use local port forwarding. If I try to directly connect to the VM in RealVNC, it will show '''The connection was refused by the computer'''. A limit by KVM?
</li>
</ul>
* [https://fabianlee.org/2019/02/16/kvm-virt-manager-to-connect-to-a-remote-console-using-qemussh/ KVM: virt-manager to connect to a remote console using qemu+ssh]
 
The question is how do we know the client's IP? I guess '''cockpit''' method is better.


== Install qemu-system-arm in Ubuntu ==
== Install qemu-system-arm in Ubuntu ==
Line 169: Line 399:
* [https://www.cyberciti.biz/faq/how-to-install-kvm-on-centos-7-rhel-7-headless-server/ How to install KVM on CentOS 7 / RHEL 7 Headless Server]
* [https://www.cyberciti.biz/faq/how-to-install-kvm-on-centos-7-rhel-7-headless-server/ How to install KVM on CentOS 7 / RHEL 7 Headless Server]
* [https://www.tecmint.com/multiple-virtual-machine-installation-using-network-install-kvm/ How to Deploy Multiple Virtual Machines using Network Install (HTTP, FTP and NFS) under KVM Environment]
* [https://www.tecmint.com/multiple-virtual-machine-installation-using-network-install-kvm/ How to Deploy Multiple Virtual Machines using Network Install (HTTP, FTP and NFS) under KVM Environment]
== qemu-system-x86_64 ==
* The command can be used to create or rung a VM. See https://www.linux-kvm.org/page/RunningKVM
* [https://fosspost.org/use-qemu-test-operating-systems-distributions/ How To Use QEMU To Test Operating Systems & Distributions]
* '''virt-install''' vs '''qemu-system-x86_64'''
** [https://www.stratoscale.com/blog/compute/using-bare-qemu-kvm-vs-libvirt-virt-install-virt-manager/ Using bare qemu-kvm vs. libvirt/virt-install/virt-manager]
* [https://subscription.packtpub.com/book/virtualization-and-cloud/9781788294676/1/ch01lvl1sec17/starting-the-qemu-vm-with-kvm-support To start a QEMU instance with KVM support]:
:<syntaxhighlight lang='bash'>
qemu-system-x86_64 -name debian \
  -vnc 146.20.141.254:0 -m 1024 \
  -drive format=raw,index=2,file=debian.img \
  -enable-kvm -daemonize
</syntaxhighlight>
:If we use Virtual Machine Manager program, you need to have KVM ('''lsmod | grep kvm''') installed on your system for this to work.
== Install using qcow2 image ==
* https://cloud.centos.org/centos/7/images/
* [https://forums.centos.org/viewtopic.php?t=67844 Requesting for username and Password for the CentOS7 Qcow image]
* [https://fabianlee.org/2020/03/14/kvm-testing-cloud-init-locally-using-kvm-for-a-centos-cloud-image/ KVM: Testing cloud-init locally using KVM for a CentOS cloud image]*
* [https://www.cyberciti.biz/faq/how-to-add-ssh-public-key-to-qcow2-linux-cloud-images-using-virt-sysprep/ How to add ssh key to qcow2 Linux cloud images using virt-sysprep]
== Running a virtual machine from a ramdisk ==
<ul>
<li>[https://en.wikipedia.org/wiki/List_of_RAM_drive_software List of RAM drive software] </li>
<li>[https://www.cloudsavvyit.com/10254/how-to-create-a-ram-drive-in-linux/ How to Create a RAM Drive in Linux]
<pre>
if [ "$(mount | grep -o "/mnt/ram")" != "/mnt/ram" ]; then
  sudo mkdir -p /mnt/ram
  sudo mount -t ramfs -o size=1g ramfs /mnt/ram
  sudo chown -R $(whoami):$(whoami) /mnt/ram
fi
mount | grep ram
sudo umount /mnt/ram
</pre> </li>
<li>https://youtu.be/fOaWrhLoVK0  </li>
<li>[https://kaurin.github.io/2018/Libvirt-In-Memory-Storage/ Libvirt In-Memory Storage]  </li>
<li>(Windows only) [https://techgenix.com/ram-disk/ USE A RAM DISK TO GET EXTREME PERFORMANCE FROM TEMPORARY VIRTUAL MACHINES]  </li>
<li>[https://www.linuxbabe.com/command-line/create-ramdisk-linux How to Easily Create RAM Disk on Debian, Ubuntu, Linux Mint, CentOS]. How to Create a RAM Disk in Any Linux Distro.
<pre>
sudo mkdir /tmp/ramdisk
sudo chmod 777 /tmp/ramdisk
htop  # check free ram
sudo mount -t tmpfs -o size=1G myramdisk /tmp/ramdisk
            # myramdisk is the device name I gave to it
mount | tail -n 1
sudo umount /tmp/ramdisk/
</pre>
Test RAM speed
<pre>
# test write speed
sudo dd if=/dev/zero of=/tmp/ramdisk/zero bs=4k count=100000
## 409600000 bytes (410 MB, 391 MiB) copied, 0.734813 s, 557 MB/s  # SATA SSD
## 409600000 bytes (410 MB, 391 MiB) copied, 0.18296 s, 2.2 GB/s  # NVME
# test read speed
sudo dd if=/tmp/ramdisk/zero of=/dev/null bs=4k count=100000
## 409600000 bytes (410 MB, 391 MiB) copied, 0.410809 s, 997 MB/s  # SATA SSD
## 409600000 bytes (410 MB, 391 MiB) copied, 0.139487 s, 2.9 GB/s  # NVME
</pre>
Auto-mount on System Boot
<pre>
sudo nano /etc/fstab
## myramdisk  /tmp/ramdisk  tmpfs  defaults,size=1G,x-gvfs-show  0  0
## To mount it immediately without reboot, run the following command.
sudo mount -a
</pre>
How to Run VirtualBox VM on RAM Disk. You should set the machine folder to the RAM disk directory ('''/tmp/ramdisk/''').
</li>
</ul>
== kvm command ==
* [https://helpmanual.io/man1/kvm/ help kvm]. The  '''kvm'''  wrapper  script  is  used  to  provide compatibility with old '''qemu-kvm''' package which has been merged into qemu as of version 1.3. The script executes '''qemu-system-x86_64 -enable-kvm''' passing all other command-line arguments to the qemu binary.
* [https://www.makeuseof.com/how-to-install-manjaro-linux-in-a-qemukvm-virtual-machine/ How to Install Manjaro Linux in a QEMU/KVM Virtual Machine]
= snapshot =
= snapshot =
<ul>
<ul>
Line 187: Line 493:
<li>
<li>
To create a snapshot using the GUI, open virtualization manager window. In the VM properties, click on the icon (two displays overlapped) which is on the right of the menu, which says '''Manage VM snapshots'''.
To create a snapshot using the GUI, open virtualization manager window. In the VM properties, click on the icon (two displays overlapped) which is on the right of the menu, which says '''Manage VM snapshots'''.
</li>
<li>
To restore a snapshot using '''Virtual Machine Manager''', right click on a snapshot and select "Start snapshot".
</li>
</li>
</ul>
</ul>


= GUI manager =
= GUI =
 
== Virtual Machine Manager/virt-manager, Cockpit, virt-viewer, remote-viewer ==
<pre>
sudo apt install cockpit cockpit-machines
</pre>
* https://cockpit-project.org/
* [https://www.answertopia.com/ubuntu/creating-ubuntu-kvm-virtual-machines-using-cockpit-and-virt-manager/ Creating Ubuntu 20.04 KVM Virtual Machines using Cockpit and virt-manager]*.
** It shows how to handle the error of cannot opening the ISO file.
** It shows how to use virt-viewer to connect to a VM ('''virt-viewer''')
** [http://manpages.ubuntu.com/manpages/bionic/man1/remote-viewer.1.html remote-viewer] will be used if we change the Console type from 'VNC' to 'Graphics Console in Desktop Viewer' and click the 'Launch Remote Viewer' button. A text file called 'download' will be downloaded. If we click it, it will launch '''remote-viewer'''. An interesting thing is the file will be automatically deleted once we click on it:)
* Consider running a VM on a ''remote'' machine with cockpit version 215.
** For Ubuntu 20.04.1 Desktop. If I increase the display resolution from 1024x768 (4:3) to others without keeping the same ratio, the mouse calibration has a problem:( Maybe it's better not to change the resolution. The VNC method works.
** For Windows 10, we need to unplug ethernet first in order to create a local account. I've not found a way to use virt-viewer or remote-viewer to view the desktop locally. I can still use cockpit web interface (Consoles) to use the Windows desktop. I am able to increase the display resolution to 1280x800 from 1024x768 which makes the interface easy for my eyes. '''One problem is the machine will freeze''' for some unknown reason.
<ul>
<ul>
<li>[https://ostechnix.com/manage-kvm-virtual-machines-using-cockpit-web-console/ Manage KVM Virtual Machines Using Cockpit Web Console]</li>
<li>[https://ostechnix.com/manage-kvm-virtual-machines-using-cockpit-web-console/ Manage KVM Virtual Machines Using Cockpit Web Console]</li>
<li>[https://ostechnix.com/how-to-manage-kvm-virtual-machines-with-virt-manager/ How To Manage KVM Virtual Machines With Virt-Manager]. View -> Graph ->  Memory Usage</li>
<li>[https://ostechnix.com/how-to-manage-kvm-virtual-machines-with-virt-manager/ How To Manage KVM Virtual Machines With Virt-Manager]. View -> Graph ->  Memory Usage. However, it seems the reported memory is correct for CentOS, but not Ubuntu or Windows.</li>
</ul>
</ul>
* [https://dbaxps.blogspot.com/2020/07/install-kvm-web-cockpit-console-on.html Install KVM && Web Cockpit Console on SparkyLinux 2020.6]
* Tip: it may help to use mouse to click the installation screen to refresh the screen if we don't see the progress bar to progress.
* [https://ostechnix.com/manage-kvm-virtual-machines-using-cockpit-web-console/ Manage KVM Virtual Machines Using Cockpit Web Console]
* [https://askubuntu.com/a/776107 Permission error in virtual machine manager]. Solution 1: use '''sudo sudo virt-manager'''  Solution 2: copy iso file to /tmp directory. Solution 3: change the owner of the iso file to '''libvirt-qemu:kvm'''  .
=== Network Install in virtual machine manager ===
* [https://opensource.com/article/19/6/create-centos-homelab-hour Create a CentOS homelab in an hour] (I tested it and got the same error as one reader).
* [https://www.tecmint.com/multiple-virtual-machine-installation-using-network-install-kvm/ How to Deploy Multiple Virtual Machines using Network Install (HTTP, FTP and NFS) under KVM Environment – Part 2]. This guide covers 3 approaches (ftp, nfs, http) so this is the most comprehensive!
=== Share folders ===
* [https://www.debugpoint.com/share-folder-virt-manager/ Share Folder Between Guest and Host in virt-manager (KVM/Qemu/libvirt)]
* [https://www.debugpoint.com/kvm-share-folder-windows-guest/ Share Folder Between Windows Guest and Linux Host in KVM using virtiofs]
=== remote-viewer/SPICE client ===
Example:
<syntaxhighlight lang='sh'>
$ remote-viewer spice://192.168.1.XXX:5900
</syntaxhighlight>
== How to quit full screen ==
[https://www.golinuxcloud.com/exit-full-screen-mode-in-qemu-virt-manager/ How to exit full screen mode in qemu virt-manager ( RHEL / CentOS 7)]. Hint: click the first of two icons shown at the top-center screen.
== Windows VM ==
* [https://www.makeuseof.com/create-windows-virtual-machine-in-linux-with-kvm/ How to Create a Windows Virtual Machine in Linux With KVM]
* [https://www.debugpoint.com/install-windows-ubuntu-virt-manager/ Install Windows 11 as Guest in Ubuntu using virt-manager]
* [https://getlabsdone.com/how-to-install-windows-11-on-kvm/ Windows 11 on KVM – How to Install Step by Step?]
=== USB host device ===
* [https://www.linux-kvm.org/page/USB_Host_Device_Assigned_to_Guest USB Host Device Assigned to Guest]
* '''Rufus''' + '''USB Passthrough''' in Virt-manager
** Create the Bootable USB with Rufus. Making sure to select the options to "Remove requirement for 4GB+ RAM, Secure Boot and TPM 2.0" and "Remove requirement for an online Microsoft account."
** Plug the USB Drive into your Host Machine
** Add the USB Drive to your VM in Virt-Manager. Add Hardware  -> '''USB Host Device'''. Select your USB flash drive from this list.
** Configure Boot Order by prioritizing the USB device.
== Windows VM by docker ==
[https://www.youtube.com/watch?v=xhGYobuG508 Running Windows in a Docker Container!]
== GNOME Boxes ==
* https://help.gnome.org/users/gnome-boxes/stable/
* [https://www.debugpoint.com/2020/05/install-use-gnome-boxes/ How to Install and Use GNOME Boxes to Create Virtual Machines]


= Network =
= Network =
Line 214: Line 577:
<li>[https://libvirt.org/formatnetwork.html Network XML format] </li>
<li>[https://libvirt.org/formatnetwork.html Network XML format] </li>
<li>[https://amoldighe.github.io/2017/12/20/kvm-networking/ KVM Networking - NAT & Host-Only] </li>
<li>[https://amoldighe.github.io/2017/12/20/kvm-networking/ KVM Networking - NAT & Host-Only] </li>
<li>[https://www.pitt-pladdy.com/blog/_20150620-151456_0100_Home_Lab_Project_Network_Bridges_for_KVM_-_NAT_Host-only_Isolated/ Home Lab Project: Network Bridges for KVM - NAT, Host-only, Isolated] </li>
<li>[https://www.pitt-pladdy.com/blog/_20150620-151456_0100_Home_Lab_Project_Network_Bridges_for_KVM_-_NAT_Host-only_Isolated/ Home Lab Project: Network Bridges for KVM - NAT, Host-only, Isolated]</li>
</ul>
</ul>
</li>
</li>


= Back and restore images =
== Find out the IP of the guest machine ==
* [https://ostechnix.com/how-to-find-the-ip-address-of-a-kvm-virtual-machine/ How To Find The IP Address Of A KVM Virtual Machine]
<pre>
# Method 1:
$ virsh list
$ virsh domifaddr centos8
 
# Method 2:
$ sudo apt install net-tools  # Debian
$ sudo dnf install net-tools  # CentOS
$ arp -n              # find the rows with virbr0 adapter
 
# Method 3:
# KVM -> Info -> NIC
</pre>
 
= Backup and restore images =
[https://techsoftcenter.com/how-to-kvm-backup-and-restore-in-linux/ How to KVM Backup and Restore in Linux]
[https://techsoftcenter.com/how-to-kvm-backup-and-restore-in-linux/ How to KVM Backup and Restore in Linux]
<pre>
* /etc/libvirt/qemu # location of xml files
* /var/lib/libvirt/images  # location of qcow2 files
<syntaxhighlight lang='sh'>
# Backup  
# Backup  
virsh list --all
sudo virsh list --all
virsh dumpxml win10 > /MyBackup/win10.xml
sudo virsh dumpxml win10 > /MyBackup/win10.xml
sudo cp /var/lib/libvirt/images/win10.qcow2 /MyBackup/win10.qcow2
sudo cp /var/lib/libvirt/images/win10.qcow2 /MyBackup/win10.qcow2
sudo chown $USER:$USER /MyBackup/*.qcow2
sudo chown $USER:$USER /MyBackup/*.qcow2


# Restore Making
# Restore Making
sudo virsh undefine win10
sudo virsh undefine win10 # delete xml (VM configuration) file
ls -l /etc/libvirt/qemu
sudo virsh list --all
virsh list --all
sudo rm /var/lib/libvirt/images/win10.qcow2 # delete qcow2 image file
sudo rm /var/lib/libvirt/images/win10.qcow2
 
sudo cp /MyBackup/win10.qcow2 /var/lib/libvirt/images/
sudo cp /MyBackup/win10.qcow2 /var/lib/libvirt/images/
sudo virsh define --file /MyBackup/win10.xml
sudo virsh define --file /MyBackup/win10.xml
# virsh start win10
# virsh start win10
</pre>
</syntaxhighlight>
 
== Free pre-built images ==
* Notes
*# We only need the image filew (like qcow2). We don't need xml files since virt-manager can recreate it.
*# '''.img''' is a generic disk image extension: The .img extension simply indicates that the file is a raw, sector-by-sector copy of a disk. It's a very generic term that doesn't necessarily imply a specific format like QCOW2 or RAW.
*# The actual format is QCOW2: Despite the .img extension, the Ubuntu cloud images that are intended for QEMU/KVM (the *-cloudimg-amd64.img files) are indeed internally formatted as QCOW2 (QEMU Copy On Write 2).
*# You can verify this yourself using the qemu-img command-line tool, which is part of the QEMU package on your Linux host: '''qemu-img info noble-server-cloudimg-amd64.img'''
*# There is no default username/password. They are designed to be provisioned using SSH keys and a service called '''cloud-init'''. [https://www.techchorus.net/posts/automating-virtual-machine-installation-using-libvirt-virsh-and-cloud-init/ Automating Virtual Machine Installation Using libvirt, virsh And cloud-init], [https://earlruby.org/2023/02/quickly-create-guest-vms-using-virsh-cloud-image-files-and-cloud-init/ Quickly create guest VMs using virsh, cloud image files, and cloud-init].
 
* Official Distribution Sites [https://docs.openstack.org/image-guide/obtain-images.html OpenStack Image Guide]:
** Ubuntu Cloud Images: https://cloud-images.ubuntu.com/ (look for *.qcow2 files)
** Debian Cloud Images: https://cloud.debian.org/images/cloud/
** Fedora Cloud Images: https://alt.fedoraproject.org/cloud/
* Pre-Built VM Images from Third-Party Sites
** There are websites that compile and offer pre-built VM images, often in formats suitable for VirtualBox (.vdi, .ova) or VMware (.vmdk, .ova), but some also provide QCOW2. These are usually general-purpose desktop or server installations.
** OSBoxes.org: https://www.osboxes.org/ offers a wide variety of Linux distributions as ready-to-use virtual machines. While they primarily list VirtualBox and VMware images, you might find QCOW2 or be able to convert them if needed.
** LinuxVMImages.com: https://www.linuxvmimages.com/ Similar to OSBoxes, focusing on various Linux flavors.


= Cheat sheet =
= Cheat sheet =
[https://blog.programster.org/kvm-cheatsheet KVM Cheatsheet]
[https://blog.programster.org/kvm-cheatsheet KVM Cheatsheet]
= Vagrant =
* https://www.vagrantup.com/
* [https://ostechnix.com/how-to-use-vagrant-with-libvirt-kvm-provider/ How To Use Vagrant With Libvirt KVM Provider]
* [https://www.lynda.com/Vagrant-tutorials/Learning-Vagrant/685028-2.html Learning vagrant] (Lynda.com)
* [https://leftasexercise.com/2020/05/15/managing-kvm-virtual-machines-part-i-vagrant-and-libvirt/ Managing KVM virtual machines part I – Vagrant and libvirt] (it has a nice diagram to show a big picture of things related to '''libvirt'''),
** [https://leftasexercise.com/2020/05/18/managing-kvm-virtual-machines-part-ii-the-libvirt-toolkit/ Managing KVM virtual machines part II – the libvirt toolkit],
** [https://leftasexercise.com/2020/05/22/managing-kvm-virtual-machines-part-iii-using-libvirt-with-ansible/ Managing KVM virtual machines part III – using libvirt with Ansible]
* [https://computingforgeeks.com/using-vagrant-with-libvirt-on-linux/ How To Use Vagrant with '''Libvirt''' on Linux]
= How to Use Virtualbox VMs on KVM In Linux =
[https://www.tecmint.com/migrate-virtualbox-vms-into-kvm-vms/ How to Use Virtualbox VMs on KVM In Linux]


= Run macOS on KVM / QEMU =
= Run macOS on KVM / QEMU =
[https://computingforgeeks.com/how-to-run-macos-on-kvm-qemu/ How To run macOS on KVM / QEMU]
* [https://computingforgeeks.com/how-to-run-macos-on-kvm-qemu/ How To run macOS on KVM / QEMU]
* [https://www.linuxuprising.com/2021/03/install-macos-big-sur-or-catalina-in.html Install macOS Big Sur Or Catalina In A Virtual Machine Using Docker-OSX]
* [https://www.makeuseof.com/macos-ubuntu-linux-virtual-machine/ How To Install macOS in a Virtual Machine on Ubuntu Linux]
 
= Run SteamOS on QEMU =
[https://blogs.igalia.com/berto/2022/07/05/running-the-steam-decks-os-in-a-virtual-machine-using-qemu/ Running the Steam Deck’s OS in a virtual machine using QEMU]
 
= QuickEMU =
* [https://github.com/quickemu-project/quickemu QuickEMU] - Quickly create and run optimised Windows, macOS and Linux desktop virtual machines
* [https://www.tomshardware.com/how-to/run-windows-11-and-mac-os-virtual-machines-in-linux How To Run Windows 11 and macOS Virtual Machines in Linux] (enough screenshots)
* [https://bytexd.com/use-quickemu-to-run-windows-macos-linux-virtual-machines/ Use Quickemu to Run Windows, macOS & Linux Virtual Machines]
* [https://www.linuxuprising.com/2021/12/quickly-create-and-run-optimized-linux.html Quickly Create And Run Optimized Linux, macOS And Windows Virtual Machines With Quickemu (With Auto ISO Download)]
* (video) By [https://www.youtube.com/watch?v=87MCT3Ekjlo Chris Titus Tech]
 
Some lessons:
* [https://github.com/quickemu-project/quickemu/wiki/02-Create-Linux-virtual-machines Create Linux virtual machines] & [https://github.com/quickemu-project/quickemu/wiki/05-Advanced-quickemu-configuration Advanced quickemu configuration]
:<syntaxhighlight lang='sh'>
quickget -h  # list of all OSs
quickget ubuntu 24.04
quickemu --vm ubuntu-24.04.conf --display spice
du -sh ubuntu-24.04 # 6.0G
</syntaxhighlight>
:<syntaxhighlight lang='sh'>
# Install the SPICE agent (spice-vdagent) in the guest to enable copy/paste and USB redirection
sudo apt install spice-vdagent
ps aux | grep spice-vdagent
sudo systemctl start spice-vdagent
sudo systemctl enable spice-vdagent
 
# Install the SPICE WebDAV agent (spice-webdavd) in the guest to enable file sharing.
sudo apt install spice-webdavd
</syntaxhighlight>
* By default new folders are created when we create/download guest machine in the home folder. We can create a new folder for managing these guest machines.
* Use Ctrl+Alt+g to release the mouse. The hint is at the top of window.
* Change boot="legacy" in '''windows-11.conf''' helps to show the Windows installation process (See [https://reposhub.com/linux/shell-package-management/wimpysworld-quickemu.html Simple shell script to "manage" Qemu virtual machines.]). But it still failed ''Windows could not create a partition on disk 0. The error occurred while applying the unattend answer file's <DiskConfiguration> setting. Error code: 0x80042565.''
* When I tried to install quickemu on another freshly installed xubuntu 20.04 focal fossa (Core2 Quad CPU), the installation went through without any problem.
* The app running the guest machine is '''spicy'''.
* I can install macOS Catalina, Windows 11, etc. The trick to install macOS is '''manually reboot''' the guest machine a couple times. Also it is useful to play the "Options -> Scale display" option in "spicy" to better see the text when we install macOS. Then it works.
* I need to use '''Shift + F12''' (see the hint at the bottom of spicy window) to release mouse (or exit full display) in [https://github.com/freedesktop/spice-gtk spicy] (the GUI where the guest machine is running) on my Ubuntu. '''When installing macOS, I need to use my keyboard''' (mouse does not work) to select the hdd for booting macOS (or just wait a few seconds & the 1st drive will be used to boot).
* It helps to drag and enlarge the guest machine window (by default 'Scale display' option is checked).
* When installing macOS, the screen says "About X minutes remaining". But it seems [https://github.com/quickemu-project/quickemu/issues/228 it stuck there] (the minutes is not changed) though the CPU is busy. If I closed the window, shutdown the guest machine and reboot it, installation continues. Doing this a few times and eventually a new window ("[https://github.com/quickemu-project/quickemu/issues/278 Select Your Country or Region]") will come up. In order to monitor the download, I open another terminal and run something like '''watch du -s ~/macos-big-sur'''. This will help me to decide when to restart the VM. For big-sur, the folder size stops at 26655436 and after I reboot the VM, the folder size keep increasing and stops at 32565600. For the 3rd reboot, it still downloads something and needs 2 internal reboots. So I think the problem is the data needs to be downloaded from Apple server is TOO large.
* macos-big-sur & macos-monterey took about 32G & 34G space.
* Every time I boot macOS, I shall use the right arrow to select the 2nd icon and press the Enter button to start.
* macOS Catalina asks at least 4 characters for the password (I choose 6)
* For macOS Catalina/Monterey guest machine, it automatically allocates 2 CPUs(?), 4/8GB RAM (depending on the host total RAM?), 100GB storage by default. After installing macOS, 75GB will still be available.
* (Maybe related to Ubuntu 22.04 host using wayland). Whenever I start macOS vm, it pops up a window "Allow inhibiting shortcuts. The application spicy wants to inhibit shortcuts. You can restore shortcuts by pressing Super+Escape." I choose the default "Allow" and it seems to be OK. PS: I need to do this action quickly or the macOS window will go to black and not responds to my keyboard/mouse.
* Windows 11 [https://github.com/quickemu-project/quickemu/issues/1475 bug and solution]
* For Windows 11 guest machine, it allocates 2 CPUs, 4/8GB RAM, 64GB storage with 43GB free.
* For Lubuntu guest machine (much better speed than macOS/Windows VM, fill full screen, Qt/KDE based), it allocates 2 CPUs, 4GB RAM, 16GB storage with 8.4GB free.
 
Build QEMU from source
* https://askubuntu.com/a/1198927
* [https://mathiashueber.com/manually-update-qemu-on-ubuntu-18-04/ How to update QEMU on Ubuntu]
 
== quickget ==
'''quickget os release edition'''
<pre>
quickget -h
quickget fedora 42 COSMIC
</pre>
 
== quickemu with own iso ==
Consider the example of Diet Pi
<ul>
<li>Download UEFI x86 dietpi iso file and move it to a folder "DietPi".
<li>Create a file '''dietpi.conf'''
<pre>
guest_os="linux"
iso="DietPi/DietPi_NativePC-UEFI-x86_64-Bookworm_Installer.iso" # Adjust filename
disk_img="DietPi/dietpi_vm.qcow2"
disk_size="10G"
ram="2G" # Adjust as needed
cpu_cores="2" # Adjust as needed
# You won't typically need an 'iso=' line if you're booting from a pre-made image
# Add other Quickemu options as desired (e.g., network, port_forwards)
</pre>
<li>Run
<pre>
quickemu --vm dietpi.conf
</pre>
During the installation, you'll see the Clonezilla interface, which helps flash the DietPi system to your virtual disk. Ensure you select the correct target virtual disk (e.g., /dev/vda or similar, usually the only one presented apart from the ISO).
 
After diet pi shut down, run 'quickemu --vm dietpi.conf' again.
 
The installation took a while and required user interaction.
 
The default username/password is root/dietpi.
</ul>
 
== ssh to VM ==
* Suppose my VM is Ubuntu 24.04
<pre>
sudo apt install openssh-server
sudo systemctl start ssh
sudo systemctl enable ssh
</pre>
* On my host, it shows ssh port 22221. It means this port on your Manjaro host is forwarded to port 22 (the standard SSH port) on your Ubuntu VM.
<pre>
ls ubuntu-24.04
cat ubuntu-24.04/ubuntu-24.04.ports
</pre>
* On my host
<pre>
ssh -p 22221 username@localhost
</pre>
* To ssh from VM to host
<pre>
</pre>
 
== Adjust VM storage ==
If I just want to delete the old VM and start a new VM, I can just run
<pre>
quickemu --vm ubuntu-24.04.conf --delete-disk
nano ubuntu-24.04.conf # Add a line disk_size="50G"
quickemu --vm ubuntu-24.04.conf
</pre>
 
== Adjust RAM ==
Add a line '''ram="4G" ''' to the .conf file.
 
== Sound ==
It works automatically (tested on MX Linux VM and Ubuntu VM).
 
== DistroSea ==
* https://distrosea.com/
* [https://ostechnix.com/test-linux-distros-online-with-distrosea/ How To Test Linux Distros Online With DistroSea]
* [https://allthings.how/how-to-try-linux-in-a-browser-with-distrosea/ How to try Linux in a browser with DistroSea]
* [https://www.howtogeek.com/ways-to-test-a-linux-distro-without-a-usb-drive/ 3 Ways to Test a Linux Distro Without Using a USB Drive]
** The default setup for most Docker containers is terminal access only, but you can totally set up things like noVNC, which is the same software that DistroSea uses.
 
= Nested KVM =
[https://www.howtogeek.com/devops/how-to-enable-nested-kvm-virtualization/ How to Enable Nested KVM Virtualization]

Latest revision as of 19:25, 21 September 2025

Resource

Big picture

  • KVM is the acceleration technology in the kernel.
  • QEMU is the software that runs the VMs, using KVM for speed.
  • libvirt is the management layer that abstracts away the complexity of KVM/QEMU.
  • virsh is the command-line tool for libvirt.
  • virt-manager is the GUI tool for libvirt
+-------------------+      +-------------------+
|   Physical Host   |      |     Guest OS      |
|    (Your PC)      |      |   (e.g., Windows/Linux) |
|                   |      |                   |
| +-----------------+-----+ |  +---------------+--+
| |     Hardware    |     | |  | VM Applications  |
| |   (CPU, RAM,    |     | |  |   (Browser, IDE) |
| |    Disks, NIC)  |     | |  +------------------+
| +-------+---------+     | |
|         |               | |
|         |               | |
| +-------v---------+     | |
| |   Linux Kernel  |     | |
| | (incl. KVM module)|<----+------> Disk (Virtual)
| +-------+---------+     | |  +---------------+--+
|         ^               | |  |    Guest OS     |
|         |  (Hardware   | |  |   Kernel/Drivers|
|         |   Acceleration)| |  +------------------+
|         |               | |
| +-------+---------+     | |
| |     QEMU        |     | |
| | (User-space VM  |     | |
| |   Emulator)     |     | |
| +-------^---------+     | |
|         |               | |
|         | (Manages VMs, | |
|         |  Networks, etc.)| |
| +-------+---------+     | |
| |   libvirtd      |     | |
| |   (Daemon)      |     | |
| +-------^---------+     | |
|         |               | |
|         | (API/Calls)   | |
| +-------+---------+     | |
| |     virsh       |     | |
| |   (CLI Tool)    |     | |
| +-----------------+-----+ |
|         ^               | |
|         |               | |
| +-------+---------+     | |
| | virt-manager    |     | |
| |   (GUI Tool)    |     | |
| +-----------------+-----+ |
|                   |       |
+-------------------+       +-------------------+

QEMU

How to Use QEMU to Boot Another Operating System

QEMU vs. KVM

QEMU vs. KVM: Which Should You Use for Virtualization? QEMU uses full system emulation, allowing it to emulate a complete computer system, including the processor, memory, storage, and peripheral devices. This flexibility makes QEMU an excellent choice for cross-platform virtualization since it supports a wide range of architectures.

libvirt

  • https://en.wikipedia.org/wiki/Libvirt. libvirt is an open-source API, daemon and management tool for managing platform virtualization.[3] It can be used to manage KVM, Xen, VMware ESXi, QEMU and other virtualization technologies.
  • https://libvirt.org/
  • Check libvirt version: sudo head -n2 /var/log/libvirt/qemu/ubuntu2004.log # on Ubuntu 20.04 it shows 6.0.0

"virt-install" to install or delete a VM

$ virt-install --help | grep graphics
$ osinfo-query os 

$ sudo virt-install  -n ubuntu2004 --os-type=Linux  \
  --os-variant=ubuntu18.04  --ram=2096  --vcpus=2  \
  --disk size=20  \
  --network network=br0 \
  --graphics vnc,listen=0.0.0.0  \
  --location Downloads/ubuntu-20.04.1-desktop-amd64.iso

$ sudo virt-install --name=centos7server \
  --os-type=Linux \
  --os-variant=centos7.0 \
  --vcpu=2 --ram=2048 \
  --disk size=20 \
  --graphics vnc \
  --location=/tmp/CentOS-7-x86_64-DVD-2009.iso

# Running locally
$ sudo virt-install  -n ubuntu20043 --os-type=Linux  \
  --os-variant=ubuntu20.04  \
  --ram=4096  --vcpus=2  \
  --disk size=20  \
  --network network=default  \
  --cdrom ~/Downloads/ubuntu-20.04.3-desktop-amd64.iso

NB

  • If we just run a live session and power off the VM, it will automatically reject the installation medium (iso file) and reboot. So eventually it showed a message "No bootable device."
  • Using the Virtual Machine Manager GUI I found after I tried to delete a VM it won't actually delete the image file created in /var/lib/libvirt/images. Be careful when deleting files there. See How to delete KVM VM guest using virsh command & Removing and deleting a VM from RedHat.
    $ virsh list --all
     Id   Name                State
    ------------------------------------
     39   ubuntu20043         running
    
    $ virsh dumpxml --domain ubuntu20043 | grep 'source file' 
          <source file='/var/lib/libvirt/images/ubuntu20043.qcow2' index='2'/>
    
    $ sudo virsh destroy ubuntu20043  # SHUT DOWN
    
    # "sudo virsh undefine ubuntu20043" WILL LEAVE qcow2
    
    $ sudo virsh undefine ubuntu20043 --remove-all-storage 
    Domain 'ubuntu20043' has been undefined
    Volume 'vda'(/var/lib/libvirt/images/ubuntu20043.qcow2) removed.
    
    $ sudo ls -lt /var/lib/libvirt/images/
    

Check if running in VM

9 things to do in your first 10 minutes on a Linux server

$ cat /sys/class/dmi/id/sys_vendor 
QEMU

$ sudo dmidecode -s system-manufacturer 
QEMU

On VirtualBox + CentOS vm, it returns "innotek GmbH".

On VMware + CentOS vm, it returns "VMware, Inc".

Guest additions

It seems QEUM/KVM does not have that to download.

Bridge network

  • There are different ways to configure the network in Ubuntu.
    • If we are using a Ubuntu server, we will use the Netplan method.
    • If we are using a Ubuntu desktop, we will use the Network manager command line nmcli method or the GUI tool nm-connection-editor.
  • Use nmcli to add a bridge network and a bridge slave interface
    sudo nmcli con add ifname br0 type bridge con-name br0
    sudo nmcli con add ifname eno1 type bridge-slave master br0
    
  • Use nmcli to bring down a wired network and bring up a bridge network
    sudo nmcli con down "Wired connection 1"
    sudo nmcli con up br0
    
  • Use nmcli to delete unused bridge networks
    sudo nmcli device show
    sudo nmcli con show
    sudo nmcli con del "br0"
    

Install

Install on Ubuntu

Where are image files saved

Install on Arch/Manjaro

VNC

  • KVM/QEMU 以 virt-install 指令建立虛擬機器、VNC 顯示畫面教學
    sudo virt-install --virt-type kvm --name ubuntu1804 --ram 2048 
      --disk /home/seal/kvm/ubuntu1804.qcow2,format=qcow2 
      --network network=default 
      --graphics vnc,listen=0.0.0.0,password=YOUR_PASSWORD 
      --noautoconsole 
      --os-type=linux --os-variant=ubuntu17.10 
      --cdrom=/home/seal/Downloads/ubuntu-18.10-desktop-amd64.iso
    
    virsh vncdisplay ubuntu1804 #  127.0.0.1:1
                                # pay attention to the port number
                                # :0  --> 5900 in ssh
                                # :1  --> 5901 in ssh
    sudo ufw disable
    
    # Another machine. 
    # Suppose the host machine has an IP 192.168.0.3
    ssh -NL 5901:localhost:5901 [email protected]
    ssh -NL 5901:127.0.0.1:5901 [email protected]
    
    vncviewer 127.0.0.1:1 # from a different machine
    

    NOTE: I have to use local port forwarding. If I try to directly connect to the VM in RealVNC, it will show The connection was refused by the computer. A limit by KVM?

The question is how do we know the client's IP? I guess cockpit method is better.

Install qemu-system-arm in Ubuntu

  • sudo apt install qemu-system-arm
  • How to emulate Raspberry Pi in QEMU which is based on qemu-rpi-kernel-Qemu kernel for emulating Rpi on QEMU.
    mkdir rpi-vm && cd rpi-vm
    git clone https://github.com/dhruvvyas90/qemu-rpi-kernel.git
    
    # Download Raspbian Buster Lite
    # from https://www.raspberrypi.org/downloads/raspberry-pi-os/
    dd if=/dev/zero bs=1M count=4096 >> 2020-08-20-raspios-buster-armhf-lite.img
    
    sudo losetup -f -P --show 2020-08-20-raspios-buster-armhf-lite.img
    
    sudo mount -o rw /dev/loopXp2 /mnt
    
    sudo nano /mnt/etc/fstab
    
    sudo nano /etc/ld.so.preload # Comment out the line and save the file. 
    # Then unmount with the following commands:
    # sudo umount /mnt
    # sudo losetup -d /dev/loopX
    
    qemu-system-arm \
      -M versatilepb \
      -cpu arm1176 \
      -m 256 \
      -kernel qemu-rpi-kernel/kernel-qemu-4.19.50-buster \
      -hda 2020-08-20-raspios-buster-armhf-lite.img \
      -append "dwc_otg.lpm_enable=0 root=/dev/sda2 console=tty1 rootfstype=ext4 elevator=deadline rootwait" \
      -dtb qemu-rpi-kernel/versatile-pb-buster.dtb \
      -no-reboot \
      -serial stdio
    
    # We can install a desktop. See 
    # https://www.raspberrypi.org/forums/viewtopic.php?t=133691
    

Install on CentOS

qemu-system-x86_64

qemu-system-x86_64 -name debian \
  -vnc 146.20.141.254:0 -m 1024 \
  -drive format=raw,index=2,file=debian.img \
  -enable-kvm -daemonize
If we use Virtual Machine Manager program, you need to have KVM (lsmod | grep kvm) installed on your system for this to work.

Install using qcow2 image

Running a virtual machine from a ramdisk

  • List of RAM drive software
  • How to Create a RAM Drive in Linux
    if [ "$(mount | grep -o "/mnt/ram")" != "/mnt/ram" ]; then
      sudo mkdir -p /mnt/ram
      sudo mount -t ramfs -o size=1g ramfs /mnt/ram
      sudo chown -R $(whoami):$(whoami) /mnt/ram
    fi
    mount | grep ram
    
    sudo umount /mnt/ram
    
  • https://youtu.be/fOaWrhLoVK0
  • Libvirt In-Memory Storage
  • (Windows only) USE A RAM DISK TO GET EXTREME PERFORMANCE FROM TEMPORARY VIRTUAL MACHINES
  • How to Easily Create RAM Disk on Debian, Ubuntu, Linux Mint, CentOS. How to Create a RAM Disk in Any Linux Distro.
    sudo mkdir /tmp/ramdisk
    sudo chmod 777 /tmp/ramdisk
    htop  # check free ram
    sudo mount -t tmpfs -o size=1G myramdisk /tmp/ramdisk
                # myramdisk is the device name I gave to it
    mount | tail -n 1
    sudo umount /tmp/ramdisk/
    

    Test RAM speed

    # test write speed
    sudo dd if=/dev/zero of=/tmp/ramdisk/zero bs=4k count=100000
    ## 409600000 bytes (410 MB, 391 MiB) copied, 0.734813 s, 557 MB/s  # SATA SSD
    ## 409600000 bytes (410 MB, 391 MiB) copied, 0.18296 s, 2.2 GB/s   # NVME
    
    # test read speed
    sudo dd if=/tmp/ramdisk/zero of=/dev/null bs=4k count=100000
    ## 409600000 bytes (410 MB, 391 MiB) copied, 0.410809 s, 997 MB/s  # SATA SSD
    ## 409600000 bytes (410 MB, 391 MiB) copied, 0.139487 s, 2.9 GB/s  # NVME
    

    Auto-mount on System Boot

    sudo nano /etc/fstab
    ## myramdisk  /tmp/ramdisk  tmpfs  defaults,size=1G,x-gvfs-show  0  0
    
    ## To mount it immediately without reboot, run the following command.
    sudo mount -a 
    

    How to Run VirtualBox VM on RAM Disk. You should set the machine folder to the RAM disk directory (/tmp/ramdisk/).

kvm command

snapshot

  • How to Create, Revert and Delete KVM Virtual machine (domain) snapshot with virsh command, How to create snapshot in Linux KVM VM/Domain
    $ sudo su
    # virsh list --all
    
    # virsh snapshot-create-as --domain win10 --name win10_snap --description "Windows 10 snapshot"    # Create a snapshot
    # virsh snapshot-list win10
    # virsh snapshot-info --domain win10 --snapshotname win10_snap
    
    # virsh snapshot-revert win10 win10_snap    # Restore
    
    # virsh snapshot-delete --domain win10 --snapshotname win10_snap
    
  • To create a snapshot using the GUI, open virtualization manager window. In the VM properties, click on the icon (two displays overlapped) which is on the right of the menu, which says Manage VM snapshots.
  • To restore a snapshot using Virtual Machine Manager, right click on a snapshot and select "Start snapshot".

GUI

Virtual Machine Manager/virt-manager, Cockpit, virt-viewer, remote-viewer

sudo apt install cockpit cockpit-machines
  • https://cockpit-project.org/
  • Creating Ubuntu 20.04 KVM Virtual Machines using Cockpit and virt-manager*.
    • It shows how to handle the error of cannot opening the ISO file.
    • It shows how to use virt-viewer to connect to a VM (virt-viewer)
    • remote-viewer will be used if we change the Console type from 'VNC' to 'Graphics Console in Desktop Viewer' and click the 'Launch Remote Viewer' button. A text file called 'download' will be downloaded. If we click it, it will launch remote-viewer. An interesting thing is the file will be automatically deleted once we click on it:)
  • Consider running a VM on a remote machine with cockpit version 215.
    • For Ubuntu 20.04.1 Desktop. If I increase the display resolution from 1024x768 (4:3) to others without keeping the same ratio, the mouse calibration has a problem:( Maybe it's better not to change the resolution. The VNC method works.
    • For Windows 10, we need to unplug ethernet first in order to create a local account. I've not found a way to use virt-viewer or remote-viewer to view the desktop locally. I can still use cockpit web interface (Consoles) to use the Windows desktop. I am able to increase the display resolution to 1280x800 from 1024x768 which makes the interface easy for my eyes. One problem is the machine will freeze for some unknown reason.

Network Install in virtual machine manager

Share folders

remote-viewer/SPICE client

Example:

$ remote-viewer spice://192.168.1.XXX:5900

How to quit full screen

How to exit full screen mode in qemu virt-manager ( RHEL / CentOS 7). Hint: click the first of two icons shown at the top-center screen.

Windows VM

USB host device

  • USB Host Device Assigned to Guest
  • Rufus + USB Passthrough in Virt-manager
    • Create the Bootable USB with Rufus. Making sure to select the options to "Remove requirement for 4GB+ RAM, Secure Boot and TPM 2.0" and "Remove requirement for an online Microsoft account."
    • Plug the USB Drive into your Host Machine
    • Add the USB Drive to your VM in Virt-Manager. Add Hardware -> USB Host Device. Select your USB flash drive from this list.
    • Configure Boot Order by prioritizing the USB device.

Windows VM by docker

Running Windows in a Docker Container!

GNOME Boxes

Network

Find out the IP of the guest machine

# Method 1:
$ virsh list
$ virsh domifaddr centos8

# Method 2:
$ sudo apt install net-tools   # Debian
$ sudo dnf install net-tools   # CentOS
$ arp -n               # find the rows with virbr0 adapter

# Method 3:
# KVM -> Info -> NIC

Backup and restore images

How to KVM Backup and Restore in Linux

  • /etc/libvirt/qemu # location of xml files
  • /var/lib/libvirt/images # location of qcow2 files
# Backup 
sudo virsh list --all
sudo virsh dumpxml win10 > /MyBackup/win10.xml
sudo cp /var/lib/libvirt/images/win10.qcow2 /MyBackup/win10.qcow2
sudo chown $USER:$USER /MyBackup/*.qcow2

# Restore Making
sudo virsh undefine win10 # delete xml (VM configuration) file 
sudo virsh list --all
sudo rm /var/lib/libvirt/images/win10.qcow2 # delete qcow2 image file

sudo cp /MyBackup/win10.qcow2 /var/lib/libvirt/images/
sudo virsh define --file /MyBackup/win10.xml
# virsh start win10

Free pre-built images

  • Notes
    1. We only need the image filew (like qcow2). We don't need xml files since virt-manager can recreate it.
    2. .img is a generic disk image extension: The .img extension simply indicates that the file is a raw, sector-by-sector copy of a disk. It's a very generic term that doesn't necessarily imply a specific format like QCOW2 or RAW.
    3. The actual format is QCOW2: Despite the .img extension, the Ubuntu cloud images that are intended for QEMU/KVM (the *-cloudimg-amd64.img files) are indeed internally formatted as QCOW2 (QEMU Copy On Write 2).
    4. You can verify this yourself using the qemu-img command-line tool, which is part of the QEMU package on your Linux host: qemu-img info noble-server-cloudimg-amd64.img
    5. There is no default username/password. They are designed to be provisioned using SSH keys and a service called cloud-init. Automating Virtual Machine Installation Using libvirt, virsh And cloud-init, Quickly create guest VMs using virsh, cloud image files, and cloud-init.

Cheat sheet

KVM Cheatsheet

Vagrant

How to Use Virtualbox VMs on KVM In Linux

How to Use Virtualbox VMs on KVM In Linux

Run macOS on KVM / QEMU

Run SteamOS on QEMU

Running the Steam Deck’s OS in a virtual machine using QEMU

QuickEMU

Some lessons:

quickget -h  # list of all OSs
quickget ubuntu 24.04
quickemu --vm ubuntu-24.04.conf --display spice
du -sh ubuntu-24.04 # 6.0G
# Install the SPICE agent (spice-vdagent) in the guest to enable copy/paste and USB redirection
sudo apt install spice-vdagent
ps aux | grep spice-vdagent
sudo systemctl start spice-vdagent
sudo systemctl enable spice-vdagent

# Install the SPICE WebDAV agent (spice-webdavd) in the guest to enable file sharing.
sudo apt install spice-webdavd
  • By default new folders are created when we create/download guest machine in the home folder. We can create a new folder for managing these guest machines.
  • Use Ctrl+Alt+g to release the mouse. The hint is at the top of window.
  • Change boot="legacy" in windows-11.conf helps to show the Windows installation process (See Simple shell script to "manage" Qemu virtual machines.). But it still failed Windows could not create a partition on disk 0. The error occurred while applying the unattend answer file's <DiskConfiguration> setting. Error code: 0x80042565.
  • When I tried to install quickemu on another freshly installed xubuntu 20.04 focal fossa (Core2 Quad CPU), the installation went through without any problem.
  • The app running the guest machine is spicy.
  • I can install macOS Catalina, Windows 11, etc. The trick to install macOS is manually reboot the guest machine a couple times. Also it is useful to play the "Options -> Scale display" option in "spicy" to better see the text when we install macOS. Then it works.
  • I need to use Shift + F12 (see the hint at the bottom of spicy window) to release mouse (or exit full display) in spicy (the GUI where the guest machine is running) on my Ubuntu. When installing macOS, I need to use my keyboard (mouse does not work) to select the hdd for booting macOS (or just wait a few seconds & the 1st drive will be used to boot).
  • It helps to drag and enlarge the guest machine window (by default 'Scale display' option is checked).
  • When installing macOS, the screen says "About X minutes remaining". But it seems it stuck there (the minutes is not changed) though the CPU is busy. If I closed the window, shutdown the guest machine and reboot it, installation continues. Doing this a few times and eventually a new window ("Select Your Country or Region") will come up. In order to monitor the download, I open another terminal and run something like watch du -s ~/macos-big-sur. This will help me to decide when to restart the VM. For big-sur, the folder size stops at 26655436 and after I reboot the VM, the folder size keep increasing and stops at 32565600. For the 3rd reboot, it still downloads something and needs 2 internal reboots. So I think the problem is the data needs to be downloaded from Apple server is TOO large.
  • macos-big-sur & macos-monterey took about 32G & 34G space.
  • Every time I boot macOS, I shall use the right arrow to select the 2nd icon and press the Enter button to start.
  • macOS Catalina asks at least 4 characters for the password (I choose 6)
  • For macOS Catalina/Monterey guest machine, it automatically allocates 2 CPUs(?), 4/8GB RAM (depending on the host total RAM?), 100GB storage by default. After installing macOS, 75GB will still be available.
  • (Maybe related to Ubuntu 22.04 host using wayland). Whenever I start macOS vm, it pops up a window "Allow inhibiting shortcuts. The application spicy wants to inhibit shortcuts. You can restore shortcuts by pressing Super+Escape." I choose the default "Allow" and it seems to be OK. PS: I need to do this action quickly or the macOS window will go to black and not responds to my keyboard/mouse.
  • Windows 11 bug and solution
  • For Windows 11 guest machine, it allocates 2 CPUs, 4/8GB RAM, 64GB storage with 43GB free.
  • For Lubuntu guest machine (much better speed than macOS/Windows VM, fill full screen, Qt/KDE based), it allocates 2 CPUs, 4GB RAM, 16GB storage with 8.4GB free.

Build QEMU from source

quickget

quickget os release edition

quickget -h
quickget fedora 42 COSMIC

quickemu with own iso

Consider the example of Diet Pi

  • Download UEFI x86 dietpi iso file and move it to a folder "DietPi".
  • Create a file dietpi.conf
    guest_os="linux" 
    iso="DietPi/DietPi_NativePC-UEFI-x86_64-Bookworm_Installer.iso" # Adjust filename
    disk_img="DietPi/dietpi_vm.qcow2"
    disk_size="10G"
    ram="2G" # Adjust as needed
    cpu_cores="2" # Adjust as needed
    # You won't typically need an 'iso=' line if you're booting from a pre-made image
    # Add other Quickemu options as desired (e.g., network, port_forwards)
    
  • Run
    quickemu --vm dietpi.conf
    

    During the installation, you'll see the Clonezilla interface, which helps flash the DietPi system to your virtual disk. Ensure you select the correct target virtual disk (e.g., /dev/vda or similar, usually the only one presented apart from the ISO).

    After diet pi shut down, run 'quickemu --vm dietpi.conf' again.

    The installation took a while and required user interaction.

    The default username/password is root/dietpi.

ssh to VM

  • Suppose my VM is Ubuntu 24.04
sudo apt install openssh-server
sudo systemctl start ssh
sudo systemctl enable ssh
  • On my host, it shows ssh port 22221. It means this port on your Manjaro host is forwarded to port 22 (the standard SSH port) on your Ubuntu VM.
ls ubuntu-24.04
cat ubuntu-24.04/ubuntu-24.04.ports
  • On my host
ssh -p 22221 username@localhost
  • To ssh from VM to host
ssh [email protected]

Adjust VM storage

If I just want to delete the old VM and start a new VM, I can just run

quickemu --vm ubuntu-24.04.conf --delete-disk
nano ubuntu-24.04.conf # Add a line disk_size="50G"
quickemu --vm ubuntu-24.04.conf

Adjust RAM

Add a line ram="4G" to the .conf file.

Sound

It works automatically (tested on MX Linux VM and Ubuntu VM).

DistroSea

Nested KVM

How to Enable Nested KVM Virtualization