Projecte

General

Perfil

Virtualbox » Historial » Versió 13

Pau Escrich, 06-01-2013 20:37

1 13 Pau Escrich
2
{{toc}}
3
4 1 Pau Escrich
h1. Virtualbox
5
6
It is possible to emulate qMp with Virtual Box.
7
8 5 Pau Escrich
First of all open your virtualbox (VB) and create a new machine (type linux 2.6).
9 6 Pau Escrich
If you are using the VB wizard, do not select any storage device, we will do it latter.
10 5 Pau Escrich
11 3 Pau Escrich
h3. Storage
12 1 Pau Escrich
13 10 Pau Escrich
To make the things easy it is better to use IDE instead of SATA. 
14
Create a new IDE disk and browse between your foldersand select the qMp vdi image file.
15
16 11 Pau Escrich
The vdi file can be obtained here: http://fw.qmp.cat/testing with the name VBox-qMp_testing-factory-XXXXX.bin
17
It should be renamed to something such as VBox-qMp1.vd1
18 3 Pau Escrich
19 2 Pau Escrich
h3. Network Configuration
20 1 Pau Escrich
21
First of all we create a virtual tun/tap device in the host machine.
22 3 Pau Escrich
23 8 Pau Escrich
<pre>ip tuntap add mode tap dev vbox 
24 1 Pau Escrich
ip link set vbox up
25
ip addr add 172.30.22.10/24 dev vbox
26 3 Pau Escrich
</pre>
27 1 Pau Escrich
28 3 Pau Escrich
In VB machine configuration at least one network interface must be added.
29 1 Pau Escrich
It should be configured as bridged interface to our new "vbox" network device.
30
The driver "PCnet-PCI II" works fine.
31
32
33
h3. Serial
34 3 Pau Escrich
35
A serial port is needed because OpenWRT expects it. So it should be added in the VB machine configuration.
36
37
It is possible to use it to connect with the qMp node from the host machine (useful for debug), but it is NOT NEEDED.
38
To do so you should configure the VB serial as host pipe.
39 1 Pau Escrich
Check the option "create pipe" and add the path "/tmp/vboxS0".
40 3 Pau Escrich
Then in the host machine execute:
41 8 Pau Escrich
<pre>socat UNIX-CONNECT:/tmp/vboxS0 TCP-LISTEN:7777 &
42 3 Pau Escrich
netcat localhost 7777
43
</pre>
44
45
And you will get serial!
46 9 Pau Escrich
47
h3. Start VM
48
49
At this point you can start your virtual machine with qMp, open a browser and go to http://172.30.22.1
50
51
If after the first reboot (automatic reboot) it does not boot (stays in "GRUB LOADING") reboot manually the VM.
52
53
h3. Clone
54
55
Ok, but just one node is quite boring so let's go to create more of them. Just switch-off the virtual machine, right click and Clone it.
56
Select the option "regenerate MAC addresses", boot the new  machine and then execute:
57
58
<pre>rm /qmp_configured
59
/etc/init.d/qmp_autoconf start
60
</pre>
61
62
Then both nodes should see each other!
63 12 Pau Escrich
64
h1. QEMU
65
66
It is possible to use the same VirtualBox VDI image file. So again, you can get it from http://fw.qmp.cat
67
Copy it to somewhere and change the name to, for instance "qMp1.vdi".
68
69
Then just start QEMU:
70
71
<pre>sudo qemu -net nic,model=pcnet -m 64 -hda qMp1.vdi</pre>
72
73
You can add "-nographic" option and "-deamonize".
74
75
h3. Serial
76
77
Get serial is very easy, just add this option to QEMU
78
79
<pre>-serial pty</pre>
80
81
The qmeu will show you the pty device attached to the serial port of the virtual machine, then just use it:
82
83
<pre>screen /dev/pts/3</pre>
84
85
Amazing!
86
87
h3. Network
88
89
There are several ways to get the network working, I use the combo bridge+tap.
90
In the host machine we will have a bridge named "qemu" and the network interface of the virtual machine
91
will be a tap device attached to such bridge.
92
93
The next options must be added to the qemu exec command line
94
95
<pre>-net tap,ifname=qmp1</pre>
96
97
And these two scripts are needed:
98
99
*/etc/qemu-ifup*
100
<pre>
101
#!/bin/sh
102
if ! brctl show | grep qemu; then
103
	brctl addbr qemu
104
	ip link set qemu up
105
fi
106
echo "Executing /etc/qemu-ifup"
107
echo "Bringing up $1 for bridged mode..."
108
sudo /sbin/ip link set $1 up promisc on
109
echo "Adding $1 to br0..."
110
sudo brctl addif qemu $1
111
sleep 2
112
</pre>
113
114
*/etc/qemu-ifdown*
115
<pre>
116
#!/bin/sh 
117
echo "Executing /etc/qemu-ifdown"
118
sudo /sbin/ip link set $1 down
119
sudo /usr/sbin/brctl delif qemu $1
120
sudo /sbin/ip link delete dev $1
121
</pre>
122
123
And make them executable
124
125
<pre>chmod +x /etc/qemu-if*</pre>
126
127
To reach the node it is needed to add an IP to the host machine bridge:
128
<pre>ip addr add 172.30.22.10/24 dev qemu</pre>