Shell script for Virtual Windows XP
#!/bin/bash

: apt install p7zip-full libguestfs-tools locate

cd -P "$(mktemp -d)"
cp -avu "$(locate --limit=1 WindowsXPMode_en-us.exe)" .

# Extract the raw image
7za x WindowsXPMode_en-us.exe
7za x sources/xpm
qemu-img convert VirtualXPVHD windows.raw

# Install drivers
virt-copy-out -a windows.raw  "/WINDOWS/Driver Cache/i386/driver.cab" .
cabextract -F pciide.sys driver.cab
virt-copy-in -a windows.raw pciide.sys /WINDOWS/system32/drivers/

# Modify registry for qemu
: sed -e 's,CurrentControlSet,ControlSet001,' <<-'SED' | \
        virt-win-reg --merge windows.raw
        Windows Registry Editor Version 5.00

        [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
        "NoWindowsUpdate"=dword:00000000
SED

sed -e 's,CurrentControlSet,ControlSet001,' <<-'SED' | \
        virt-win-reg --merge windows.raw
        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
        "Password"="net user Administrator Administrator"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile]
        "EnableFirewall"=dword:00000000

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TlntSvr]
        "Type"=dword:00000010
        "Start"=dword:00000002
        "DisplayName"="Telnet"
        "ObjectName"="LocalSystem"
SED
sed -e 's,CurrentControlSet,ControlSet001,' <<-'SED' | \
        virt-win-reg --merge windows.raw
        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\primary_ide_channel]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="atapi"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\secondary_ide_channel]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="atapi"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*pnp0600]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="atapi"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\*azt0502]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="atapi"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\gendisk]
        "ClassGUID"="{4D36E967-E325-11CE-BFC1-08002BE10318}"
        "Service"="disk"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#cc_0101]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_0e11&dev_ae33]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1039&dev_0601]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1039&dev_5513]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1042&dev_1000]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_105a&dev_4d33]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1095&dev_0640]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1095&dev_0646]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1095&dev_0646&REV_05]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1095&dev_0646&REV_07]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1095&dev_0648]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1095&dev_0649]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1097&dev_0038]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_10ad&dev_0001]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_10ad&dev_0150]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_10b9&dev_5215]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_10b9&dev_5219]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_10b9&dev_5229]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="pciide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_1106&dev_0571]
        "Service"="pciide"
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_1222]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_1230]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_2411]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_2421]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_7010]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_7111]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\pci#ven_8086&dev_7199]
        "ClassGUID"="{4D36E96A-E325-11CE-BFC1-08002BE10318}"
        "Service"="intelide"

        ;Add driver for Atapi (requires Atapi.sys in Drivers directory)

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\atapi]
        "ErrorControl"=dword:00000001
        "Group"="SCSI miniport"
        "Start"=dword:00000000
        "Tag"=dword:00000019
        "Type"=dword:00000001
        "DisplayName"="Standard IDE/ESDI Hard Disk Controller"
        "ImagePath"=hex(2):53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,44,00,\
          52,00,49,00,56,00,45,00,52,00,53,00,5c,00,61,00,74,00,61,00,70,00,69,00,2e,\
          00,73,00,79,00,73,00,00,00

        ;Add driver for intelide (requires intelide.sys in drivers directory)

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IntelIde]
        "ErrorControl"=dword:00000001
        "Group"="System Bus Extender"
        "Start"=dword:00000000
        "Tag"=dword:00000004
        "Type"=dword:00000001
        "ImagePath"=hex(2):53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,44,00,\
          52,00,49,00,56,00,45,00,52,00,53,00,5c,00,69,00,6e,00,74,00,65,00,6c,00,69,\
          00,64,00,65,00,2e,00,73,00,79,00,73,00,00,00


        ;Add driver for Pciide (requires Pciide.sys and Pciidex.sys in Drivers directory)

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PCIIde]
        "ErrorControl"=dword:00000001
        "Group"="System Bus Extender"
        "Start"=dword:00000000
        "Tag"=dword:00000003
        "Type"=dword:00000001
        "ImagePath"=hex(2):53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,44,00,\
          52,00,49,00,56,00,45,00,52,00,53,00,5c,00,70,00,63,00,69,00,69,00,64,00,65,\
          00,2e,00,73,00,79,00,73,00,00,00
SED

# https://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-casesensitive
<<-'SED' \
sed -e 's,CurrentControlSet,ControlSet001,' | \
virt-win-reg --merge windows.raw
        REGEDIT4

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\kernel]
        "obcaseinsensitive"=dword:00000000

SED

guestfish -a windows.raw -i <<-'EOF'
        rm /WINDOWS/system32/drivers/processr.sys
        rm /WINDOWS/system32/drivers/intelppm.sys
        rm /WINDOWS/inf/cpu.inf
EOF

qemu-img convert -f raw -O qcow2 windows.raw VirtualXPVHD.~1~
find -! -name VirtualXPVHD.~1~ -delete
qemu-img create VirtualXPVHD -b VirtualXPVHD.~1~ -f qcow2
mv -vn VirtualXPVHD VirtualXPVHD.~1~ ..
cd -
rmdir $OLDPWD

# NET command net view \\SAMBA net user Administrator Administrator net use X: \\SAMBA\pub net