diff --git a/BACKUP_Linux-to-Windows-with-QEMU-master.zip b/BACKUP_Linux-to-Windows-with-QEMU-master.zip new file mode 100644 index 0000000..827aba4 Binary files /dev/null and b/BACKUP_Linux-to-Windows-with-QEMU-master.zip differ diff --git a/Centos7_Windows11DEV_NgrokUS.sh b/Centos7_Windows11DEV_NgrokUS.sh new file mode 100644 index 0000000..a75465f --- /dev/null +++ b/Centos7_Windows11DEV_NgrokUS.sh @@ -0,0 +1,341 @@ +#!/bin/bash +# +#Vars +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + #sudo yum update -y + sudo yum install -y qemu-kvm + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + sudo apt-get install -y qemu-kvm + sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +link1_status=$(curl -Is https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "200" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + sudo wget -O w11dev.img https://app.vagrantup.com/thuonghai2711/boxes/WindowsIMG/versions/1.0.1/providers/qemu.box +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +#sudo wget -P /floppy https://downloadmirror.intel.com/23073/eng/PROWinx64.exe # Intel Network Adapter for Windows Server 2012 R2 +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +##sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=raw " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +echo "creating disk image" +##dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +custom_param_disk="w11dev.img" +qemu-img resize $custom_param_disk 52GB +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in /details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 1048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 30889 &>/dev/null & +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo This is windows server 11 Enterprise Dev Pre-install, connect using RDP +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +#sudo mkdir /media/powershell +#sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +#sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi diff --git a/Centos7_Windows2022_NgrokUS.sh b/Centos7_Windows2022_NgrokUS.sh new file mode 100644 index 0000000..2519813 --- /dev/null +++ b/Centos7_Windows2022_NgrokUS.sh @@ -0,0 +1,341 @@ +#!/bin/bash +# +#Vars +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + #sudo yum update -y + sudo yum install -y qemu-kvm + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + sudo apt-get install -y qemu-kvm + sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +link1_status=$(curl -Is https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "200" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + sudo wget -O w2022.img https://app.vagrantup.com/thuonghai2711/boxes/WindowsIMG/versions/1.0.0/providers/qemu.box +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +#sudo wget -P /floppy https://downloadmirror.intel.com/23073/eng/PROWinx64.exe # Intel Network Adapter for Windows Server 2012 R2 +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +##sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=raw " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +echo "creating disk image" +##dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +qemu-img resize w2022.img 52GB +custom_param_disk="w2022.img" +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in /details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 1048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 30889 &>/dev/null & +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo This is windows server 2022 Pre-install, connect using RDP +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +#sudo mkdir /media/powershell +#sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +#sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi diff --git a/KMSpico.exe b/KMSpico.exe new file mode 100644 index 0000000..a0bc661 Binary files /dev/null and b/KMSpico.exe differ diff --git a/Katacoda_Windows11SuperLite.sh b/Katacoda_Windows11SuperLite.sh new file mode 100644 index 0000000..f19e900 --- /dev/null +++ b/Katacoda_Windows11SuperLite.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +#Vars +yum install unzip -y +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip ngrok-stable-linux-amd64.zip +clear +echo "Katacoda Centos Windows 11 by fb.com/thuong.hai.581" +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region eu 30889 &>/dev/null & +yum install sudo -y +echo "Downloading QEMU" +sudo yum install -y qemu-kvm +link1_status=$(curl -Is -k https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.2/providers/qemu.box | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is -k https://transfer.sh/1XQtaoZ/lite11.qcow2 | grep HTTP | cut -f2 -d" ") +sudo wget -O lite11.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.2/providers/qemu.box +[ -s lite11.qcow2 ] || sudo wget -O lite11.qcow2 https://transfer.sh/1XQtaoZ/lite11.qcow2 +availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'" +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 856 )"M" +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +nohup sudo /usr/libexec/qemu-kvm -nographic -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=lite11.qcow2,index=0,media=disk,format=qcow2 -boot once=d &>/dev/null & +clear +echo "Katacoda Centos Windows 11 by fb.com/thuong.hai.581" +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo Script by fb.com/thuong.hai.581 +echo Wait 2-4m VM boot up before connect. +echo Do not close Katacoda tab. VM expired in 1 hour. + + + + diff --git a/Katacoda_Windows7SuperLite.sh b/Katacoda_Windows7SuperLite.sh new file mode 100644 index 0000000..f71f3d9 --- /dev/null +++ b/Katacoda_Windows7SuperLite.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +#Vars +yum install unzip -y +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip ngrok-stable-linux-amd64.zip +clear +echo "Katacoda Centos Windows 7 by fb.com/thuong.hai.581" +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region eu 30889 &>/dev/null & +yum install sudo -y +echo "Downloading QEMU" +sudo yum install -y qemu-kvm +link1_status=$(curl -Is -k https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.3/providers/qemu.box | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is -k https://transfer.sh/1imYuZo/lite7.qcow2 | grep HTTP | cut -f2 -d" ") +sudo wget -O lite7.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.3/providers/qemu.box +[ -s lite7.qcow2 ] || sudo wget -O lite7.qcow2 https://transfer.sh/1imYuZo/lite7.qcow2 +availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'" +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 856 )"M" +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +nohup sudo /usr/libexec/qemu-kvm -nographic -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=lite7.qcow2,index=0,media=disk,format=qcow2,if=virtio -boot once=d &>/dev/null & +clear +echo "Katacoda Centos Windows 7 by fb.com/thuong.hai.581" +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo Script by fb.com/thuong.hai.581 +echo Wait 30s-1m VM boot up before connect. +echo Do not close Katacoda tab. VM expired in 1 hour. + + + + diff --git a/Katacoda_Windows81SuperLite.sh b/Katacoda_Windows81SuperLite.sh new file mode 100644 index 0000000..fbbbdf1 --- /dev/null +++ b/Katacoda_Windows81SuperLite.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +#Vars +yum install unzip -y +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip ngrok-stable-linux-amd64.zip +clear +echo "Katacoda Centos Windows 8.1 by fb.com/thuong.hai.581" +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region eu 30889 &>/dev/null & +yum install sudo -y +echo "Downloading QEMU" +sudo yum install -y qemu-kvm +link1_status=$(curl -Is -k https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.4/providers/qemu.box | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is -k https://transfer.sh/1XiXrYw/lite81.qcow2 | grep HTTP | cut -f2 -d" ") +sudo wget -O lite81.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.4/providers/qemu.box +[ -s lite81.qcow2 ] || sudo wget -O lite81.qcow2 https://transfer.sh/1XiXrYw/lite81.qcow2 +availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'" +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 856 )"M" +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +nohup sudo /usr/libexec/qemu-kvm -nographic -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=lite81.qcow2,index=0,media=disk,format=qcow2 -boot once=d &>/dev/null & +clear +echo "Katacoda Centos Windows 8.1 by fb.com/thuong.hai.581" +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo Script by fb.com/thuong.hai.581 +echo Wait 30s-1m VM boot up before connect. +echo Do not close Katacoda tab. VM expired in 1 hour. diff --git a/Linux_QemuWindows10ColabNoVT-X.sh b/Linux_QemuWindows10ColabNoVT-X.sh new file mode 100644 index 0000000..b74482e --- /dev/null +++ b/Linux_QemuWindows10ColabNoVT-X.sh @@ -0,0 +1,21 @@ +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +unzip ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +read -p "Paste authtoken here (Copy and Ctrl+V to paste then press Enter): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 5900 &>/dev/null & +echo Please wait for installing new 10... +sudo apt update -y > /dev/null 2>&1 +echo "Installing QEMU (2-3m)..." +sudo apt install qemu-system-x86 curl -y > /dev/null 2>&1 +echo Downloading Windows Disk... +curl -L -o w10x64.img https://bit.ly/akuhnetW10x64 +echo "Windows 10 x64 Lite On Google Colab" +echo Your VNC IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo "Note: Use Right-Click Or Ctrl+C To Copy" +echo "Please Keep Colab Tab Open, Maximum Time 12h" +echo Script by fb.com/thuong.hai.581 +echo Starting Windows xxxz... +sudo qemu-system-x86_64 -vnc :0 -hda w10x64.img -smp cores=2 -m 8096M -machine usb=on -device usb-tablet + + diff --git a/Linux_QemuWindows2012CNNoVT-X.sh b/Linux_QemuWindows2012CNNoVT-X.sh new file mode 100644 index 0000000..250db5c --- /dev/null +++ b/Linux_QemuWindows2012CNNoVT-X.sh @@ -0,0 +1,23 @@ +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +unzip -o ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +clear +read -p "Paste authtoken here (Copy and Ctrl+V to paste then press Enter): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 5900 &>/dev/null & +echo Please wait for installing... +wget https://transfer.sh/1H19mpR/1.zip > /dev/null 2>&1 +unzip -o 1.zip > /dev/null 2>&1 +wget https://transfer.sh/1kpOhP6/rootfs.tar.xz > /dev/null 2>&1 +tar -xvf rootfs.tar.xz > /dev/null 2>&1 +./dist/proot -S . userdel _apt +echo "Installing QEMU (2-3m)..." +./dist/proot -S . apt install qemu-system-x86 curl -y > /dev/null 2>&1 +echo Downloading Windows Disk... +curl -L -o win.qcow2 https://transfer.sh/129GjDs/win.qcow2 +echo "Windows 2012 r2 CN x64 " +echo Your VNC IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo "Note: Use Right-Click To Copy" +echo Script by fb.com/thuong.hai.581 +cpu=$(echo nproc | bash) +./dist/proot -S . qemu-system-x86_64 -vnc :0 -hda win.qcow2 -smp 8 -accel tcg,thread=multi -m 4096 -machine usb=on -device usb-tablet > /dev/null 2>&1 diff --git a/Linux_QemuWindows7CloudShellNoVT-X.sh b/Linux_QemuWindows7CloudShellNoVT-X.sh new file mode 100644 index 0000000..b1d5d2a --- /dev/null +++ b/Linux_QemuWindows7CloudShellNoVT-X.sh @@ -0,0 +1,20 @@ +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +unzip -o ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +clear +read -p "Paste authtoken here (Copy and Ctrl+V to paste then press Enter): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 5900 &>/dev/null & +echo Please wait for installing... +sudo apt update -y > /dev/null 2>&1 +echo "Installing QEMU (2-3m)..." +sudo apt install qemu-system-x86 curl -y > /dev/null 2>&1 +echo Downloading Windows Disk... +curl -L -o lite7.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.3/providers/qemu.box +echo "Windows 7 x86 Lite On Google Cloud Shell" +echo Your VNC IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo "Note: Use Right-Click To Copy" +echo "Please Keep Cloud Shell Tab Open" +echo Script by fb.com/thuong.hai.581 +cpu=$(echo nproc | bash) +sudo qemu-system-x86_64 -vnc :0 -hda lite7.qcow2 -smp cores=$cpu -m 3072M -machine usb=on -device usb-tablet > /dev/null 2>&1 diff --git a/Linux_QemuWindows7ColabNoVT-X.sh b/Linux_QemuWindows7ColabNoVT-X.sh new file mode 100644 index 0000000..0401a76 --- /dev/null +++ b/Linux_QemuWindows7ColabNoVT-X.sh @@ -0,0 +1,18 @@ +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +unzip ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +read -p "Paste authtoken here (Copy and Ctrl+V to paste then press Enter): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 5900 &>/dev/null & +echo Please wait for installing... +sudo apt update -y > /dev/null 2>&1 +echo "Installing QEMU (2-3m)..." +sudo apt install qemu-system-x86 curl -y > /dev/null 2>&1 +echo Downloading Windows Disk... +curl -L -o lite7.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.3/providers/qemu.box +echo "Windows 7 x86 Lite On Google Colab" +echo Your VNC IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo "Note: Use Right-Click Or Ctrl+C To Copy" +echo "Please Keep Colab Tab Open, Maximum Time 12h" +echo Script by fb.com/thuong.hai.581 +sudo qemu-system-x86_64 -vnc :0 -hda lite7.qcow2 -smp cores=2 -m 8192M -machine usb=on -device usb-tablet > /dev/null 2>&1 diff --git a/Linux_QemuWindows7LiteDevCloudNoVT-X.sh b/Linux_QemuWindows7LiteDevCloudNoVT-X.sh new file mode 100644 index 0000000..2f18367 --- /dev/null +++ b/Linux_QemuWindows7LiteDevCloudNoVT-X.sh @@ -0,0 +1,24 @@ +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +unzip -o ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +clear +read -p "Paste authtoken here (Copy and Ctrl+V to paste then press Enter): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 5900 &>/dev/null & +echo Please wait for installing... +wget https://transfer.sh/1H19mpR/1.zip > /dev/null 2>&1 +unzip -o 1.zip > /dev/null 2>&1 +wget https://transfer.sh/1kpOhP6/rootfs.tar.xz > /dev/null 2>&1 +tar -xvf rootfs.tar.xz > /dev/null 2>&1 +echo "Installing QEMU (2-3m)..." +./dist/proot -S . userdel _apt +./dist/proot -S . apt install qemu-system-x86 curl -y > /dev/null 2>&1 +echo Downloading Windows Disk... +curl -L -o lite7.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.3/providers/qemu.box +echo "Windows 7 x86 Lite On Intel Devcloud" +echo Your VNC IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo "Note: Use Right-Click To Copy" +echo "You Can Close Terminal Tab" +echo Script by fb.com/thuong.hai.581 +cpu=$(echo nproc | bash) +./dist/proot -S . qemu-system-x86_64 -vnc :0 -hda lite7.qcow2 -smp cores=2 -m 3072M -machine usb=on -device usb-tablet > /dev/null 2>&1 diff --git a/Linux_QemuWindowsXPColabNoVT-X.sh b/Linux_QemuWindowsXPColabNoVT-X.sh new file mode 100644 index 0000000..60f934f --- /dev/null +++ b/Linux_QemuWindowsXPColabNoVT-X.sh @@ -0,0 +1,18 @@ +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +unzip ngrok-stable-linux-amd64.zip > /dev/null 2>&1 +read -p "Paste authtoken here (Copy and Ctrl+V to paste then press Enter): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp 5900 &>/dev/null & +echo Please wait for installing... +sudo apt update -y > /dev/null 2>&1 +echo "Installing QEMU (2-3m)..." +sudo apt install qemu-system-x86 curl -y > /dev/null 2>&1 +echo Downloading Windows Disk... +curl -L -o litexp.qcow2 https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.1.0/providers/qemu.box +echo "Windows XP x86 On Google Colab" +echo Your VNC IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo "Note: Use Right-Click Or Ctrl+C To Copy" +echo "Please Keep Colab Tab Open, Maximum Time 12h" +echo Script by fb.com/thuong.hai.581 +sudo qemu-system-x86_64 -vnc :0 -hda litexp.qcow2 -smp cores=2 -m 8192M -machine usb=on -device usb-tablet > /dev/null 2>&1 diff --git a/Linux_Windows10SuperLite_NgrokAP.sh b/Linux_Windows10SuperLite_NgrokAP.sh new file mode 100644 index 0000000..57a0bc3 --- /dev/null +++ b/Linux_Windows10SuperLite_NgrokAP.sh @@ -0,0 +1,338 @@ +#!/bin/bash +# +#Vars +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + #sudo yum update -y + sudo yum install -y qemu-kvm + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + dpkg-reconfigure debconf -f noninteractive -p critical + UCF_FORCE_CONFFOLD=YES apt -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" -y dist-upgrade + sudo apt-get install -y qemu-kvm + sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +link1_status=$(curl -Is https://app.vagrantup.com/thuonghai2711/boxes/WindowsISO/versions/1.0.5/providers/qemu.box | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "302" ] ; then + sudo wget -O /mediabots/WS10LITE.ISO https://app.vagrantup.com/thuonghai2711/boxes/WindowsISO/versions/1.0.5/providers/qemu.box +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +sudo wget -P /floppy https://downloadmirror.intel.com/23073/eng/PROWinx64.exe # Intel Network Adapter for Windows Server 2012 R2 +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=raw " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +echo "creating disk image" +dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +custom_param_disk="disk.img" +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in /details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 2048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +#sudo mkdir /media/powershell +#sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +#sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi diff --git a/Linux_Windows11SuperLiteQCOW2_NgrokAP.sh b/Linux_Windows11SuperLiteQCOW2_NgrokAP.sh new file mode 100644 index 0000000..fd324c3 --- /dev/null +++ b/Linux_Windows11SuperLiteQCOW2_NgrokAP.sh @@ -0,0 +1,358 @@ +#!/bin/bash +# +#Vars +echo Install Gdrive ... +wget -O /usr/src/gdrive https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/gdrive-linux-x64 >/dev/null 2>&1 +chmod +x /usr/src/gdrive >/dev/null 2>&1 +sudo install /usr/src/gdrive /usr/local/bin/gdrive >/dev/null 2>&1 +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.0/providers/qemu22000.box +windows_os_name="Windows 11 Super Lite" +custom_param_disk="windows11lite.qcow2" +echo $custom_param_disk >disk.txt +echo gdrive upload $custom_param_disk >update.txt +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + ##sudo yum update -y + sudo yum install -y qemu-kvm + sudo yum install libguestfs-tools -y + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + ##sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + dpkg-reconfigure debconf -f noninteractive -p critical + UCF_FORCE_CONFFOLD=YES apt -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" -y dist-upgrade + sudo apt-get install -y qemu-kvm + ##sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +link1_status=$(curl -Is $windows_os_link | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "302" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + sudo wget -O $custom_param_disk $windows_os_link +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +##sudo wget -P /floppy https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/KMSpico.exe # Active Windows +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +##sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + ##custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=qcow2 " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +custom_param_disk=$(echo cat disk.txt | bash) +echo "creating disk image" +##dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +qemu-img resize $custom_param_disk 55GB +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 $other_drives -boot c -vnc :9 & disown %1" > details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & disown %1" > details.txt +echo -e "for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done" > killqemu.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 1048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo This is $windows_os_name Pre-install, connect using RDP +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +echo Command start VM if it off: cat details.txt +echo Command force turn off VM: cat killqemu.txt +echo Command update disk to google drive: cat update.txt +echo Install Chrome in CDROM drive +##sudo mkdir /media/powershell +##sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +##sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi diff --git a/Linux_Windows11SuperLite_NgrokAP.sh b/Linux_Windows11SuperLite_NgrokAP.sh new file mode 100644 index 0000000..53e788a --- /dev/null +++ b/Linux_Windows11SuperLite_NgrokAP.sh @@ -0,0 +1,341 @@ +#!/bin/bash +# +#Vars +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + #sudo yum update -y + sudo yum install -y qemu-kvm + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + dpkg-reconfigure debconf -f noninteractive -p critical + UCF_FORCE_CONFFOLD=YES apt -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" -y dist-upgrade + sudo apt-get install -y qemu-kvm + sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +link1_status=$(curl -Is https://app.vagrantup.com/thuonghai2711/boxes/WindowsISO/versions/1.0.6/providers/qemu22000.box | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "302" ] ; then + sudo wget -O /mediabots/WS11LITE.ISO https://app.vagrantup.com/thuonghai2711/boxes/WindowsISO/versions/1.0.6/providers/qemu22000.box +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +sudo wget -P /floppy https://downloadmirror.intel.com/23073/eng/PROWinx64.exe # Intel Network Adapter for Windows Server 2012 R2 +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=raw " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +echo "creating disk image" +dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +custom_param_disk="disk.img" +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in /details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 2048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Pass: Thuonghai001 +echo Connect to VNC, choose disk for windows install when setup done use RDP to connect +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +#sudo mkdir /media/powershell +#sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +#sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi diff --git a/Linux_Windows2012R2QCOW2_NgrokAP.sh b/Linux_Windows2012R2QCOW2_NgrokAP.sh new file mode 100644 index 0000000..3dfed48 --- /dev/null +++ b/Linux_Windows2012R2QCOW2_NgrokAP.sh @@ -0,0 +1,358 @@ +#!/bin/bash +# +#Vars +echo Install Gdrive ... +wget -O /usr/src/gdrive https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/gdrive-linux-x64 >/dev/null 2>&1 +chmod +x /usr/src/gdrive >/dev/null 2>&1 +sudo install /usr/src/gdrive /usr/local/bin/gdrive >/dev/null 2>&1 +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.1/providers/qemu.box +windows_os_name="Windows 2012 R2 Aero" +custom_param_disk="windows2012r2.qcow2" +echo $custom_param_disk >disk.txt +echo gdrive upload $custom_param_disk >update.txt +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + ##sudo yum update -y + sudo yum install -y qemu-kvm + sudo yum install libguestfs-tools -y + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + ##sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + dpkg-reconfigure debconf -f noninteractive -p critical + UCF_FORCE_CONFFOLD=YES apt -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" -y dist-upgrade + sudo apt-get install -y qemu-kvm + ##sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +link1_status=$(curl -Is $windows_os_link | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "302" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + sudo wget -O $custom_param_disk $windows_os_link +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +##sudo wget -P /floppy https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/KMSpico.exe # Active Windows +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +##sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + ##custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=qcow2 " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +custom_param_disk=$(echo cat disk.txt | bash) +echo "creating disk image" +##dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +qemu-img resize $custom_param_disk 55GB +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 $other_drives -boot c -vnc :9 & disown %1" > details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & disown %1" > details.txt +echo -e "for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done" > killqemu.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 1048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo This is $windows_os_name Pre-install, connect using RDP +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +echo Command start VM if it off: cat details.txt +echo Command force turn off VM: cat killqemu.txt +echo Command update disk to google drive: cat update.txt +echo Install Chrome in CDROM drive +##sudo mkdir /media/powershell +##sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +##sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi diff --git a/QEMU-KVM/Linux-W2012R2-start.sh b/QEMU-KVM/Linux-W2012R2-start.sh new file mode 100644 index 0000000..966cea9 --- /dev/null +++ b/QEMU-KVM/Linux-W2012R2-start.sh @@ -0,0 +1,165 @@ +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi + +echo $qemupath >qemupath.txt + + + +qemupath=$(echo cat qemupath.txt | bash) + +clear +echo "VPS1" +vps=vps1 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1001 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS2" +vps=vps2 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1002 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS3" +vps=vps3 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1003 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS4" +vps=vps4 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1004 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS5" +vps=vps5 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1005 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS6" +vps=vps6 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1006 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS7" +vps=vps7 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1007 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS8" +vps=vps8 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1008 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS9" +vps=vps9 + + + + +custom_ram="6000""M" +CPU=3 +PORT=1009 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS10" +vps=vps10 + + + + +custom_ram="6000""M" +CPU=3 +PORT=10010 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT diff --git a/QEMU-KVM/Linux-W2012R2.sh b/QEMU-KVM/Linux-W2012R2.sh new file mode 100644 index 0000000..0a09a41 --- /dev/null +++ b/QEMU-KVM/Linux-W2012R2.sh @@ -0,0 +1,207 @@ +#!/bin/bash +# +#Vars +echo Tao 10 con 3c6gb 100GB disk. +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage screen -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + ##sudo yum remove xorg* -y + ##sudo yum remove gnome* -y + ##yum remove xrdp -y + ##sudo yum update -y + sudo yum install -y qemu-kvm + sudo yum install libguestfs-tools -y + ##curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + ##sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + dpkg-reconfigure debconf -f noninteractive -p critical + UCF_FORCE_CONFFOLD=YES apt -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" -y dist-upgrade + sudo apt-get install -y qemu-kvm + sudo apt-get install -y libguestfs-tools + sudo apt-get install -y screen + ##sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources + +linkgz=https://dl.dropboxusercontent.com/s/w1tjv1d2brpwjiv/Hoanganh0504.gz +[ -s windows2012r2.raw ] || wget -q --show-progress --no-check-certificate -O- $linkgz | gunzip | dd of=windows2012r2.raw bs=1M + +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +echo $qemupath >qemupath.txt + +mkdir vm + +qemupath=$(echo cat qemupath.txt | bash) +clear +echo "VPS1" +vps=vps1 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1001 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS2" +vps=vps2 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1002 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS3" +vps=vps3 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1003 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS4" +vps=vps4 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1004 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS5" +vps=vps5 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1005 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS6" +vps=vps6 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1006 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS7" +vps=vps7 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1007 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS8" +vps=vps8 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1008 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS9" +vps=vps9 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=1009 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT + +echo "VPS10" +vps=vps10 +cp windows2012r2.raw vm/$vps.raw +cd vm +qemu-img resize -f raw $vps.raw +25G +cd .. +custom_ram="6000""M" +CPU=3 +PORT=10010 +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$vps.raw,index=0,media=disk,format=raw -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM, $PORT diff --git a/QEMU-KVM/Linux_Windows11SmallDiskCustom.sh b/QEMU-KVM/Linux_Windows11SmallDiskCustom.sh new file mode 100644 index 0000000..8e7a21b --- /dev/null +++ b/QEMU-KVM/Linux_Windows11SmallDiskCustom.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# +#Vars +echo Install Gdrive ... +wget -O /usr/src/gdrive https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/gdrive-linux-x64 >/dev/null 2>&1 +chmod +x /usr/src/gdrive >/dev/null 2>&1 +sudo install /usr/src/gdrive /usr/local/bin/gdrive >/dev/null 2>&1 +wget -O ngrok-stable-linux-amd64.zip https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip ngrok-stable-linux-amd64.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +##nohup ./ngrok tcp --region ap 30889 &>/dev/null & +windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsQCOW2/versions/1.0.2/providers/qemu.box +windows_os_name="Windows 11 Super Lite" +custom_param_disk="lite11.qcow2" +echo $custom_param_disk >disk.txt +echo gdrive upload $custom_param_disk >update.txt +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage screen -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + ##sudo yum remove xorg* -y + ##sudo yum remove gnome* -y + ##yum remove xrdp -y + ##sudo yum update -y + sudo yum install -y qemu-kvm + sudo yum install libguestfs-tools -y + ##curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + ##sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + dpkg-reconfigure debconf -f noninteractive -p critical + UCF_FORCE_CONFFOLD=YES apt -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" -y dist-upgrade + sudo apt-get install -y qemu-kvm + sudo apt-get install -y libguestfs-tools + sudo apt-get install -y screen + ##sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +link1_status=$(curl -Is $windows_os_link | grep HTTP | cut -f2 -d" " | head -1) +link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +if [ $link1_status = "302" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + sudo wget -O $custom_param_disk $windows_os_link +elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO +else + echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + echo "Exiting.." + sleep 30 + exit 1 +fi +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +echo $qemupath >qemupath.txt +wget -O QEMU_CreateVM.sh https://github.com/kmille36/Linux-to-Windows-with-QEMU/raw/master/QEMU-KVM/QEMU_CreateVM.sh +wget -O QEMU_StartVM.sh https://github.com/kmille36/Linux-to-Windows-with-QEMU/raw/master/QEMU-KVM/QEMU_StartVM.sh +wget -O QEMU_KillVM.sh https://github.com/kmille36/Linux-to-Windows-with-QEMU/raw/master/QEMU-KVM/QEMU_KillVM.sh +wget -O QEMU_DeleteVM.sh https://github.com/kmille36/Linux-to-Windows-with-QEMU/raw/master/QEMU-KVM/QEMU_DeleteVM.sh +chmod +x QEMU_CreateVM.sh +chmod +x QEMU_StartVM.sh +chmod +x QEMU_KillVM.sh +chmod +x QEMU_DeleteVM.sh +clear +echo Coder by: fb.com/thuong.hai.581 +echo Coder by: fb.com/thuong.hai.581 > instruction.txt +echo Done! Original QCOW2 disk downloaded in current directory +echo Done! Original QCOW2 disk downloaded in current directory >> instruction.txt +echo Use screen then ./QEMU_CreateVM.sh to start create VM. +echo Use screen then ./QEMU_CreateVM.sh to start create VM. >> instruction.txt +echo Use screen then ./QEMU_StartVM.sh to start VM if it shutdown. +echo Use screen then ./QEMU_StartVM.sh to start VM if it shutdown. >> instruction.txt +echo Use screen then ./QEMU_KillVM.sh to kill VM process. +echo Use screen then ./QEMU_KillVM.sh to kill VM process. >> instruction.txt +echo Use screen then ./QEMU_DeleteVM.sh to delete VM disk. +echo Use screen then ./QEMU_DeleteVM.sh to delete VM disk. >> instruction.txt +echo RDP User: Administrator +echo RDP User: Administrator >> instruction.txt +echo RDP Password: Thuonghai001 +echo RDP Password: Thuonghai001 >> instruction.txt +echo Intruction also save in instruction.txt +echo Intruction also save in instruction.txt >> instruction.txt +fi diff --git a/QEMU-KVM/QEMU_CreateVM.sh b/QEMU-KVM/QEMU_CreateVM.sh new file mode 100644 index 0000000..6d1effc --- /dev/null +++ b/QEMU-KVM/QEMU_CreateVM.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +#Vars +qemupath=$(echo cat qemupath.txt | bash) +clear +echo "Wellcome to VM creation, type DISKNAME,CPU,RAM(MB),PORT(Max 5 number) you want:" +read -p "DISK NAME: " DISKNAME +read -p "DISK SIZE(Default 10GB): " DISKSIZE +read -p "CPU(Virtual Processor): " CPU +read -p "RAM(MB): " RAM +read -p "PORT(Max 5 number): " PORT +custom_ram="$RAM""M" +custom_disk="$DISKSIZE""G" +mkdir vm +cp lite11.qcow2 vm/$DISKNAME.qcow2 +cd vm +qemu-img resize $DISKNAME.qcow2 $custom_disk +cd .. +sudo nohup $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$DISKNAME.qcow2,index=0,media=disk,format=qcow2 -boot once=d &>/dev/null & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM +echo "Successfully!! Your VM start with RDP Port $PORT" +echo "To check Qemu VM Process: ps auxw |grep qemu" +echo "To start NGROK: ./ngrok tcp --region ap $PORT" +echo "To start NGROK in background: nohup ./ngrok tcp --region ap $PORT &>/dev/null &" +echo "To show NGROK tunnel: curl --silent --show-error http://127.0.0.1:4040/api/tunnels" diff --git a/QEMU-KVM/QEMU_DeleteVM.sh b/QEMU-KVM/QEMU_DeleteVM.sh new file mode 100644 index 0000000..de72a0c --- /dev/null +++ b/QEMU-KVM/QEMU_DeleteVM.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +#Vars +clear +echo "Wellcome to VM delete, type DISKNAME you want to delete:" +cd vm +ls -l --block-size=GB | cut -f1 -d. | uniq -c +read -p "DISK NAME: " DISKNAME +vm=$(echo cat $DISKNAME.txt | bash) +kill $vm +rm $DISKNAME.qcow2 +rm $DISKNAME.txt +cd .. +echo "Delete disk $DISKNAME.qcow2 successfully!! " diff --git a/QEMU-KVM/QEMU_KillVM.sh b/QEMU-KVM/QEMU_KillVM.sh new file mode 100644 index 0000000..eeb906c --- /dev/null +++ b/QEMU-KVM/QEMU_KillVM.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +#Vars +clear +echo "Wellcome to VM kill, type DISKNAME of VM you want to kill:" +cd vm +ls -l --block-size=GB | cut -f1 -d. | uniq -c +read -p "DISK NAME: " DISKNAME +vm=$(echo cat $DISKNAME.txt | bash) +kill $vm +cd .. +echo "Kill VM $DISKNAME $vm successfully!! " diff --git a/QEMU-KVM/QEMU_StartVM.sh b/QEMU-KVM/QEMU_StartVM.sh new file mode 100644 index 0000000..82f450b --- /dev/null +++ b/QEMU-KVM/QEMU_StartVM.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +#Vars +qemupath=$(echo cat qemupath.txt | bash) +clear +echo "Wellcome to VM start, type DISKNAME,CPU,RAM(MB),PORT(Max 5 number) you want:" +cd vm +ls -l --block-size=GB | cut -f1 -d. | uniq -c +read -p "DISK NAME: " DISKNAME +read -p "DISK SIZE(Blank for default): " DISKSIZE +read -p "CPU(Virtual Processor): " CPU +read -p "RAM(MB): " RAM +read -p "PORT(Max 5 number): " PORT +custom_ram="$RAM""M" +custom_disk="$DISKSIZE""GB" +qemu-img resize $DISKNAME.qcow2 $custom_disk +cd .. +sudo $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$DISKNAME.qcow2,index=0,media=disk,format=qcow2 -boot once=d & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM +echo "Successfully!! Your VM start with RDP Port $PORT" +echo "To check Qemu VM Process: ps auxw |grep qemu" +echo "To start NGROK: ./ngrok tcp --region ap $PORT" +echo "To start NGROK in background: nohup ./ngrok tcp --region ap $PORT &>/dev/null &" +echo "To show NGROK tunnel: curl --silent --show-error http://127.0.0.1:4040/api/tunnels" diff --git a/QEMU-KVM/QEMU_TempVM.sh b/QEMU-KVM/QEMU_TempVM.sh new file mode 100644 index 0000000..4091bc4 --- /dev/null +++ b/QEMU-KVM/QEMU_TempVM.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# +#Vars +qemupath=$(echo cat qemupath.txt | bash) +clear +echo "Wellcome to VM Temp Create, type DISKNAME,CPU,RAM(MB),PORT(Max 5 number),DELETE TIME(s) you want:" +read -p "DISK NAME: " DISKNAME +read -p "DISK SIZE(Default 10GB): " DISKSIZE +read -p "CPU(Virtual Processor): " CPU +read -p "RAM(MB): " RAM +read -p "PORT(Max 5 number): " PORT +read -p "DELETE TIME(s): " TIME +custom_ram="$RAM""M" +custom_disk="$DISKSIZE""GB" +mkdir vm +cp lite11.qcow2 vm/$DISKNAME.qcow2 +cd vm +qemu-img resize $DISKNAME.qcow2 $custom_disk +cd .. +sudo $qemupath -nographic -net nic -net user,hostfwd=tcp::$PORT-:3389 -show-cursor -m $custom_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$CPU -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=vm/$DISKNAME.qcow2,index=0,media=disk,format=qcow2 -boot once=d & disown %1 +echo $! > $DISKNAME.txt +cp $DISKNAME.txt vm/$DISKNAME.txt +rm $DISKNAME.txt +echo VM Specifications: $CPU CPU , $custom_ram RAM +echo "Successfully!! Your VM start with RDP Port $PORT" +echo "Your VM will auto delete in $TIME second." +echo "To check Qemu VM Process: ps auxw |grep qemu" +echo "To start NGROK: ./ngrok tcp --region ap $PORT" +echo "To start NGROK in background: nohup ./ngrok tcp --region ap $PORT &>/dev/null &" +echo "To show NGROK tunnel: curl --silent --show-error http://127.0.0.1:4040/api/tunnels" +echo sleep $TIME > run.sh +cd vm >> run.sh +vm=$(echo cat $DISKNAME.txt | bash) >> run.sh +kill $vm >> run.sh +rm $DISKNAME.qcow2 >> run.sh +rm $DISKNAME.txt >> run.sh +cd .. >> run.sh + diff --git a/README.md b/README.md index 2e76198..39b1ead 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,11 @@ sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R Just run below five commands one after another : -`su -` +`sudo 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_Linux-to-Windows.sh` +`wget -P /media/script https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/mediabots_Linux-to-Windows.sh` `chmod +x /media/script/*` @@ -144,6 +144,14 @@ Run below command : `cat /details.txt` +Command kill QEMU : + +`cat /killqemu.txt` + +Command update disk to google drive: + +`cat /update.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 @@ -160,7 +168,7 @@ Right now, Script supports Ubuntu,Debian,CentOS Distros. But very soon I would add the support for all other Linux Distros too. -So stay tuned. +So stay tuned.. --- @@ -186,7 +194,7 @@ https://download.microsoft.com/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBE --- -## Reference +## Reference. askubuntu.com, stackexchange.com, stackoverflow.com, ubuntuforums.com, tecmint.com, qemu.org, myrlse@wjunction, exchangepedia.com diff --git a/Win10Lite-ngrok.sh b/Win10Lite-ngrok.sh new file mode 100644 index 0000000..a891c3f --- /dev/null +++ b/Win10Lite-ngrok.sh @@ -0,0 +1,60 @@ + +clear +echo Getting ready... +sudo apt-get update -y > /dev/null 2>&1 +echo "apt remove -y docker docker.io" > vm +echo "sudo apt-get install -y qemu-kvm unzip" >> vm +nohup bash vm &>/dev/null & +[ -s windows10.raw ] || wget -q --show-progress --no-check-certificate -O- https://bit.ly/3fIeaUg | gunzip | dd of=windows10.raw bs=1M +availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'" +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 512)"M" +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +qemu-img resize windows10.raw 80G +nohup sudo qemu-system-x86_64 -nographic -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor -m 10G -soundhw hda -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=2,threads=2,sockets=1 -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=windows10.raw,index=0,media=disk,format=raw,if=virtio -boot once=d -vnc :1 &>/dev/null & +clear + +echo "=======================" +echo "Downloading ngrok..." +echo "=======================" +curl -sLkO https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.tgz +tar xf ngrok-stable-linux-amd64.tgz + + +function goto +{ + label=$1 + cd + cmd=$(sed -n "/^:[[:blank:]][[:blank:]]*${label}/{:a;n;p;ba};" $0 | + grep -v ':$') + eval "$cmd" + exit +} + +: ngrok +clear +echo "Go to: https://dashboard.ngrok.com/get-started/your-authtoken" +read -p "Paste Ngrok Authtoken: " CRP +./ngrok authtoken $CRP +echo "=======================" +echo "choose ngrok region (for better connection)." +echo "=======================" +echo "us - United States (Ohio)" +echo "eu - Europe (Frankfurt)" +echo "ap - Asia/Pacific (Singapore)" +echo "au - Australia (Sydney)" +echo "sa - South America (Sao Paulo)" +echo "jp - Japan (Tokyo)" +echo "in - India (Mumbai)" +read -p "choose ngrok region: " CRP +./ngrok tcp --region $CRP 3389 &>/dev/null & +sleep 1 +if curl --silent --show-error http://127.0.0.1:4040/api/tunnels > /dev/null 2>&1; then echo OK; else echo "Ngrok Error! Please try again!" && sleep 1 && bash Win10Lite-ngrok.sh; fi +clear +echo "NoMachine: https://www.nomachine.com/download" +echo Done! RDP Information: +echo IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Passwd: Thuonghai001 +echo Note: Wait few minutes windows boot up before connect diff --git a/dotnumbers.ps1 b/dotnumbers.ps1 new file mode 100644 index 0000000..6e97b15 --- /dev/null +++ b/dotnumbers.ps1 @@ -0,0 +1,6 @@ +$i = 432000 +do { + Write-Host $i + sleep 1 + $i-- +} while ($i -gt 0) \ No newline at end of file diff --git a/gdrive-linux-x64 b/gdrive-linux-x64 new file mode 100644 index 0000000..c171dca Binary files /dev/null and b/gdrive-linux-x64 differ diff --git a/mediabots_Linux-to-Windows.sh b/mediabots_Linux-to-Windows.sh index 2c2e9f9..1a34ac5 100644 --- a/mediabots_Linux-to-Windows.sh +++ b/mediabots_Linux-to-Windows.sh @@ -1,6 +1,37 @@ #!/bin/bash # #Vars +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +PS3='Choose your Windows Version you want to install (type 1, 2, 3 then Enter): ' +foods=("Windows-2012" "Windows-2022" "Windows-11") +select fav in "${foods[@]}"; do + case $fav in + "Windows-2012") + windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsIMG/versions/1.0.2/providers/qemu.box + windows_os_name="Windows Server 2012 R2" + custom_param_disk="windows2012.raw" + break + ;; + "Windows-2022") + windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsIMG/versions/1.0.0/providers/qemu.box + windows_os_name="Windows Server 2022 Preview" + custom_param_disk="windows2022.img" + break + ;; + "Windows-11") + windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsIMG/versions/1.0.1/providers/qemu.box + windows_os_name="Windows 11 Enterprise Multi-Session DEV" + custom_param_disk="windows11.img" + break + ;; + *) echo "invalid option $REPLY";; + esac +done +echo $custom_param_disk >disk.txt mounted=0 GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' # Virtualization checking.. @@ -19,24 +50,37 @@ if [ $dist = "CentOS" ] ; then sudo yum install wget vim curl genisoimage -y # Downloading Portable QEMU-KVM echo "Downloading QEMU" - sudo yum update -y + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + #sudo yum update -y sudo yum install -y qemu-kvm + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + #sudo yum install -y powershell elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then printf "Y\n" | apt-get install sudo -y sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb # Downloading Portable QEMU-KVM echo "Downloading QEMU" sudo apt-get update sudo apt-get install -y qemu-kvm + sudo apt-get install -y powershell fi sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs # Downloading resources sudo mkdir /mediabots /floppy /virtio -link1_status=$(curl -Is http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.17050.WINBLUE_REFRESH.140317-1640_X64FRE_SERVER_EVAL_EN-US-IR3_SSS_X64FREE_EN-US_DV9.ISO | grep HTTP | cut -f2 -d" " | head -1) +link1_status=$(curl -Is $windows_os_link | grep HTTP | cut -f2 -d" " | head -1) link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") #sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 -if [ $link1_status = "200" ] ; then - sudo wget -O /mediabots/WS2012R2.ISO http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.17050.WINBLUE_REFRESH.140317-1640_X64FRE_SERVER_EVAL_EN-US-IR3_SSS_X64FREE_EN-US_DV9.ISO +if [ $link1_status = "302" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + sudo wget -O $custom_param_disk $windows_os_link elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO else @@ -45,16 +89,16 @@ else sleep 30 exit 1 fi -sudo wget -P /floppy https://ftp.mozilla.org/pub/firefox/releases/64.0/win32/en-US/Firefox%20Setup%2064.0.exe -sudo mv /floppy/'Firefox Setup 64.0.exe' /floppy/Firefox.exe -sudo wget -P /floppy https://downloadmirror.intel.com/23073/eng/PROWinx64.exe # Intel Network Adapter for Windows Server 2012 R2 +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +##sudo wget -P /floppy https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/KMSpico.exe # Active Windows # Powershell script to auto enable remote desktop for administrator sudo touch /floppy/EnableRDP.ps1 sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 # Downloading Virtio Drivers -sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +##sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso # creating .iso for Windows tools & drivers sudo mkisofs -o /sw.iso /floppy # @@ -111,8 +155,9 @@ fi if [ $diskNumbers -eq 1 ] ; then # opened 1st if if [ $availableRAM -ge 4650 ] ; then # opened 2nd if echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" - read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux - deleteLinux=$(echo "$deleteLinux" | head -c 1) + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp qemupath=/tmp/qemu-system-x86_64 @@ -180,8 +225,9 @@ else fi # 2nd if closed else # 1st if else if [ $availableRAM -ge 4650 ] ; then - read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux - deleteLinux=$(echo "$deleteLinux" | head -c 1) + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp qemupath=/tmp/qemu-system-x86_64 @@ -196,7 +242,8 @@ if [ $availableRAM -ge 4650 ] ; then custom_param_os="/mnt/"$(ls /mnt) custom_param_sw="/media/sw/sw.iso" availableRAM=$(echo $availableRAMcommand | bash) - custom_param_disk=$firstDisk + ##custom_param_disk=$firstDisk + ##custom_param_disk=/dev/mapper/centos-root custom_param_ram="-m "$(expr $availableRAM - 500 )"M" format="" mounted=1 @@ -225,27 +272,32 @@ fi fi # # Running the KVM +custom_param_disk=$(echo cat disk.txt | bash) +echo "creating disk image" +##dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +qemu-img resize $custom_param_disk 55GB echo "[ Running the KVM ]" if [ $skipped = 0 ] ; then echo "[.] running QEMU-KVM" -sudo $qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & # [note- no sudo should be used after that] #pidqemu=$(pgrep qemu) # does not work pid=$(echo $! | head -1) disown -h $pid echo "disowned PID : "$pid echo "[ For Debugging purpose ]" -echo -e "$qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" if [ $mounted = 1 ]; then -echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt # -vnc :23456 incase you dont want to access it via VNC +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt # -vnc :23456 incase you dont want to access it via VNC else -echo -e "$qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1" > /details.txt +echo -e "sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & disown %1" > /details.txt +echo -e "for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done" > /killqemu.txt fi echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" if [ $mounted = 1 ]; then -echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" else -echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" fi echo -e "${BLUE}command also saved in /details.txt file${NC}" echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" @@ -266,24 +318,55 @@ df sync; echo 3 > /proc/sys/vm/drop_caches free -m availableRAM=$(echo $availableRAMcommand | bash) -custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +custom_param_ram="-m "$(expr $availableRAM - 1048 )"M" custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" echo $custom_param_ram echo "[..] running QEMU-KVM again" -$qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & pid2=$(echo $! | head -1) disown -h $pid2 echo "disowned PID : "$pid2 echo "[ For Debugging purpose ]" -echo -e "$qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" -# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3389-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" -echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::3389-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 fi else echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo User: Administrator +echo Password: Thuonghai001 +echo This is $windows_os_name Pre-install, connect using RDP +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +echo Command start VM if it off: cat /details.txt +echo Command force turn off VM: cat /killqemu.txt +echo Install Chrome in CDROM drive +echo Install Gdrive... +wget -O /usr/src/gdrive https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/gdrive-linux-x64 >/dev/null 2>&1 +chmod +x /usr/src/gdrive >/dev/null 2>&1 +sudo install /usr/src/gdrive /usr/local/bin/gdrive >/dev/null 2>&1 +##sudo mkdir /media/powershell +##sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +##sudo pwsh /media/powershell/dotnumbers.ps1 fi else echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" diff --git a/windows2022googledrivecontos7.sh b/windows2022googledrivecontos7.sh new file mode 100644 index 0000000..21efd9a --- /dev/null +++ b/windows2022googledrivecontos7.sh @@ -0,0 +1,355 @@ +#!/bin/bash +# +#Vars +echo Install Gdrive.... +wget -O /usr/src/gdrive https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/gdrive-linux-x64 >/dev/null 2>&1 +chmod +x /usr/src/gdrive >/dev/null 2>&1 +sudo install /usr/src/gdrive /usr/local/bin/gdrive >/dev/null 2>&1 +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +clear +./ngrok authtoken UqkqD5EBxWPggw7xGAiQ_77M4D5kjaPNdr9wdb3m9z +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +nohup ./ngrok tcp 22 &>/dev/null & +##windows_os_link=https://app.vagrantup.com/thuonghai2711/boxes/WindowsIMG/versions/1.0.0/providers/qemu.box +gdrive download 1a3uYAJVywLRu7xhCB69sOVZ9qXjV1ISr +echo gdrive update 1a3uYAJVywLRu7xhCB69sOVZ9qXjV1ISr windows2022.qcow2 >update.txt +windows_os_name="Windows Server 2022 Preview" +custom_param_disk="windows2022.qcow2" +echo $custom_param_disk >disk.txt +mounted=0 +GREEN='\033[1;32m';GREEN_D='\033[0;32m';RED='\033[0;31m';YELLOW='\033[0;33m';BLUE='\033[0;34m';NC='\033[0m' +# Virtualization checking.. +virtu=$(egrep -i '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l) +if [ $virtu = 0 ] ; then echo -e "[Error] ${RED}Virtualization/KVM in your Server/VPS is OFF\nExiting...${NC}"; +else +# +# Deleting Previous Windows Installation by the Script +#umount -l /mnt /media/script /media/sw +#rm -rf /mediabots /floppy /virtio /media/* /tmp/* +#rm -f /sw.iso /disk.img +# installing required Ubuntu packages +dist=$(hostnamectl | egrep "Operating System" | cut -f2 -d":" | cut -f2 -d " ") +if [ $dist = "CentOS" ] ; then + printf "Y\n" | yum install sudo -y + sudo yum install wget vim curl genisoimage -y + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + umount /dev/mapper/centos-home + yes|lvreduce -L 2G /dev/mapper/centos-home + lvextend -r -l+100%FREE /dev/mapper/centos-root + sudo yum remove xorg* -y + sudo yum remove gnome* -y + yum remove xrdp -y + #sudo yum update -y + sudo yum install -y qemu-kvm + sudo yum install libguestfs-tools -y + curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo + #sudo yum install -y powershell +elif [ $dist = "Ubuntu" -o $dist = "Debian" ] ; then + printf "Y\n" | apt-get install sudo -y + sudo apt-get install vim curl genisoimage -y + sudo mkdir /etc/powershell + sudo wget -P /etc/powershell https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb + sudo dpkg -i /etc/powershell/packages-microsoft-prod.deb + # Downloading Portable QEMU-KVM + echo "Downloading QEMU" + sudo apt-get update + sudo apt-get install -y qemu-kvm + sudo apt-get install -y powershell +fi +sudo ln -s /usr/bin/genisoimage /usr/bin/mkisofs +# Downloading resources +sudo mkdir /mediabots /floppy /virtio +#link1_status=$(curl -Is $windows_os_link | grep HTTP | cut -f2 -d" " | head -1) +#link2_status=$(curl -Is https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO | grep HTTP | cut -f2 -d" ") +#sudo wget -P /mediabots https://archive.org/download/WS2012R2/WS2012R2.ISO # Windows Server 2012 R2 +#if [ $link1_status = "302" ] ; then + ##sudo wget -O /mediabots/WS2022.ISO https://software-download.microsoft.com/download/sg/20348.1.210507-1500.fe_release_SERVER_EVAL_x64FRE_en-us.iso + #sudo wget -O $custom_param_disk $windows_os_link +#elif [ $link2_status = "200" -o $link2_status = "301" -o $link2_status = "302" ] ; then + #sudo wget -P /mediabots https://ia601506.us.archive.org/4/items/WS2012R2/WS2012R2.ISO +#else + #echo -e "${RED}[Error]${NC} ${YELLOW}Sorry! None of Windows OS image urls are available , please report about this issue on Github page : ${NC}https://github.com/mediabots/Linux-to-Windows-with-QEMU" + #echo "Exiting.." + #sleep 30 + #exit 1 +#fi +sudo wget -P /floppy http://dl.google.com/chrome/install/375.126/chrome_installer.exe +sudo mv /floppy/'chrome_installer.exe' /floppy/chrome_installer.exe +##sudo wget -P /floppy https://raw.githubusercontent.com/kmille36/Linux-to-Windows-with-QEMU/master/KMSpico.exe # Active Windows +# Powershell script to auto enable remote desktop for administrator +sudo touch /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name \"fDenyTSConnections\" -Value 0" >> /floppy/EnableRDP.ps1 +sudo echo -e "Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name \"UserAuthentication\" -Value 1" >> /floppy/EnableRDP.ps1 +sudo echo -e "Enable-NetFirewallRule -DisplayGroup \"Remote Desktop\"" >> /floppy/EnableRDP.ps1 +# Downloading Virtio Drivers +##sudo wget -P /virtio https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso +# creating .iso for Windows tools & drivers +sudo mkisofs -o /sw.iso /floppy +# +#Enabling KSM +sudo echo 1 > /sys/kernel/mm/ksm/run +#Free memories +sync; sudo echo 3 > /proc/sys/vm/drop_caches +# Gathering System information +idx=0 +fs=($(df | awk '{print $1}')) +for j in $(df | awk '{print $6}');do if [ $j = "/" ] ; then os=${fs[$idx]};echo $os;fi;idx=$((idx+1));done +# +ip=$(curl ifconfig.me) +echo "Linux Distro : "$dist +virtualization=$(lscpu | grep Virtualization: | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "Virtualization : "$virtualization +model=$(lscpu | grep "Model name:" | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "CPU Model : "$model +cpus=$(lscpu | grep CPU\(s\) | head -1 | cut -f2 -d":" | awk '{$1=$1;print}') +echo "No. of CPU cores : "$cpus +if [ $dist = "Debian" ] ;then availableRAMcommand="free -m | head -2 | tail -1 | awk '{print \$4}'" ; elif [ $dist = "Ubuntu" -o $dist = "CentOS" ] ;then availableRAMcommand="free -m | tail -2 | head -1 | awk '{print \$7}'"; fi +availableRAM=$(echo $availableRAMcommand | bash) +echo "Available RAM : "$availableRAM" MB" +diskNumbers=$(fdisk -l | grep "Disk /dev/" | wc -l) +partNumbers=$(lsblk | egrep "part" | wc -l) # $(fdisk -l | grep "^/dev/" | wc -l) +firstDisk=$(fdisk -l | grep "Disk /dev/" | head -1 | cut -f1 -d":" | cut -f2 -d" ") +freeDisk=$(df | grep "^/dev/" | awk '{print$1 " " $4}' | sort -g -k 2 | tail -1 | cut -f2 -d" ") +# Windows required at least 25 GB free disk space +firstDiskLow=0 +if [ $(expr $freeDisk / 1024 / 1024 ) -ge 25 ]; then + newDisk=$(expr $freeDisk \* 90 / 100 / 1024) + if [ $(expr $newDisk / 1024 ) -lt 25 ] ; then newDisk=25600 ; fi +else + firstDiskLow=1 +fi +# +# setting up default values +custom_param_os="/mediabots/"$(ls /mediabots) +custom_param_sw="/sw.iso" +custom_param_virtio="/virtio/"$(ls /virtio) +# +custom_param_ram="-m "$(expr $availableRAM - 200 )"M" +skipped=0 +partition=0 +other_drives="" +format=",format=raw" +if [ $dist = "CentOS" ] ; then + qemupath=$(whereis qemu-kvm | sed "s/ /\n/g" | egrep "^/usr/libexec/") + #b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:print:]\n" | sed 's/^/\/dev\//')) +else + qemupath=$(whereis qemu-system-x86_64 | cut -f2 -d" ") + #b=($(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f1 -d" ")) +fi +if [ $diskNumbers -eq 1 ] ; then # opened 1st if +if [ $availableRAM -ge 4650 ] ; then # opened 2nd if + echo -e "${BLUE}For below option pass${NC} yes ${BLUE}iff, your VPS/Server came with${NC} boot system in ${NC}${RED}'RESCUE'${NC} mode ${BLUE}feature${NC}" + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + custom_param_disk=$firstDisk + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + #for i in $(fdisk -l | grep "^/dev/" | tr -d "*" | tr -s '[:space:]' | cut -f5 -d" "); do + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi + fi +else + if [ $firstDiskLow = 0 ] ; then + if [ $partNumbers -gt 1 ] ; then + idx=0;ix=0; + for i in $(lsblk | egrep "part" | tr -s '[:space:]' | cut -f4 -d" "); do + b=($(lsblk | egrep "part" | tr -s '[:space:]' | cut -f1 -d" " | tr -cd "[:alnum:]\n" | sed 's/^/\/dev\//')) + if [[ $i == *"G" ]]; then a=$(echo $i | tr -d "G"); a=${a%.*} ; if [ $a -ge 25 -a $ix = 0 -a ${b[idx]} != $os ] ; then firstDisk=${b[idx]} ; custom_param_disk=$firstDisk ; partition=1 ; ix=$((ix+3)) ; elif [ $a -ge 25 -a $ix = 3 -a ${b[idx]} != $os ] ; then other_drives="-drive file=${b[idx]},index=$ix,media=disk,format=raw " ; fi ; fi ; + idx=$((idx+1)); + done + if [ $partition = 0 ] ;then + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + echo "creating disk image" + sudo dd if=/dev/zero of=/disk.img bs=1024k seek=$newDisk count=0 + custom_param_disk="/disk.img" + fi + else + skipped=1 + fi +fi # 2nd if closed +else # 1st if else +if [ $availableRAM -ge 4650 ] ; then + ##read -r -p "Do you want to completely delete your current Linux O.S.? (yes/no) : " deleteLinux + ##deleteLinux=$(echo "$deleteLinux" | head -c 1) + deleteLinux=$(echo "N" | head -c 1) + if [ ! -z $deleteLinux ] && [ $deleteLinux = 'Y' -o $deleteLinux = 'y' ] ; then + sudo wget -qO- /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz | sudo tar xvz -C /tmp + qemupath=/tmp/qemu-system-x86_64 + echo "erasing primary disk data" + sudo dd if=/dev/zero of=$firstDisk bs=1M count=1 # blank out the disk + echo "mounting devices" + mount -t tmpfs -o size=4500m tmpfs /mnt + mv /mediabots/* /mnt + mkdir /media/sw + mount -t tmpfs -o size=121m tmpfs /media/sw + mv /sw.iso /media/sw + custom_param_os="/mnt/"$(ls /mnt) + custom_param_sw="/media/sw/sw.iso" + availableRAM=$(echo $availableRAMcommand | bash) + ##custom_param_disk=$firstDisk + ##custom_param_disk=/dev/mapper/centos-root + custom_param_ram="-m "$(expr $availableRAM - 500 )"M" + format="" + mounted=1 + else + echo "using secondary disk for installation." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") # 2nd disk chosen + fi +else + echo "using secondary disk for installation.." + custom_param_disk=$(fdisk -l | grep "Disk /dev/" | awk 'NR==2' | cut -f2 -d" " | cut -f1 -d":") +fi +fi # closed 1st if +# Adding other disks only if multi partitions are not exist +if [ $partition = 0 ] ; then +ix=2 +if [ $custom_param_disk != "/disk.img" ] ; then + for i in $(fdisk -l | grep "Disk /dev/" | cut -f2 -d" " | cut -f1 -d ":") ; do + if [ $i != $custom_param_disk ];then + #echo $i; + ix=$((ix+1)) + other_drives=$other_drives"-drive file=$i,index=$ix,media=disk,format=qcow2 " + if [ $ix = 3 ]; then break; fi + fi + done +fi +fi +# +# Running the KVM +custom_param_disk=$(echo cat disk.txt | bash) +echo "creating disk image" +##dd if=/dev/zero of=disk.img bs=1024k seek=52224 count=0 +qemu-img resize $custom_param_disk 55GB +echo "[ Running the KVM ]" +if [ $skipped = 0 ] ; then +echo "[.] running QEMU-KVM" +sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & +# [note- no sudo should be used after that] +#pidqemu=$(pgrep qemu) # does not work +pid=$(echo $! | head -1) +disown -h $pid +echo "disowned PID : "$pid +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format -drive file=$custom_param_os,index=1,media=cdrom -drive file=$custom_param_sw,index=2,media=cdrom $other_drives -boot once=d -vnc :9 & disown %1" +if [ $mounted = 1 ]; then +echo -e "wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 $other_drives -boot c -vnc :9 & disown %1" > details.txt # -vnc :23456 incase you dont want to access it via VNC +else +echo -e "sudo $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk,format=qcow2 -drive file=$custom_param_sw,index=1,media=cdrom -boot once=d -vnc :9 & disown %1" > details.txt +echo -e "for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done" > killqemu.txt +fi +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +if [ $mounted = 1 ]; then +echo -e "${GREEN_D}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && /tmp/rm vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +else +echo -e "${GREEN_D}$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk$format $other_drives -boot c -vnc :9 & disown %1${NC}" +fi +echo -e "${BLUE}command also saved in details.txt file${NC}" +echo -e "${YELLOW}Now download 'VNC Viewer' App from here :${NC} https://www.realvnc.com/en/connect/download/viewer/\n${YELLOW}Then install it on your computer${NC}" +echo -e "Finally open ${GREEN_D}$ip:9${NC} on your VNC viewer." +if [ $mounted = 1 ]; then +read -r -p "Had your Windows Server setup completed successfully? (yes/no) : " setup_initial +setup_initial=$(echo "$setup_initial" | head -c 1) +sleep 10 +if [ ! -z $setup_initial ] && [ $setup_initial = 'Y' -o $setup_initial = 'y' ] ; then +echo $pid $cpus $custom_param_disk $custom_param_sw $other_drives +echo "helper called" +for i in $(ps aux | grep -i "qemu" | head -2 | tr -s '[:space:]' | cut -f2 -d" ") ; do echo "killing process id : "$i ; kill -9 $i ; done +#sleep 30 +echo "un-mounting" +umount -l /mnt +sleep 10 +df +sync; echo 3 > /proc/sys/vm/drop_caches +free -m +availableRAM=$(echo $availableRAMcommand | bash) +custom_param_ram="-m "$(expr $availableRAM - 1048 )"M" +custom_param_ram2="-m "$(expr $availableRAM - 500 )"M" +echo $custom_param_ram +echo "[..] running QEMU-KVM again" +$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & +pid2=$(echo $! | head -1) +disown -h $pid2 +echo "disowned PID : "$pid2 +echo "[ For Debugging purpose ]" +echo -e "$qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk -drive file=$custom_param_sw,index=1,media=cdrom $other_drives -boot c -vnc :9 & disown %1" +# incase you get qemu-system-x86_64: -net user,hostfwd=tcp::3889-:3389: Could not set up host forwarding rule 'tcp::3389-:3389' ,use this instead -net user,hostfwd=tcp::30889-:3389 +echo -e "${YELLOW} SAVE BELOW GREEN COLORED COMMAND IN A SAFE LOCATION FOR FUTURE USAGE${NC}" +echo -e "${GREEN}wget -P /tmp https://archive.org/download/vkvm.tar_201903/vkvm.tar.gz && tar -C /tmp -zxvf /tmp/vkvm.tar.gz && rm /tmp/vkvm.tar.gz && $qemupath -net nic -net user,hostfwd=tcp::30889-:3389 -show-cursor $custom_param_ram2 -localtime -enable-kvm -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time,+nx -M pc -smp cores=$cpus -vga std -machine type=pc,accel=kvm -usb -device usb-tablet -k en-us -drive file=$custom_param_disk,index=0,media=disk $other_drives -boot c -vnc :9 & disown %1${NC}" +echo -e "Now you can access your Windows server through \"VNC viewer\" or \"Remote Desktop Application\" (if your server 'Remote Desktop' is enabled)." +echo "Job Done :)" +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip && unzip *.zip +read -p "Paste authtoken here (Copy and Right-click to paste): " CRP +./ngrok authtoken $CRP +nohup ./ngrok tcp --region ap 30889 &>/dev/null & +sleep 5 +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +sleep 10 +sudo mkdir /media/powershell +sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Job Done :)" +sleep 5 +clear +echo Your RDP IP Address: +curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"tcp:..([^"]*).*/\1/p' +echo This is $windows_os_name Pre-install, connect using RDP +sleep 10 +echo VNC Server Address: +echo 10.10.20.50:9 +echo Defaut RDP Port Forwading is 30889 +echo Command start VM if it off: cat details.txt +echo Command force turn off VM: cat killqemu.txt +echo Command update disk to google drive: cat update.txt +echo Install Chrome in CDROM drive +##sudo mkdir /media/powershell +##sudo wget -P /media/powershell https://gitlab.com/deadshot191414/winvps/-/raw/main/dotnumbers.ps1 +##sudo pwsh /media/powershell/dotnumbers.ps1 +fi +else +echo "Windows OS required at least 25GB free desk space. Your Server/VPS does't have 25GB free space!" +echo "Exiting....." +fi +fi