Windows 10 and 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
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 pc-q35-6.2,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 pc-q35-6.2,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
Download image from https://msdl.gravesoft.dev (Windows 10 22H2 v1 ,Build 19045.2965, US English, IsoX64 Download)
sudo mv ~/Downloads/Win10_22H2_English_x64v1.iso /var/lib/libvirt/images/win10.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/win10.qcow2 80G
sudo chmod a+w /var/lib/libvirt/images/win10.qcow2
/usr/bin/qemu-system-x86_64 \
-cpu host \
-boot d \
-cdrom /var/lib/libvirt/images/win10.iso \
-enable-kvm \
-m 4G \
-drive file=/var/lib/libvirt/images/win10.qcow2,format=qcow2 \
-drive if=ide,index=3,media=cdrom,file=/var/lib/libvirt/images/virtio-win.iso \
-device virtio-tablet,wheel-axis=true \
-net none
Press Enter at Boot, no Key, Win10ProN, Custom: Install Windows only, load Driver E:\viostor\w10\amd64, unhide, no internet, user user, pwd user, no Spy, no Cortana.
After installation install all Win Guest Tools and Drivers: E:\virtio-win-guest-tools.exe
/usr/bin/qemu-system-x86_64 \
-enable-kvm \
-m 8G \
-smp 6,sockets=1,cores=3,threads=2 \
-cpu host \
-drive file=/var/lib/libvirt/images/win10.qcow2 \
-device qemu-xhci \
-device virtio-tablet,wheel-axis=true \
-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 \
-device virtio-net,netdev=vmnic \
-netdev user,id=vmnic,smb=/home/user/Schreibtisch/Arbeit \
Activate Windows -> open Powershell and insert "irm https://get.activated.win | iex" -> Enter -> 1 -> Enter
Make all updates, any update like KB5034441 with error 0x80070643, you can make them unseen:
http://download.microsoft.com/download/F/2/2/F22D5FDB-59CD-4275-8C95-1BE17BF70B21/wushowhide.diagcab
Ethernet-USB drivers "AX88179_178A_Win7_v1.x.11.0_Drivers_Setup_v3.0.3.0.zip" and Realtek "USB 3.0 LAN Driver_10.005.zip"
Disable taskbar thumbnail preview using Windows Registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ExtendedUIHoverTime DWORD 30000
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/ShadowWhisperer/Remove-MS-Edge/blob/main/Remove-EdgeOnly.exe
https://github.com/Open-Shell/Open-Shell-Menu/releases/latest
https://github.com/hellzerg/optimizer/releases/latest
https://github.com/ionuttbara/one-drive-uninstaller
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 10 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,migratable=on,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
-enable-kvm \
-m 8G \
-smp 6,sockets=1,cores=3,threads=2 \
-machine pc-q35-6.2,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
/usr/bin/qemu-system-x86_64 \
-enable-kvm \
-m 8G \
-smp 6,sockets=1,cores=3,threads=2 \
-cpu host \
-drive file=/var/lib/libvirt/images/win10.qcow2 \
-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/win10.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:
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 driver=spice,id=audio -device intel-hda -device hda-duplex,audiodev=audio
-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 in second line:
-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 -serial mon:stdio
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
-device virtio-net,netdev=vmnic -netdev user,id=vmnic,smb=/home/user/Schreibtisch/Arbeit
In windows:
explorer: \\10.0.2.4\qemu ---> Map network device...
On host:
sudo pluma /etc/samba/smb.conf
# Start /etc/samba/smb.conf
[global]
bind interfaces only = Yes
interfaces = lo br0
idmap config * : backend = tdb
[share]
force user = user
path = /home/user/Schreibtisch/Arbeit
read only = No
# End /etc/samba/smb.conf
testparm -s
sudo service smbd restart
sudo ufw allow samba
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.