Skip to content

Commit 71aa8c4

Browse files
authored
Update Manual.md
1 parent 034bde3 commit 71aa8c4

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

Manual.md

+61-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
In manual part we are going to see two base example of using ```QEMU``` in order to virtualize
44
our system.
55

6-
## VM Creation
6+
## 1. VM Creation
77

88
In first example we are going to create a virtual machine on our system using ```QEMU```.
99

@@ -46,7 +46,59 @@ After installing Ubuntu, make sure you remove the -cdrom flag from the qemu comm
4646
qemu-system-x86_64 -enable-kvm -boot menu=on -drive file=Image.img -m 4G -cpu host -vga virtio -display sdl,gl=on
4747
```
4848

49-
## CPU Hotplugin
49+
## 2. Hosting QEMU VMs with Public IP Addresses using TAP Interfaces
50+
51+
To allow VMs to have their own IP addresses while using the same physical link, we need to introduce a bridge into this setup.
52+
Both the VM’s network interface as well as the host’s interface will be connected to the bridge.
53+
54+
### create bridge
55+
56+
```shell
57+
ip link add br0 type bridge
58+
ip link set br0 up
59+
```
60+
61+
Next, we want to connect the eth0 interface to the bridge and re-assign the IP address from eth0 to br0. Please note that these commands
62+
will drop internet connectivity of your machine, so either only run them on a local PC or ensure that in case of disaster
63+
you can reboot the machine somehow.
64+
```192.168.0.10``` is just an example IP address, you need to use your own of course.
65+
66+
### add ip to bridge
67+
68+
```shell
69+
ip link set eth0 up
70+
ip link set eth0 master br0
71+
72+
ip addr flush dev eth0
73+
74+
ip addr add 192.168.0.10/24 brd + dev br0
75+
ip route add default via 192.168.0.1 dev br0
76+
```
77+
78+
### tap interface
79+
80+
Next, we can create the TAP interface to be used by the VMs. ```$YOUR_USER``` is used to allow an unprivileged user to connect to the TAP device.
81+
This is important for QEMU, since QEMU VMs should be started as non-root users.
82+
83+
```shell
84+
ip tuntap add dev tap0 mode tap user $YOUR_USER
85+
ip link set dev tap0 up
86+
ip link set tap0 master br0
87+
```
88+
89+
### start
90+
91+
And now we can start a VM. The MAC address could e.g. be generated randomly:
92+
93+
```shell
94+
RAND_MAC=$(printf 'DE:AD:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256)))
95+
96+
qemu-system-x86_64 -m 1024 -cdrom archlinux-2020.05.01-x86_64.iso \
97+
-device virtio-net-pci,netdev=network0,mac=$RAND_MAC \
98+
-netdev tap,id=network0,ifname=tap0,script=no,downscript=no
99+
```
100+
101+
## 3. CPU Hotplugin
50102

51103
Run ```qmp-shell``` (located in the source tree, under ‍‍‍‍```/scripts/qmp/```) to connect to the just-launched **QEMU**:
52104

@@ -63,7 +115,7 @@ query-hotpluggable-cpus
63115
The ```query-hotpluggable-cpus``` command returns an object for CPUs that are present
64116
(containing a ```qom-path``` member).
65117

66-
## Adding a new vCPU
118+
### adding a new vCPU
67119

68120
From its output, we can see that **IvyBridge-IBRS-x86_64-cpu** is present in socket 1,
69121
while hot-plugging a CPU into socket 1 requires passing the listed properties to QMP device_add:
@@ -72,7 +124,7 @@ while hot-plugging a CPU into socket 1 requires passing the listed properties to
72124
device_add id=cpu-2 driver=IvyBridge-IBRS-x86_64-cpu socket-id=0 core-id=1 thread-id=0
73125
```
74126

75-
### Question 1
127+
#### Question 1
76128

77129
<details>
78130

@@ -95,10 +147,14 @@ Optionally, run QMP ```query-cpus-fast``` for some details about the vCPUs:
95147
query-cpus-fast
96148
```
97149

98-
### Removing vCPU
150+
### removing vCPU
99151

100152
From the ```qmp-shell```, invoke the QMP ```device_del``` command:
101153

102154
```shell
103155
device_del id=cpu-2
104156
```
157+
158+
## Resources
159+
160+
- [blog.stefan-koch.name](https://blog.stefan-koch.name/2020/10/25/qemu-public-ip-vm-with-tap)

0 commit comments

Comments
 (0)