📜 ⬆️ ⬇️

Virtual Windows under Virtual Debian

It was necessary to quickly raise the Windows on the VPS. Hosting chose "cloudy" from Oversana, because they give for testing when registering a small denyuzhku. If the server is kept off and turned on as needed, then it will be enough for a long time. However, the subsequent payment with such a scheme will not afford to hit hard. But the problem is that as a pre-installed Windows system there, of course, no. This article is a small, but complete and working step-by-step guide on installing Windows on a VPS under Debian. Other hosters will probably have something different, but the essence is the same.

We register, buy IP (hereinafter referred to as as an example), we create a server with the installed Debian OS.
Install the necessary:
apt-get update
apt-get install mc nano screen qemu bridge-utils vde2

create a 100M test disk
dd if=/dev/zero of=/root/hda.img count=1 bs=100M

We try to run:
qemu -M pc -m 1024 -win2k-hack -localtime -hda /root/hda.img -boot d -net nic,vlan=0,macaddr=00:ce:53:e9:71:cf -net user,vlan=0 -name "test" -vnc :1

If started, then try to access the console of our virtual machine using vncviewer. IP, port 1

Happened? Great, go ahead.

DNS has already been registered in /etc/resolv.conf, but if we change the network settings, then we will no longer have DNS, therefore we will demolish the package:
apt-get remove --purge resolvconf

We need to get normal control over Windows, for which we will port 3389 to the outside and make NAT so that we can access the Internet from Windows.
We include forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
Run the editor:
nano /etc/sysctl.conf
Next, look for the line # net.ipv4.ip_forward = 1 and remove the "grid"
Add rules for NAT and forwarding:
iptables -A FORWARD -i eth0 -o eth1 -s -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -d -j ACCEPT
iptables -t nat -A POSTROUTING -s -o eth1 -j SNAT --to-source
iptables -A INPUT -s -i eth1 -p tcp -m tcp --dport 3389 -j ACCEPT
iptables -A FORWARD -s -i eth1 -p tcp -m tcp --dport 3389 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 3389 -j DNAT --to-destination

So that every time the network interfaces are started, the rules are loaded, we’ll save the current rules
iptables-save > /etc/iptables.conf
And in the / etc / network / interfaces file, add the boot line “post-up / sbin / iptables-restore </etc/iptables.conf”

Now edit the network configuration file / etc / network / interfaces:

auto eth0 lo eth1 br0

iface lo inet loopback

iface eth0 inet static

iface eth1 inet static

iface br0 inet static
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

post-up /sbin/iptables-restore < /etc/iptables.conf

In file
/ etc / qemu-ifup
comment all

Create / root / qemu-auto and assign the necessary permissions:
echo "" > /root/qemu-auto
chmod 755 /root/qemu-auto
chmod +s /root/qemu-auto

In / root / qemu-auto we write:

sleep 30
vde_tunctl -b
sleep 1
/sbin/ifconfig tap0 promisc up
sleep 1
brctl addif br0 tap0
screen -Sdm qemu qemu -M pc -m 1024 -win2k-hack -localtime -cdrom /root/server2003.iso -hda /root/hda.img -boot d -net nic,macaddr=00:ce:53:e9:71:cf -net tap,ifname=tap0 -name "win2k3" -vnc :1

And in autoload on krone:
crontab -e
@reboot /root/qemu-auto

Downloading a Windows installation disk image from somewhere, like this:

wget http ://myserver/server2003.iso

We create a disk of the size we need, 5G was enough for me:
dd if=/dev/zero of=/root/hda.img count=50 bs=100M

And we start the virtual machine:

Then everything should be clear - with the help of VNC we go to the virtual machine (as in the test example above) and see the usual Windows installation screen. I installed the system on five slots (very quickly, but expensive), then reduced the number to two - it works quite comfortably. By the way, this is the advantage of scalable cloud hosting. In Windows, do not forget to configure the network - IP, mask, gateway, dns Google - and

Everything, we received completely working Windows Server.
And, yes, do not forget after installation to remove the "-vnc: 1" from the start line or replace it with "-vnc"
After rebooting, everything will come to life itself.

Perhaps something was doing wrong - I see Debian almost for the first time. But it works and works the way I need. I hope that someone will come in handy.

PS Do not consider it for ad hosting - I have nothing to do with them.

Source: https://habr.com/ru/post/107471/

All Articles