📜 ⬆️ ⬇️

Install Windows in QEMU under FreeBSD

The installation process of QEMU is covered in the network rather vaguely. All more or less detailed articles that I managed to find have unpleasant features:

First, these articles are outdated. For example, to raise the network bridge in the new 7th FreeBSD, instead of the outdated bridge, use if_bridge.

Secondly, the authors of these articles somehow casually miss some important points, without which the step-by-step implementation of the described procedures has no effect. For example, there is no clear indication that to run QEMU you need either root privileges or configured sudo.
')
Third, the articles set forth some extra procedures that are not directly related to the case. For example, it describes how to export the QEMU window installed on the server to the local Windows.

Simply put, these articles do not work. So I decided to write my article, with blackjack and whores.

Go.

1) Install QEMU
# cd /usr/ports/emulator/qemu
# make -DWITH_KQEMU
# make install

QEMU is easy to install from the ports; you just need to remember to assemble it with the support of the KQEMU acceleration module. In principle, this module is not mandatory, but QEMU works with it much faster.

2) load the acceleration module
# kldload kqemu

In order for the module to load when loaded, you need to add a line to the /boot/loader.conf configuration file:
kqemu_load="YES"

3) We load the asynchronous I / O module
# kldload aio

In order for the module to load when loaded, you need to add a line to the /boot/loader.conf configuration file:
aio_load="YES"

4) Create a hard disk image, on which we will install Windows
$ mkdir /home/user/qemu
$ qemu-img create /home/user/qemu/windows.img 4096M

Place the image in the home directory. However, this is not significant, you can place anywhere. The image size is 4 gigabytes (for Windows itself and a couple of installed programs, this is enough; if needed, you can do more).

5) Install Windows
$ qemu -localtime -m 512 -boot d -cdrom /home/user/windows_install.iso -hda /home/user/qemu/windows.img -name "Windows"

In this case, Windows is installed from the CD image. If you are installing Windows from a real CD, then instead of the /home/user/windows_install.iso image, you must specify the device / dev / acd0.

What does all this garbage mean:

-localtime sets the time in Windows to equal FreeBSD time
-m sets the size of memory in megabytes to be allocated for Windows.
-boot tells QEMU where to boot from (d - CD, c - hard disk)
-cdrom specifies the path to the CD
-hda specify the path to the hard disk
-name displays the name of the operating system running in it in the QEMU window header (optional, purely for beauty)

6) Start Windows
$ qemu -localtime -m 512 -boot c /home/user/qemu/windows.img -name "Windows"

Please note - Windows boots from a hard disk image (-boot c option).

On this, in fact, everything. Windows is running QEMU running FreeBSD.

And now - blackjack and whores.

Windows running in QEMU does not have access to the network. In order for Windows to go online, you need to make some effort.

Imagine that we have two computers, one of which is connected to the network. We want the second computer, which does not have its own access to the network, however, could also go online. To do this, we are a computer that does not have a network, connect to the computer on which the network is. And we set up the computer on which there is a network so that it passes all packets that it sends to the second computer through itself to the network. Thus, the first computer becomes a kind of “bridge” for the second company, through which the network-free computer can enter the network.

This connection is called a “network bridge”.

In our case, FreeBSD, which has access to the network, acts as the first computer, and Windows, running QEMU, as the second company that does not have access to the network. Accordingly, our task is to connect Windows to FreeBSD, and FreeBSD, in turn, to configure it so that it passes packets sent from Windows to itself through the network.

The network bridge in FreeBSD 7.0 is created using the if_bridge module. The network bridge if_bridge was ported from NetBSD and, starting with version 7 of FreeBSD, replaced the outdated network bridge.

0) Find out what is the name of the real physical interface through which the network works in FreeBSD

I have it called em0, your name may be different, for example, rl0.

1) Create a virtual network interface to which Windows will be connected.
# ifconfig tap0 create

2) Create a virtual network interface that will act as a bridge
# ifconfig bridge0 create

3) We integrate interfaces into a bridge
# ifconfig bridge0 addm em0 addm tap0 up

In order for the bridge to be created at boot time, you need to add two lines to the /etc/rc.conf configuration file:
cloned_interfaces="tap0 bridge0"
ifconfig_bridge0="addm em0 addm tap0 up"

This completes the creation of a network bridge. ifconfig should show something like this:
$ ifconfig
em0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=198<VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4>
ether 00:1c:c0:2a:25:3d
inet 192.168.216.10 netmask 0xffffff00 broadcast 192.168.216.255
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
tap0: flags=8902<BROADCAST,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 00:bd:f3:19:00:00
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 5e:54:49:fc:f9:f0
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: tap0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
member: em0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>

As you can see, here we have a real physical interface em0, a virtual interface tap0 and a bridge bridge0. Pay attention: inside bridge0 there are two members - these are em0 and tap0 interfaces connected by a bridge.

Now you need to connect Windows to FreeBSD.

4) Turn on automatic tap0 interface lifting
# sysctl net.link.tap.up_on_open=1

In order for this variable to be initialized when loading, you need to add a line to the configuration file /etc/sysctl.conf:
net.link.tap.up_on_open=1

5) Allow unprivileged user to connect to tap0 interface
# sysctl net.link.tap.user_open=1

In order for this variable to be initialized when loading, you need to add a line to the configuration file /etc/sysctl.conf:
net.link.tap.user_open=1

6) Allow an unprivileged user to open the device / dev / tap0
# chmod 666 /dev/tap0

Here is a delicate moment - device files are re-created every time the system is booted, so access rights to the file after rebooting will return to their original state (600). Therefore, you should set the permissions to the device not through chmod, but through the devfs rules. To do this, add a line to the configuration file /etc/devfs.conf:
perm tap0 0666

And finally, run Windows.

7) Run Windows with network support
$ qemu -localtime -m 512 -boot c /home/user/windows.img -name "Windows" -net nic -net tap,ifname=tap0

As you can see, two -net parameters have been added to the normal startup parameters.

The first -net with a value of nic creates a QEMU network card “inside” that Windows will see and use next.

The second -net with a tap value connects this network card to the virtual interface tap0. The option ifname = tap0, separated by a comma, means that you need to connect to the tap0 interface. In principle, this is not a mandatory option, but sometimes, for whatever reasons, QEMU tries to connect not with default tap0, but, say, to tap1 or tap4. In this case, you can explicitly specify the desired interface by adding this option.

All booted, Windows will detect the network card and will go to the network through it.

Original article:

m-ivanov.livejournal.com/3384.html

Additional materials about QEMU:

www.ibm.com/developerworks/ru/library/l-qemu/index.html
community.livejournal.com/ru_root/710103.html
www.opennet.ru/base/sys/qemu_win.txt.html
ru.gentoo-wiki.com/%D0%9F%D0%BE%D0%B4%D0%BA%D0%BB%D1% 8E%D1%87% D0% B5% D0% BD% D0% B8% D0 % B5_% D0% 92% D0% 9C_qemu_% D0% B2_% D0% BB% D0% BE% D0% BA% D0% B0% D0% BB% D1% 8C% D0% BD% D1% 83% D1% 8E_ % D1% 81% D0% B5% D1% 82% D1% 8C
www.michurin.com.ru/qemu.shtml

And also about setting up a network bridge:

www.opennet.ru/base/net/net_bridge.txt.html
www.bsdportal.ru/viewtopic.php?p=93244&sid=915bbd7f20ecd5765f078824486bb6c3

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


All Articles