[Script] Turn your Linux VPS/Server into Windows Server automatically using Shell script

sohom

Supreme Member
Joined
May 26, 2013
Messages
1,361
Reaction score
646
Open Source Github Project/Repository URL :
https://github.com/mediabots/Linux-to-Windows-with-QEMU

A Shell Script for Auto installation of Windows Server into a Linux Server.

A Shell Script to Auto install Windows Server on your Linux System. [Right now, it supports 2012 R2 < evaluation/180 days trial > copy]

Script would use QEMU-KVM portable software for Virtualization purpose. Since QEMU is a portable s/w, so it can reside in temporary RAM.

Actually script is semi-automatic. All Linux commands part(such as downloading Windows ISO image, gathering system info, choosing disk/partition, managing RAM , attaching required windows s/w in CDROM) would be handled by script automatically.

And rest of the windows part(clicking, selecting, setting Administrator password ) need to be done manually by any Free VNC windows software.

After Windows Installation completed, you would find a Power Shell script under CD-ROM, called "EnableRDP.ps1". By running it you would be able to enable Remote Desktop on your Windows server, so after that you would be able to connect your Windows server through Windows "Remote Desktop Application" App :)

I also attached Firefox App on CD-ROM, install that, so you don't need to face "Internet Explorer" horrible setting experience!


Requirements


A SSH client such as Putty : https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

A VNC software such as RealVNC : https://www.realvnc.com/en/connect/download/vnc/

A VPS or Dedicated server with Ubuntu OS Installed.

At least 30GB Free disk space in your system.

Virtualization of your VPS or Server must be enabled. Run below coammnd :

Code:
echo $(egrep '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l)

if output is greater than 0, then Virtualization is enabled :D

Either should have access of root user OR run with su (super user)

How to Run the Script

Just run below five commands one after another :
Code:
su

mkdir /media/script && mount -t tmpfs -o size=1m tmpfs /media/script

wget -P /media/script https://raw.githubusercontent.com/mediabots/Linux-to-Windows-with-QEMU/master/mediabots_Ubuntu-to-Windows.sh

chmod +x /media/script/*

/media/script/mediabots_Ubuntu-to-Windows.sh

Screen-shots step by step

1) Download Putty(SSH client) from here : https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
2) Run Putty.exe file and connect to your Linux Server IP address (with port 22)
lPVhvhm

Login with your Linux Server Credential.
3) Run the Script. [ Read -> "How to Run the Script" section of this topic ]
KGejlQu

4) If your Server/VPS RAM size > 5 GB
Script would ask , whether you would like to delete existing Linux OS or not
-> I opted for [No]
LFwowrx

Script has done its work
5) now Download & install VNC [ https://www.realvnc.com/en/connect/download/viewer/ ]
and open your VPS/Server IP with port 0
Tc6NAGt

in my case my VPS IP was 51.15.229.233
4) Now you would see, Windows installation is on the process
k2tLHAR

5) Click/Choose options which I highlighted
5m02t3j

mpixbrf

Choose "Windows Server 2012 R2 SE (with GUI)"
Qk8W93v

yllbhw7

PRydybd

eksRoWZ

KOdQxNn

Set password for user : Administrator
Create a 16 to 20 Character long strong password
VsEPiSI

dLJze9n

login to Windows Server with your password
v9zWnwj

tR6CXfk

Windows Server installed successfully :D
W7olVM3

Enable Remote Desktop through ebableRDP.ps1 power shell script
Also install Firefox for browsing
TXKbKTX

In case .ps1 script prompt like this
BT2bQOz

press Y and Enter
---
Job Done :)
Enjoy
-------------------------------------------------------

Demo Video


img404.jpg


or

https://bit.ly/Linux-to-Windows

Disclaimer

For few cases, due to RAID configuration of the hard disk, if you had chosen to delete existing Linux OS & install Windows OS on entire hard disk. On your VNC , you might see, Windows installation failing.

If you are facing such issue; Exit from the script & Re-run it & in this time just opt for installing Windows OS without deleting Linux OS. And it would work :D

In case, portable QEMU-KVM app stopped/closed, your Widows-Server would not be accessible. To access it again, you require to run the QEMU-KVM app again with proper parameters.

Run below command :

Code:
cat /details.txt

Copy the Output of the above result and Paste it & press Enter button. It would run the QEMU-KVM again. So your Windows Server would be accessible again :D

If you required a reboot of your Windows Server, just reboot it from Windows Server reboot option. Don't reboot your server from Server Hosting Control-panel. Otherwise QEMU App would get stopped.

If you had opted for removing your old Linux OS, you would get Windows server with full HDD capacity. But RAM would not be full, because QEMU resides on RAM.

Updates

Right now, Script supporting Ubuntu Distro only.

But very soon I would add the support for all popular Linux Distros too.

So stay tuned.

--
Hope you guys like it.
If you are a developer, you are welcome to contribute in the project

Feel free to ask any question

Don't forget to share your thoughts

Thank you
 
Last edited by a moderator:
How Script works?

CASE - 1

Your Server/VPS Free RAM size > 5 GB

If your system comes with more than 5GB free RAM, script would ask, whether do you want to delete your existing Linux OS(Ubuntu in this case).

Go with that option only if "Rescue Boot" option is available in your Server Hosting Control-panel.

Case - 1.a

Suppose you proceed with that option, in that case, script would download Windows-ISO image & other stuffs in your system RAM.

Case - 1.b

Suppose you dont go with that option.

Script would first check, how many Disk are attached with your VPS/Server.

Case - 1.b.i

If there are multi Disk.

Winodws-OS would be installed on your second Disk.

Case - 1.b.ii

If only one Disk attached, then it would check how many partitions(size > 25 GB) are present there.

If there are multi partitons(size > 25 GB). Windows-OS would be installed on second partition.

Else

If only one partion exist, and that partition has more than 30 GB free space. In that case ,it would create a "disk.img" file of 25 GB size for installing Windows-OS on that file.

CASE - 2

Your Server/VPS Free RAM size < 5 GB

start from <Case - 1.b>



---

Best Regards
 
Does this works on servers previously encrypted with full-disk encryption using Luks2?
 
Are you sure this works on a Linux VPS? I highly doubt you can use virtualization twice.
 
Does this works on servers previously encrypted with full-disk encryption using Luks2?

I never tried that.

As I said in my 1st post(under requirement section)
check whether your server Virtualization is on or off
command:
Code:
echo $(egrep '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l)
if output is greater than 0, then Virtualization is enabled :D

if it is enabled, run the script & at first try to install Windows-OS with the option without deleting your existing Linux-OS. In this case you must have at least 30 GB free diskspace

if it did not work, then you could try with the script option : install windows-OS by deleting existing Linux-OS (WARNING! in this case your old data would be lost)

@sohom will that turn my digitalocean droplet to windows VPS it's with ubuntu server 18

if your digitalocean VPS Virtualization is on , then it should work
command:
Code:
echo $(egrep '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l)
if output is greater than 0, then Virtualization is enabled :D

Run the script
Follow my screen-shots guide at 1st post

Regards
 
That's a good way to buy cheap Linux vps and transform them in windows ones free. Thanks! But make sure the vps supplier doesn't know what you are doing or you'll be banned.
 
Does this works on servers previously encrypted with full-disk encryption using Luks2?
I think this guide was meant for VPS providers and users alike. I'm yet to see a VPS provider using luks encryption even though I use it on my boxes. I honestly think it won't work, seeing as you'd need to enter your encryption key on every restart.
 
Does this works on servers previously encrypted with full-disk encryption using Luks2?
as far as i know luks2 is currently not supported by qemu-kvm l
 
@sohom will that turn my digitalocean droplet to windows VPS it's with ubuntu server 18

Nested virtualization allows you to run a virtual machine (VM) inside another VM while still using hardware acceleration from the host.

Checking if nested virtualization is supported
For Intel processors, check the /sys/module/kvm_intel/parameters/nested file. For AMD processors, check the /sys/module/kvm_amd/parameters/nested file. If you see 1 or Y, nested virtualization is supported; if you see 0 or N, nested virtualization is not supported.

For example:

$ cat /sys/module/kvm_intel/parameters/nested
Y
Enabling nested virtualization
To enable nested virtualization for Intel processors:

  1. Shut down all running VMs and unload the kvm_probe module:

    # modprobe -r kvm_intel
  2. Activate the nesting feature:

    # modprobe kvm_intel nested=1
  3. Nested virtualization is enabled until the host is rebooted. To enable it permanently, add the following line to the /etc/modprobe.d/kvm.conf file:

    options kvm_intel nested=1
To enable nested virtualization for AMD processors:

  1. Shut down all running VMs and unload the kvm_amd module:

    # modprobe -r kvm_amd
  2. Activate the nesting feature:

    # modprobe kvm_amd nested=1
  3. Nested virtualization is enabled until the host is rebooted. To enable it permanently, add the following line to the /etc/modprobe.d/kvm.conf file:

    options kvm_amd nested=1
after that you have to configure virt manager which i am not posting here
 
Are you sure this works on a Linux VPS? I highly doubt you can use virtualization twice.

Obviously
I already tested it on www.scaleway.com Cloud VPS.
Starter Plan : 1-S, 1-M, 1-L
As well as on
BareMetal : C2S

As like, I said, if your VPS Virtualization is enabled (even if it is a nested virtualization)
Then this Shell should do its job.

I think this guide was meant for VPS providers and users alike. I'm yet to see a VPS provider using luks encryption even though I use it on my boxes. I honestly think it won't work, seeing as you'd need to enter your encryption key on every restart.

Just for the information
Script has been tested on www.Oneprovider.com & www.Online.net servers. As well tested on www.Scaleway.com Cloud VPS & Baremetal servers.

So this script is not only for VPS users.

And for that luks encrypted disk thing. Might be you are correct.
if you have some spare time,you can still test it(specially if your box came with a single disk device & if there is only one partition with size > 25 GB).
In that case, script would create a 25GB disk image called 'disk.img' under your primary partition & install Windows Server there.
That would make no harm! Anytime you don't need WINDOWS, all you have to delete that 'disk.img' file only :)

Regards
 
Last edited:
Nice share OP :)
It working perfectly for Digitalocean

I am unable to use it on Google Cloud Virtual Machine.
It shows virtuailization is disabled and even if I delete it, it doesn't work.. Any tips?
 
Checking if nested virtualization is supported
For Intel processors, check the /sys/module/kvm_intel/parameters/nested file. For AMD processors, check the /sys/module/kvm_amd/parameters/nested file. If you see 1 or Y, nested virtualization is supported; if you see 0 or N, nested virtualization is not supported.

For example:

$ cat /sys/module/kvm_intel/parameters/nested
Y
Enabling nested virtualization
To enable nested virtualization for Intel processors:

  1. Shut down all running VMs and unload the kvm_probe module:

    # modprobe -r kvm_intel
  2. Activate the nesting feature:

    # modprobe kvm_intel nested=1
  3. Nested virtualization is enabled until the host is rebooted. To enable it permanently, add the following line to the /etc/modprobe.d/kvm.conf file:

    options kvm_intel nested=1
To enable nested virtualization for AMD processors:

  1. Shut down all running VMs and unload the kvm_amd module:

    # modprobe -r kvm_amd
  2. Activate the nesting feature:

    # modprobe kvm_amd nested=1
  3. Nested virtualization is enabled until the host is rebooted. To enable it permanently, add the following line to the /etc/modprobe.d/kvm.conf file:

    options kvm_amd nested=1
after that you have to configure virt manager which i am not posting here

Thanks for sharing valuable information with us.

Would like to hear about about "configure virt manager" too :)

Regards
 
VirusTotal Results:

[Full .zip package]
Code:
https://www.virustotal.com/#/url/43cca1a337fd69fca4dc7eab19effa5e828d2982063d79c006645ad90f00427d/detection

[.sh script file]
Code:
https://www.virustotal.com/#/url/41afac7f5c1791890e6fe038d5485a811f653288aec26c30d5e0872555c46c74/detection

Dependencies

[Windows Server 2012 R2 .ISO file]
Code:
https://www.virustotal.com/#/url/0d84faba6c5738588d91ed3a7e6db36884d4dda956acc90461965065b533d69f/detection

[QEMU-KVM App]
Code:
https://www.virustotal.com/#/url/4634adccfa49f26913dec2073dafac222eb99f218b4eca014a2bf95c2bae725b/detection
 
Would like to know if this works on a CONTABO VPS?
Also, do I lose performance this way?
Will the Windows machine run slower, than originally getting a Windows VPS?
 
Would like to know if this works on a CONTABO VPS?
Also, do I lose performance this way?
Will the Windows machine run slower, than originally getting a Windows VPS?

run this below command :
Code:
echo $(egrep '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l)
if output is greater than 0, then Virtualization is enabled :D
Then you can apply this Script.

Now about performance.
CPU Performance:
QEMU-KVM virtualization would copy exact physical CPU cores, so CPU performance wise, it would be almost same.
Network performance:
QEMU-KVM virtualization would use a nic(network interface card) rather than its own physical network interface, so network speed would be lower.

Regards
 
Was looking for something like this, much appreciated
 
Back
Top