Windows 11 on Linux using KVM and Qemu
Installing all tools:
sudo apt-get install qemu-kvm bridge-utils ovmf virt-manager samba qemu-utils qemu-system-x86 virt-viewer spice-client-gtk libvirt-daemon-system nfs-kernel-server virtiofsd swtpm-tools swtpm
check if your system supports KVM:
kvm-ok
Download image from https://msdl.gravesoft.dev (Windows 11 23H2 v2 (Build 22631.2861), US English, IsoX64 Download)
sudo mv ~/Downloads/Win11_23H2_English_x64v2.iso /var/lib/libvirt/images/win11.iso
wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
sudo mv ./virtio-win.iso /var/lib/libvirt/images/
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/win11.qcow2 80G
sudo chmod a+w /var/lib/libvirt/images/win11.qcow2
sudo killall swtpm
sudo rm -rf /tmp/emulated_tpm
mkdir -p /tmp/emulated_tpm
swtpm socket --tpmstate dir=/tmp/emulated_tpm --ctrl type=unixio,path=/tmp/emulated_tpm/swtpm-sock --daemon
/usr/bin/qemu-system-x86_64 \
-cpu host,migratable=on,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-enable-kvm \
-m 8G \
-smp 6 \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.secboot.fd \
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
-chardev socket,id=chrtpm,path=/tmp/emulated_tpm/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis,tpmdev=tpm0 \
-machine q35,accel=kvm,smm=on \
-boot d -cdrom /var/lib/libvirt/images/win11.iso \
-drive file=/var/lib/libvirt/images/win11.qcow2,format=qcow2,if=virtio \
-drive if=ide,index=3,media=cdrom,file=/var/lib/libvirt/images/virtio-win.iso \
-device qemu-xhci -device usb-tablet \
-netdev user,id=net0 -device e1000,netdev=net0 \
-global driver=cfi.pflash01,property=secure,value=on
Boot: Press Enter at boot.
Setup: Select "I do not have a key", Choose Win11ProN, Select Custom: Install Windows only.
Load Driver: E:\viostor\w11\amd64.
Disable Internet Requirement: Shift + F10 -> oobe\bypassnro -> Enter, Reboot -> Shift + F10 -> ipconfig /release -> Enter.
Regional Settings: United States -> Yes. US -> Yes. Add German (Germany) layout.
Internet Setup: Select "I do not have internet". Continue with limited setup.
User Setup: Username: user -> Next.Password: user -> Next. Skip unnecessary options (Spy, Cortana).
Finalize: Shutdown, then restart. Install drivers: E:\virtio-win-guest-tools.exe.
Activate Windows -> open Powershell and insert "irm https://get.activated.win | iex" -> Enter -> 1 -> Enter
Disable taskbar thumbnail preview using Windows Registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ExtendedUIHoverTime DWORD 30000
Now start your Windows 11 setup.
mkdir -p /tmp/emulated_tpm && \
swtpm socket \
--tpmstate dir=/tmp/emulated_tpm \
--ctrl type=unixio,path=/tmp/emulated_tpm/swtpm-sock \
--daemon && \
/usr/bin/qemu-system-x86_64 \
-cpu host,migratable=on,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-enable-kvm \
-m 8G \
-smp 6 \
-machine q35,accel=kvm,smm=on \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.secboot.fd \
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
-chardev socket,id=chrtpm,path=/tmp/emulated_tpm/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis,tpmdev=tpm0 \
-drive file=/var/lib/libvirt/images/win11.qcow2,format=qcow2,if=virtio \
-device qemu-xhci \
-device usb-tablet \
-global driver=cfi.pflash01,property=secure,value=on \
-device virtio-net,netdev=vmnic \
-netdev user,id=vmnic,smb=/home/user/Schreibtisch/Arbeit \
-vga qxl \
-device virtio-serial-pci \
-spice port=3001,disable-ticketing=on \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
-chardev spicevmc,id=spicechannel0,name=vdagent \
-display spice-app
https://download.sysinternals.com/files/AutoLogon.zip
https://download.sysinternals.com/files/SDelete.zip
https://www.7-zip.org/download.html
https://www.mozilla.org/en-US/firefox/all/#product-desktop-release
https://github.com/valinet/ExplorerPatcher
https://github.com/hellzerg/optimizer/releases/latest
https://github.com/ionuttbara/one-drive-uninstaller
https://github.com/Open-Shell/Open-Shell-Menu/releases/latest
https://github.com/ShadowWhisperer/Remove-MS-Edge/blob/main/Remove-EdgeOnly.exe
https://github.com/massgravel/Microsoft-Activation-Scripts
https://github.com/es3n1n/no-defender
Uninstall vmware utils using VMware
Disable Hibernate in Windows 10:
https://www.tenforums.com/tutorials/2859-enable-disable-hibernate-windows-10-a.html
Disable Sleep Mode In Windows 10:
https://www.intowindows.com/how-to-enable-or-disable-sleep-mode-in-windows-10
Turn Off Fast Startup in Windows 10:
https://www.tenforums.com/tutorials/4189-turn-off-fast-startup-windows-10-a.html
download drivers
wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
sudo mv ./virtio-win.iso /var/lib/libvirt/images/
Copy virtual disk from VMWARE and install it in Linux
sudo rm /var/lib/libvirt/images/Siemens_TIA19.qcow2
sudo qemu-img convert -f vmdk -O qcow2 /home/user/Schreibtisch/Siemens_TIA19.vmdk /var/lib/libvirt/images/Siemens_TIA19.qcow2
sudo chmod a+w /var/lib/libvirt/images/Siemens_TIA19.qcow2
In Windows after start qemu run D:\virtio-win-guest-tools.exe
mkdir -p /tmp/emulated_tpm && \
swtpm socket \
--tpmstate dir=/tmp/emulated_tpm \
--ctrl type=unixio,path=/tmp/emulated_tpm/swtpm-sock \
--daemon && \
/usr/bin/qemu-system-x86_64 \
-cpu host,+hv-time,+hv-relaxed,+hv-vapic,+hv-spinlocks=0x1fff \
-enable-kvm \
-m 8G \
-smp 6,sockets=1,cores=3,threads=2 \
-machine q35,accel=kvm,smm=on \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.secboot.fd \
-drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_VARS_4M.fd \
-chardev socket,id=chrtpm,path=/tmp/emulated_tpm/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis,tpmdev=tpm0 \
-global driver=cfi.pflash01,property=secure,value=on \
-drive file=/var/lib/libvirt/images/win11.qcow2,format=qcow2,if=virtio \
-device virtio-tablet,wheel-axis=true \
Atatch one CD-ROM with the drivers
-cdrom /var/lib/libvirt/images/virtio-win.iso \
Atatch two CD-ROM with the drivers
-drive if=ide,index=1,media=cdrom,file=/var/lib/libvirt/images/win11.iso \
-drive if=ide,index=2,media=cdrom,file=/var/lib/libvirt/images/virtio-win.iso \
kernel: usb 3-4.2: new high-speed USB device number 12 using xhci_hcd
kernel: usb 3-4.2: New USB device found, idVendor=0bda, idProduct=8153, bcdDevice=30.00
kernel: usb 3-4.2: New USB device strings: Mfr=1, Product=2, SerialNumber=6
kernel: usb 3-4.2: Product: USB 10/100/1000 LAN
kernel: usb 3-4.2: Manufacturer: Realtek
kernel: usb 3-4.2: SerialNumber: 000001
kernel: r8152-cfgselector 3-4.2: reset high-speed USB device number 12 using xhci_hcd
kernel: r8152 3-4.2:1.0: load rtl8153a-4 v2 02/07/20 successfully
Bus 003 Device 012: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
idVendor 0x0bda Realtek Semiconductor Corp.
idProduct 0x8153 RTL8153 Gigabit Ethernet Adapter
check permision:
lsusb
Bus 003 Device 012: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
ls -l /dev/bus/usb/003/012
crw-rw-r-- 1 root root 189, 267 Mai 23 16:18 /dev/bus/usb/003/012
change user:
sudo echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0bda", ATTR{idProduct}=="8153", OWNER="root", GROUP="kvm", MODE="0666"' > /etc/udev/rules.d/99-usb-stick.rules
udevadm control --reload-rules && udevadm trigger
check permision again:
ls -l /dev/bus/usb/003/012
crw-rw-rw- 1 root kvm 189, 267 Mai 23 17:43 /dev/bus/usb/003/012
Now start quem with this parameter to use usb ethernet device
-device usb-ehci,id=ehci -usb -device usb-host,bus=ehci.0,vendorid=0x0bda,productid=0x8153 \
-audiodev pipewire,id=audio0 -device intel-hda -device hda-duplex,audiodev=audio0 \
-device qemu-xhci,id=xhci \
-device virtio-tablet,wheel-axis=true \
Copy & Paste + Drag & Drop + Automatic Resolution Adjustment
Start quem with this parameter to use direct spice app:
-vga qxl -device virtio-serial-pci -spice addr=127.0.0.1,port=3001,disable-ticketing=on \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
-chardev spicevmc,id=spicechannel0,name=vdagent \
-display spice-app \
Start quem with this parameter to connect later with spice:
-vga qxl -device virtio-serial-pci -spice addr=127.0.0.1,port=3001,disable-ticketing=on \
-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent \
Use one to connect to VM
remote-viewer spice://localhost:3001
spicy -h localhost -p 3001
Configure two USB redirection channel for spice.
-device usb-redir,chardev=usbredir0 -chardev spicevmc,id=usbredir0,name=usbredir \
-device usb-redir,chardev=usbredir1 -chardev spicevmc,id=usbredir1,name=usbredir \
It will be launched from the same terminal this script runs from.
-monitor stdio \
Use the QEMU monitor with telnet:
-monitor telnet::45454,server,nowait \
and on a host terminal:
telnet localhost 45454
Command on host for working Ping until next boot:
sudo sysctl -w net.ipv4.ping_group_range='0 2147483647'
Command on host for working Ping forever (on linux host):
echo "net.ipv4.ping_group_range = 0 2147483647" | sudo tee -a /etc/sysctl.conf
-device virtio-net,netdev=vmnic -netdev user,id=vmnic \
The -snapshot option is particularly useful in a kiosk mode scenario where you want the VM to return to a clean state after each session, ensuring that no user changes are permanent.
Commit changes: Use in QEMU Monitor "commit virtio0" (if -snapshot is used)
-snapshot \
On Linux host (Ubuntu/Debian):
sudo apt install uidmap virtiofsd
/usr/libexec/virtiofsd --socket-path=/tmp/virtiofs_socket -o source=/home/boss/Desktop/Arbeit
In windows guest:
Download and install WinFSP with at least "Core" feature enabled.
Install virtiofs driver and service from VirtIO-Win package.
On Linux host (Ubuntu/Debian):
sudo apt install nfs-kernel-server
sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server
Edit /etc/exports:
After editing /etc/exports, apply the changes by running:
sudo exportfs -ra
In windows guest:
Open PowerShell as Administrator and run the following command:
Enable-WindowsOptionalFeature -Online -FeatureName "ServicesForNFS-ClientOnly" -All
Restart windows guest after the installation is complete.
Open a command prompt, and type:
mount -o anon \\192.168.0.1\srv\nfs\files Z:
QEMU launches Samba on the host using an automatically generated smb.conf file, located in /tmp/qemu-smb.random_string, and makes it available to the guest at a different IP address (default is 10.0.2.4). This setup only functions with user-mode networking and is handy if you prefer not to start the regular Samba service on the host, which can also provide shared access to the guest if you've configured shares on it. Samba must be installed on the host.
-device virtio-net,netdev=vmnic -netdev user,id=vmnic,smb=/home/you_user/Schreibtisch/Arbeit \
In windows guest:
explorer: \\10.0.2.4\qemu ---> Map network device...
Defrag with the open source UltraDefrag software with "full optimisation"
Downlod tool: https://learn.microsoft.com/en-us/sysinternals/downloads/sdelete
Clean with https://www.wisecleaner.com/wise-disk-cleaner.html
On client:
sdelete -c c:
sdelete -z c:
On host:
time nice ionice -c 3 qemu-img convert -c -p -f qcow2 /var/lib/libvirt/images/win10.qcow2 -O qcow2 /var/lib/libvirt/images/win10.comp.qcow2
cp /var/lib/libvirt/images/win10.comp.qcow2 /var/lib/libvirt/images/win10.qcow2
time nice ionice -c 3 qemu-img convert -c -p -f qcow2 /var/lib/libvirt/images/win11.qcow2 -O qcow2 /var/lib/libvirt/images/win11.comp.qcow2
cp /var/lib/libvirt/images/win11.comp.qcow2 /var/lib/libvirt/images/win11.qcow2
Note: do not compress the end file.