Credits : https://blog.rodney.io/2016/06/installing-windows-though-qemu-kvm-on-servers-without-kvm-or-ipmi
Windows Server 2019 (ENG): http://mirror.hetzner.de/bootimages/windows/SW_DVD9_Win_Server_STD_CORE_2019_1809.11_64Bit_English_DC_STD_MLF_X22-51041.ISO
Windows Server 2016 (ENG): http://mirror.hetzner.de/bootimages/windows/SW_DVD9_Win_Server_STD_CORE_2016_64Bit_English_-4_DC_STD_MLF_X21-70526.ISO
Windows Server 2012 R2 (ENG): http://mirror.hetzner.de/bootimages/windows/SW_DVD9_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_-4_MLF_X19-82891.ISO
This tutorial is loosely based on this one. It uses the same portable QEMU-KVM binaries but has more information as well as additional steps that I needed to take when I used this method of installing an OS
This Tutorial aims to provide you with a step-by-step guide to install Windows from an ISO on a server that does not feature KVM (iDRAC, iLO, etc.) but has a rescue system available.
mount -t tmpfs -o size=6000m tmpfs /mnt && \
wget -O /mnt/windows.iso http://mirror.hetzner.de/bootimages/windows/SW_DVD9_Win_Server_STD_CORE_2016_64Bit_English_-4_DC_STD_MLF_X21-70526.ISO && \
wget -qO- /tmp https://cdn.rodney.io/content/blog/files/vkvm.tar.gz | tar xvz -C /tmp && \
/tmp/qemu-system-x86_64 -net nic -net user,hostfwd=tcp::3389-:3389 -m 2048M -localtime -enable-kvm -cpu host,+nx -M pc -smp 2 -vga std -usbdevice tablet -k fr -cdrom /mnt/windows.iso -hda /dev/sda -boot once=d -vnc :1
- A Windows ISO
- A Server with a Linux-based "Rescue System" available
- Enough RAM to store the ISO OR a secondary hard drive
- A SSH and VNC Client
- Basic knowledge about advanced Windows settings
First you want to boot into the rescue system, in case of Hetzner and Webtropia its as easy as pressing a button in the web interface. You'll get a root password to login into the rescue system.
Now create a RAM disk for the Windows ISO:
mount -t tmpfs -o size=6000m tmpfs /mnt
My ISO is about 4.8 GB big and fits compfortably into the 32 GB RAM my server has, if you don't have enough RAM but a second hard drive available you can use that instead.
Now download the Windows ISO, in my case it sits on a FTP(s) server that require sauthentication so I download it like this:
curl -u 'user:pw' -k --ftp-ssl 'ftp://host//ISOs/en_windows_server_2012_r2_with_update_3_x64_dvd_6052708-MAY.2016.iso' -o /mnt/windows.iso
If your host offers a repository with ISOs (such as Hetzner) you can also use wget to download the ISO:
wget -O /mnt/windows.iso http://mirror.hetzner.de/bootimages/windows/SW_DVD9_Win_Server_STD_CORE_2016_64Bit_English_-4_DC_STD_MLF_X21-70526.ISO
After that finishes it's time to download the portable QEMU-KVM version:
wget -qO- /tmp https://cdn.rodney.io/content/blog/files/vkvm.tar.gz | tar xvz -C /tmp
If your server has a main hard drive > 2TB and boots through UEFI you can use the UEFI BIOS for QEMU:
wget -qO- /tmp https://cdn.rodney.io/content/blog/files/uefi.tar.gz | tar xvz -C /tmp
However none of the servers I tested so far used UEFI to boot despite having harddrives over 2 TB.
Now you can start QEMU-KVM and start the installation:
/tmp/qemu-system-x86_64 -net nic -net user,hostfwd=tcp::3389-:3389 -m 2048M -localtime -enable-kvm -cpu host,+nx -M pc -smp 2 -vga std -usbdevice tablet -k fr -cdrom /mnt/windows.iso -hda /dev/sda -boot once=d -vnc :1
Or for UEFI systems:
/tmp/qemu-system-x86_64 -bios /tmp/uefi.bin -net nic -net user,hostfwd=tcp::3389-:3389 -m 2048M -localtime -enable-kvm -cpu host,+nx -M pc -smp 2 -vga std -usbdevice tablet -k fr -cdrom /mnt/windows.iso -hda /dev/sda -boot once=d -vnc :1
Once you've started the VM you can connect to your-ip:1 using VNC and go through the graphical installer.
After installing Windows it will boot and allow you to create a User etc. Windows is now installed but not quite ready yet.
- Enable RDP
- Disable Firewall
You can now test the RDP connection by connecting to your-ip, the QEMU switches we used forward that port. The second step is required because Windows will recognize the real network connection of the server as a new network on startup and block RDP by default. By disabling it RDP will stay available, you can enable the firewall again after logging in and allowing RDP through the firewall on the new network.
If your server uses a NIC that is supported by Windows without any additional drivers (i.e. Intel NICs) and your provider uses DHCP you're now done, shut down the VM and disable the rescue system, then reboot. This was the case with my Hetzner box.
My Webtropia box uses a Realtek NIC and static IP configuration and required further configuration:
Find out what NIC your server uses using the rescue system, you can use one of the following commands to find out:
$ lspci | egrep -i --color 'network|ethernet'
$ lshw -class network
In my case the result was RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller. I just searched for the driver and downloaded it from the Realtek website and installed it through the grapical installer. I got an error that the NIC wasn't installed but you can just ignore that. Windows will load and install the driver after booting.
In my case I got the following information from my provider:
IP Address: 37.XXX.XXX.183
Gateway: 37.XXX.XXX.129
Netmask: 255.255.255.192 (/26)
I cannot set those within the VM since the network adapter is not connected yet. So in order to set this configuration after the server reboots into windows I have to create a startup script that sets those values on the new NIC. This can be done with a simple batch script:
netsh interface ipv4 set address name="REAL INTERFACE NAME HERE - E.G : Ethernet" static 37.XXX.XXX.183 255.255.255.192 37.XXX.XXX.129
You need to use your real interface's name instead of "REAL INTERFACE NAME HERE - E.G : Ethernet". You can list them with netsh interface show interface.
Order of parameters is IP, Netmask, Gateway.
This is anticipating that the new network connection will be called "Ethernet 2" which is the default on an english windows installation, you might have to adjust this based on your locale.
This single line can now be saved as C:\startup.bat and added as a startup script in gpedit.msc under "Computer Configuration"->"Windows Settings"->"Scripts (Startup/Shutdown)".
You can now reboot.
After rebooting and (hopefully) getting into your new machine you will be asked wether or not the new network is private or public, I choose public. After that you can configure your firewall to allow RDP and re-enable it again.
Finally remove the startup script (if any) and add DNS servers to your static configuration (if any).
You have now finished the installation, congratulations!
If you server doesn't boot you can use QEMU-KVM to boot the installation on your disk, this allows you to troubleshoot and avoid reinstalling windows again if you made a mistake.
mount -t tmpfs -o size=6000m tmpfs /mnt && \
wget -qO- /tmp https://cdn.rodney.io/content/blog/files/vkvm.tar.gz | tar xvz -C /tmp && \
/tmp/qemu-system-x86_64 -net nic -net user,hostfwd=tcp::3389-:3389 -m 2048M -localtime -enable-kvm -cpu host,+nx -M pc -smp 2 -vga std -usbdevice tablet -k fr -hda /dev/sda -boot c -vnc :1
Download the portable QEMU again and start your VM from disk like this:
/tmp/qemu-system-x86_64 -net nic -net user,hostfwd=tcp::3389-:3389 -m 2048M -localtime -enable-kvm -cpu host,+nx -M pc -smp 2 -vga std -usbdevice tablet -k fr -hda /dev/sda -boot c -vnc :1
Or with UEFI:
/tmp/qemu-system-x86_64 -bios /tmp/uefi.bin -net nic -net user,hostfwd=tcp::3389-:3389 -m 2048M -localtime -enable-kvm -cpu host,+nx -M pc -smp 2 -vga std -usbdevice tablet -k fr -cdrom /mnt/win8-64.iso -hda /dev/sda -boot c -vnc :1