1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice
  2. The hosting section is sponsored by Hostwinds visit the BHW Partnership program for your exclusive BHW member hosting benefit today.
    MUST be signed into your BHW account.
    Dismiss Notice

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

Discussion in 'Web Hosting' started by sohom, Feb 23, 2019.

  1. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    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)
    [​IMG]
    Login with your Linux Server Credential.
    3) Run the Script. [ Read -> "How to Run the Script" section of this topic ]
    [​IMG]
    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]
    [​IMG]
    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
    [​IMG]
    in my case my VPS IP was 51.15.229.233
    4) Now you would see, Windows installation is on the process
    [​IMG]
    5) Click/Choose options which I highlighted
    [​IMG]
    [​IMG]
    Choose "Windows Server 2012 R2 SE (with GUI)"
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    Set password for user : Administrator
    Create a 16 to 20 Character long strong password
    [​IMG]
    [​IMG]
    login to Windows Server with your password
    [​IMG]
    [​IMG]
    Windows Server installed successfully :D
    [​IMG]
    Enable Remote Desktop through ebableRDP.ps1 power shell script
    Also install Firefox for browsing
    [​IMG]
    In case .ps1 script prompt like this
    [​IMG]
    press Y and Enter
    ---
    Job Done :)
    Enjoy
    -------------------------------------------------------

    Demo Video




    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
     
    • Thanks Thanks x 15
    Last edited by a moderator: Feb 24, 2019
  2. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    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
     
    • Thanks Thanks x 3
  3. Yzetien

    Yzetien Jr. VIP Jr. VIP

    Joined:
    Jul 23, 2018
    Messages:
    153
    Likes Received:
    75
    Gender:
    Male
    Occupation:
    Strategist
    Does this works on servers previously encrypted with full-disk encryption using Luks2?
     
  4. Fast Cheap Services

    Fast Cheap Services Jr. VIP Jr. VIP

    Joined:
    Dec 16, 2016
    Messages:
    190
    Likes Received:
    144
    Occupation:
    I know how to beat Google
    Location:
    Behind My Computer
    Home Page:
    @sohom will that turn my digitalocean droplet to windows VPS it's with ubuntu server 18
     
  5. Litty21

    Litty21 Newbie

    Joined:
    Jan 30, 2019
    Messages:
    33
    Likes Received:
    3
    Are you sure this works on a Linux VPS? I highly doubt you can use virtualization twice.
     
  6. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    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)

    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
     
    • Thanks Thanks x 1
  7. M4DM4X

    M4DM4X Power Member

    Joined:
    Jan 21, 2015
    Messages:
    535
    Likes Received:
    103
    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.
     
    • Thanks Thanks x 2
  8. saleh06

    saleh06 Registered Member

    Joined:
    Feb 10, 2019
    Messages:
    50
    Likes Received:
    10
    Thankkkksss
     
    • Thanks Thanks x 1
  9. miyuru2u

    miyuru2u Power Member

    Joined:
    Feb 24, 2012
    Messages:
    559
    Likes Received:
    87
    Gender:
    Female
    Home Page:
    thats really helpful
     
    • Thanks Thanks x 1
  10. Lupe God

    Lupe God Newbie

    Joined:
    Jun 18, 2018
    Messages:
    18
    Likes Received:
    11
    Gender:
    Male
    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.
     
  11. stromind

    stromind Jr. VIP Jr. VIP

    Joined:
    Oct 1, 2018
    Messages:
    172
    Likes Received:
    33
    Gender:
    Male
    Occupation:
    system administrator
    Location:
    localhost
    Home Page:
    as far as i know luks2 is currently not supported by qemu-kvm l
     
  12. stromind

    stromind Jr. VIP Jr. VIP

    Joined:
    Oct 1, 2018
    Messages:
    172
    Likes Received:
    33
    Gender:
    Male
    Occupation:
    system administrator
    Location:
    localhost
    Home Page:
    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
     
    • Thanks Thanks x 3
  13. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    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.

    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: Feb 24, 2019
  14. Almighty Pull

    Almighty Pull Regular Member

    Joined:
    Jan 16, 2019
    Messages:
    322
    Likes Received:
    195
    Gender:
    Male
    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?
     
    • Thanks Thanks x 1
  15. Johnlayers

    Johnlayers BANNED BANNED

    Joined:
    Feb 24, 2019
    Messages:
    4
    Likes Received:
    1
    Gender:
    Male
    wow.thanks a lot.
     
    • Thanks Thanks x 1
  16. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    Thanks for sharing valuable information with us.

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

    Regards
     
  17. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    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
     
  18. plau889

    plau889 Newbie

    Joined:
    Sep 19, 2015
    Messages:
    27
    Likes Received:
    2
    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?
     
  19. sohom

    sohom Senior Member

    Joined:
    May 26, 2013
    Messages:
    1,065
    Likes Received:
    240
    Occupation:
    Coder | Programmer
    Location:
    Automation
    Home Page:
    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
     
  20. RayChand

    RayChand Jr. VIP Jr. VIP

    Joined:
    Aug 3, 2010
    Messages:
    575
    Likes Received:
    152
    Gender:
    Male
    Occupation:
    Netrepreneur
    Location:
    Dallas & Alleppey
    Home Page:
    Was looking for something like this, much appreciated