Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

QEMU/KVM For Starters

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

QEMU/KVM For Starters

#1 Post by pwzhangzz »

There are two recent tutorials for those who are interested in playing with QEMU/KVM:

https://linuxconfig.org/setting-up-virt ... ian-ubuntu

(Setting Up Virtual Machines with QEMU, KVM, and Virt-Manager on Debian)

https://linuxconfig.org/converting-virt ... deployment

(Converting VirtualBox OVA to QCOW2 for QEMU/KVM Deployment)

We have been using VirtualBox before it was acquired by Sun Microsystems and then Oracle and have been very pleased with our experience, but are also interested in getting our hands dirty on QEMU/KVM

bin
Posts: 59
Joined: 2019-03-07 12:02
Been thanked: 7 times

Re: QEMU/KVM For Starters

#2 Post by bin »

You'll find Qemu/KVM machines are much faster than Virtualbox (at least since the more recent releases)

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#3 Post by pwzhangzz »

bin wrote: 2024-02-17 06:57 You'll find Qemu/KVM machines are much faster than Virtualbox (at least since the more recent releases)
I have noticed the same speed improvement when I ran a Windows 11 VM (but Debian VMs run very smoothly in VirtualBox). However, it is very much involved to try to optimally configure Qemu/KVM (and then I totally forgot what I did). VirtualBox has a great (I mean "GREAT"!) gui and is much easier for those who don't run virtual machines on a regular basis.

Thus I am posting the above two entry-level tutorials in the hope more people will try and post questions. Probably the best way to learn and broaden its use base.

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#4 Post by pwzhangzz »

Nowadays, most laptops come with at least 16GB of DDR. Even our new machines, an inexpensive (<$300) but very powerful mini-PC, come with 16GB RAM:

viewtopic.php?t=157844&start=2

Now is really a great time to start building experiences regarding virtual machines.

CwF
Global Moderator
Global Moderator
Posts: 2719
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 201 times

Re: QEMU/KVM For Starters

#5 Post by CwF »

pwzhangzz wrote: 2024-02-17 23:04 Now is really a great time to start building experiences regarding virtual machines.
Just like planting trees, the 2nd best time is today if not yesterday!

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#6 Post by pwzhangzz »

CwF wrote: 2024-02-18 03:58 the 2nd best time is today if not yesterday!
This maxim needs to be upgraded--at least as far as VM is concerned. :mrgreen: :mrgreen: :mrgreen:

The truth is, if "you" tried VM yesterday (or even today), because the hardware is very likely to be inadequate, "you" are very likely to be discouraged by your experience. And probably will never go back. :( :(

But things are changing. As I mentioned above, a complete AMD PC with Ryzen 7 5700U, Radeon Vega 8, 16 GB DDR, and 500 GB Nvme can now cost less than $300*. Both Qemu/KVM and VirtualBox allow VMs to run very well with this spec!

To spread the Linux desktops gospel to the general public, we really need a tool that can run Windows apps inside Linux (& WINE will never cut it). At least to provide a smooth transition. We can download Windows 10/11 images from Microsoft's official web sites**, and install the Windows images as a VM via Qemu/KVM or VirtualBox. I have heard that Windows 11 under Qemu/KVM can approach native speed. I am anxious to try it out.

* You can velcro this palm-sized "super" PC to the rear of a large 4K LED TV and create a gigantic AIO (All-in-One) machine. Many of my friends gauge the prowess of my computer based on the size of the computer screen! :D :D :D

** This is the link to download a Windows 11 iso (current release: Windows 11 2023 Update l Version 23H2):

https://www.microsoft.com/en-us/softwar ... /windows11
Last edited by pwzhangzz on 2024-02-21 23:52, edited 1 time in total.

CwF
Global Moderator
Global Moderator
Posts: 2719
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 201 times

Re: QEMU/KVM For Starters

#7 Post by CwF »

pwzhangzz wrote: 2024-02-19 01:40 * You can velcro this palm-sized "super" PC to the rear of a large 4K LED TV and create a gigantic AIO (All-in-One) machine.
I recently was talking over this idea with an RV'er. There are some brackets available that sandwich in the typical DIN mount to hold 1U style mini computers. Or I can custom make a heat piped milled aluminum...$$$...never mind. In the corner I still have a few snowmobile radiators for base stock. Anyway, favoring 3.5 sbc's with intel xeons I can do some really nice solutions. They bought a high end amd with nvidia gamer laptop instead, I'm out.

For me, dual 43 and a 21:9 below! All dumb, one with MHL (whatever) which would work with that laptop probably.

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#8 Post by pwzhangzz »

pwzhangzz wrote: 2024-02-19 01:40** This is the link to download a Windows 11 iso (current release: Windows 11 2023 Update l Version 23H2):

https://www.microsoft.com/en-us/softwar ... /windows11
Installing Windows 11 in Debian (I am running Sid, fully updated) is quite easy, probably much easier than in any other distro. The only thing you need to do is to install two packages:

Code: Select all

sudo apt install virtualbox linux-headers-$(uname -r)
For some reason I was not able to download the guest-additions iso in Windows 11 guest. In order to install the guest additions in Windows I need to apt install the encompassing package in the Debian Sid host:

Code: Select all

sudo apt install virtualbox-guest-additions-iso
Then you can install Windows 11 using the above-downloaded iso. This is a screenshot (running Windows 11 VM in Sid under VirtualBox):
win11_in_d13.jpg
Hardware is the above-mentioned mini PC. Performance is amazingly good with this amazingly inexpensive machine.

Would really appreciate it if one or more Qemu/KVM experts in this forum could share their experience. Or best, post their config file. :!:

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#9 Post by pwzhangzz »

The following is a screenshot of running Windows 11 in Sid via qemu/kvm:

win11-qemu.jpg

I basically followed the steps described in the following article:
How to Properly Install a Windows 11 Virtual Machine on KVM

https://sysguides.com/install-a-windows ... ine-on-kvm


Thanks for the excellent tutorial.

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#10 Post by pwzhangzz »

One apparent advantage that I can see--and I am speaking as a seasoned VBox user--of qemu over vbox, is that qemu allows an ummap discard option when selecting VirtIO as the emulated storage controller. In vbox, a file can be deleted but the "freed" disk space is not released, causing the vm to be indefinitely expanded (with time)*. As described in the above tutorial, "[w]hen you set the discard mode to unmap, the qcow2 disk image will automatically shrink to reflect the newly freed space]**.

When installing the Windows vm in qemu/kvm, I also needed to download the virtio-win driver (as part of an iso image) from the following site maintained by fedora/RedHat developers:

https://github.com/virtio-win/virtio-wi ... /README.md

* This problem can be greatly ameliorated by designating one or more partitions in the host (thus allowing files to be operated on the bare metal) as vbox shares which are automatically mounted during vm starts

** Debian developers have already set the qemu/kvm default storage option to "VirtIO with unmap discard mode" for (at least) Debian vm's***. Plse see the attached screenshot:
debian12_qemu.1.jpg

The default cache mode for the virtual disk is "hypervisor default". Not knowing what it means, I set the value to "none".

*** Since this thread is intended for qemu/kvm beginners (i.e., myself), I need to point out the even with the discard=unmap option, the previously occupied disk space will not be automatically freed. In order to reclaim the space, I needed to execute a fstrim (in the guest):

Code: Select all

sudo fstrim -av
The following example shows that deleting a file does not cause the vm to shrink, only after executing the fstrim command will do:

Before file removal:

ryzen@L32:/extra/qemu-images$ du debian13.qcow2
6490992 debian13.qcow2

After file removal:

ryzen@L32:/extra/qemu-images$ du debian13.qcow2
6497776 debian13.qcow2

After the fstrim command:

ryzen@L32:/extra/qemu-images$ du debian13.qcow2
4556216 debian13.qcow2
Last edited by pwzhangzz on 2024-03-14 02:06, edited 8 times in total.

CwF
Global Moderator
Global Moderator
Posts: 2719
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 201 times

Re: QEMU/KVM For Starters

#11 Post by CwF »

I'm not a M$ on libvirt expert, but you can sparsify the ntfs containing qcow2 with virt-sparsify.

This utility is available in libguestfs-tools. I don't think ntfs supports '--in-place' trim but it can be done with a two step temp 'zero' file followed by a qemu-img from qemu-utils with '-c' option to compress.

Without a manual trim and compress sparsness operation while the vm is off, the qcow2 will grow but not indefinitely. The 'sparsness' action on a ntfs qcow2 running 24/7 can be lazy...

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#12 Post by pwzhangzz »

To simplify life, we're ext4-only, except of course the EFI partition. :D

Speaking of the devil, most people are stingy with the EFI partition (Debian installer suggests at least 300MB), we, on the other hand, typically give it at least 8GB space especially for our persistent LiveUSB sticks. This way, we don't have to create a separate FAT partition when we need to share files with, say Walmart, for printing photos etc. :mrgreen: :mrgreen: :mrgreen:

CwF
Global Moderator
Global Moderator
Posts: 2719
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 201 times

Re: QEMU/KVM For Starters

#13 Post by CwF »

pwzhangzz wrote: 2024-02-26 23:08 To simplify life, we're ext4-only, except of course the EFI partition. :D
I didn't know windows 11 can run on ext4...
I thought the comments were about the file system within the qcow2.

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#14 Post by pwzhangzz »

Yes, Windows 11 was ntfs-formatted inside gcow2 (I don't think there is any other choice?).

Thanks for the libguestfs-tools suggestion. I will take a look.

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#15 Post by pwzhangzz »

pwzhangzz wrote: 2024-02-22 09:55
pwzhangzz wrote: 2024-02-19 01:40** This is the link to download a Windows 11 iso (current release: Windows 11 2023 Update l Version 23H2):

https://www.microsoft.com/en-us/softwar ... /windows11
Installing Windows 11 in Debian (I am running Sid, fully updated) is quite easy, probably much easier than in any other distro.
Of course, to install Windows, you must first create an MSA (MicroSoft Account). Even the great E£on Mu$k was unable to get away from this. Below is his well-timed complaint (90 million views in one day):
Just bought a new PC laptop and it won’t let me use it unless I create a Microsoft account, which also means giving their AI access to my computer! [emphasis added] This is messed up.
https://twitter.com/elonmusk/status/176 ... tosize%3D1

elon1.jpg
Finally, a "desperate (?)" incentive to switch the everyday OS to debian and run windows apps under a vm*. :D :D :D

* In VBox, I can create a desktop icon to execute a Windows program that has been installed in Windows VM. Suppose I can do the same with qemu/kvm.

CwF
Global Moderator
Global Moderator
Posts: 2719
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 201 times

Re: QEMU/KVM For Starters

#16 Post by CwF »

There is a way. Involving a 'cancel', a keystroke for a prompt, and a fancy oobe command.

I'm sure that doesn't end the concern if used online, they'll know.

Dai_trying
Posts: 1101
Joined: 2016-01-07 12:25
Has thanked: 7 times
Been thanked: 16 times

Re: QEMU/KVM For Starters

#17 Post by Dai_trying »

Last time I installed Windows 10 I could refuse to connect to internet and it would eventually offer to create a local account, maybe they fixed that in the latest version though...

pwzhangzz
Posts: 441
Joined: 2020-11-11 17:42
Has thanked: 10 times
Been thanked: 27 times

Re: QEMU/KVM For Starters

#18 Post by pwzhangzz »

Below is a screenshot of running both Debian 12 and Windows 11 vms in Sid:
qemu.2.resized.jpg

Installing Debian vm is very straightforward, except that, in order to allow file sharing between guests and host, I needed to install the virtiofsd package, which is included in Sid repo but, for some reason, not in Bkworm repositories including backport:

viewtopic.php?p=794400#p794400

Dai_trying
Posts: 1101
Joined: 2016-01-07 12:25
Has thanked: 7 times
Been thanked: 16 times

Re: QEMU/KVM For Starters

#19 Post by Dai_trying »

I find it easier to install nfs-common and connect to my NAS (or any nfs-server), but of course I already have that set-up so it makes sense in my situation.

Post Reply