Virtualbox » Historial » Versió 18
Roger Pueyo Centelles, 11-03-2014 17:20
| 1 | 13 | Pau Escrich | {{toc}} |
|---|---|---|---|
| 2 | |||
| 3 | 1 | Pau Escrich | h1. Virtualbox |
| 4 | |||
| 5 | It is possible to emulate qMp with Virtual Box. |
||
| 6 | |||
| 7 | 5 | Pau Escrich | First of all open your virtualbox (VB) and create a new machine (type linux 2.6). |
| 8 | 6 | Pau Escrich | If you are using the VB wizard, do not select any storage device, we will do it latter. |
| 9 | 5 | Pau Escrich | |
| 10 | 3 | Pau Escrich | h3. Storage |
| 11 | 1 | Pau Escrich | |
| 12 | 10 | Pau Escrich | To make the things easy it is better to use IDE instead of SATA. |
| 13 | Create a new IDE disk and browse between your foldersand select the qMp vdi image file. |
||
| 14 | |||
| 15 | 11 | Pau Escrich | The vdi file can be obtained here: http://fw.qmp.cat/testing with the name VBox-qMp_testing-factory-XXXXX.bin |
| 16 | 18 | Roger Pueyo Centelles | It should be renamed to something such as VBox-qMp1.vdi |
| 17 | 3 | Pau Escrich | |
| 18 | 2 | Pau Escrich | h3. Network Configuration |
| 19 | 1 | Pau Escrich | |
| 20 | First of all we create a virtual tun/tap device in the host machine. |
||
| 21 | 3 | Pau Escrich | |
| 22 | 8 | Pau Escrich | <pre>ip tuntap add mode tap dev vbox |
| 23 | 1 | Pau Escrich | ip link set vbox up |
| 24 | ip addr add 172.30.22.10/24 dev vbox |
||
| 25 | 3 | Pau Escrich | </pre> |
| 26 | 1 | Pau Escrich | |
| 27 | 3 | Pau Escrich | In VB machine configuration at least one network interface must be added. |
| 28 | 1 | Pau Escrich | It should be configured as bridged interface to our new "vbox" network device. |
| 29 | The driver "PCnet-PCI II" works fine. |
||
| 30 | |||
| 31 | |||
| 32 | h3. Serial |
||
| 33 | 3 | Pau Escrich | |
| 34 | A serial port is needed because OpenWRT expects it. So it should be added in the VB machine configuration. |
||
| 35 | |||
| 36 | It is possible to use it to connect with the qMp node from the host machine (useful for debug), but it is NOT NEEDED. |
||
| 37 | To do so you should configure the VB serial as host pipe. |
||
| 38 | 1 | Pau Escrich | Check the option "create pipe" and add the path "/tmp/vboxS0". |
| 39 | 3 | Pau Escrich | Then in the host machine execute: |
| 40 | 8 | Pau Escrich | <pre>socat UNIX-CONNECT:/tmp/vboxS0 TCP-LISTEN:7777 & |
| 41 | 3 | Pau Escrich | netcat localhost 7777 |
| 42 | </pre> |
||
| 43 | |||
| 44 | And you will get serial! |
||
| 45 | 9 | Pau Escrich | |
| 46 | h3. Start VM |
||
| 47 | |||
| 48 | At this point you can start your virtual machine with qMp, open a browser and go to http://172.30.22.1 |
||
| 49 | |||
| 50 | If after the first reboot (automatic reboot) it does not boot (stays in "GRUB LOADING") reboot manually the VM. |
||
| 51 | |||
| 52 | h3. Clone |
||
| 53 | |||
| 54 | 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. |
||
| 55 | Select the option "regenerate MAC addresses", boot the new machine and then execute: |
||
| 56 | |||
| 57 | <pre>rm /qmp_configured |
||
| 58 | /etc/init.d/qmp_autoconf start |
||
| 59 | </pre> |
||
| 60 | |||
| 61 | Then both nodes should see each other! |
||
| 62 | 12 | Pau Escrich | |
| 63 | h1. QEMU |
||
| 64 | |||
| 65 | It is possible to use the same VirtualBox VDI image file. So again, you can get it from http://fw.qmp.cat |
||
| 66 | Copy it to somewhere and change the name to, for instance "qMp1.vdi". |
||
| 67 | |||
| 68 | Then just start QEMU: |
||
| 69 | |||
| 70 | <pre>sudo qemu -net nic,model=pcnet -m 64 -hda qMp1.vdi</pre> |
||
| 71 | 1 | Pau Escrich | |
| 72 | 14 | Pau Escrich | You can add "-nographic" option and "-daemonize". |
| 73 | 12 | Pau Escrich | |
| 74 | h3. Serial |
||
| 75 | |||
| 76 | Get serial is very easy, just add this option to QEMU |
||
| 77 | |||
| 78 | <pre>-serial pty</pre> |
||
| 79 | |||
| 80 | The qmeu will show you the pty device attached to the serial port of the virtual machine, then just use it: |
||
| 81 | |||
| 82 | <pre>screen /dev/pts/3</pre> |
||
| 83 | |||
| 84 | Amazing! |
||
| 85 | |||
| 86 | h3. Network |
||
| 87 | |||
| 88 | There are several ways to get the network working, I use the combo bridge+tap. |
||
| 89 | In the host machine we will have a bridge named "qemu" and the network interface of the virtual machine |
||
| 90 | will be a tap device attached to such bridge. |
||
| 91 | |||
| 92 | The next options must be added to the qemu exec command line |
||
| 93 | |||
| 94 | <pre>-net tap,ifname=qmp1</pre> |
||
| 95 | |||
| 96 | And these two scripts are needed: |
||
| 97 | |||
| 98 | */etc/qemu-ifup* |
||
| 99 | <pre> |
||
| 100 | #!/bin/sh |
||
| 101 | if ! brctl show | grep qemu; then |
||
| 102 | brctl addbr qemu |
||
| 103 | ip link set qemu up |
||
| 104 | fi |
||
| 105 | echo "Executing /etc/qemu-ifup" |
||
| 106 | echo "Bringing up $1 for bridged mode..." |
||
| 107 | sudo /sbin/ip link set $1 up promisc on |
||
| 108 | echo "Adding $1 to br0..." |
||
| 109 | sudo brctl addif qemu $1 |
||
| 110 | sleep 2 |
||
| 111 | </pre> |
||
| 112 | |||
| 113 | */etc/qemu-ifdown* |
||
| 114 | <pre> |
||
| 115 | #!/bin/sh |
||
| 116 | echo "Executing /etc/qemu-ifdown" |
||
| 117 | sudo /sbin/ip link set $1 down |
||
| 118 | sudo /usr/sbin/brctl delif qemu $1 |
||
| 119 | sudo /sbin/ip link delete dev $1 |
||
| 120 | </pre> |
||
| 121 | |||
| 122 | And make them executable |
||
| 123 | |||
| 124 | 15 | Pau Escrich | <pre>chmod +x /etc/qemu-*</pre> |
| 125 | 12 | Pau Escrich | |
| 126 | To reach the node it is needed to add an IP to the host machine bridge: |
||
| 127 | 1 | Pau Escrich | <pre>ip addr add 172.30.22.10/24 dev qemu</pre> |
| 128 | 15 | Pau Escrich | |
| 129 | h3. Multiple nodes |
||
| 130 | |||
| 131 | Each virtual machine needs its own disk file, so copy the VirtualBox vdi image to, for instance "qMpv2.vdi". |
||
| 132 | You should use a new one, do not copy the image from another existing machine! |
||
| 133 | |||
| 134 | To skip the problem of duplicate MAC addresses, the option "macaddr" should be added to the previous net option. |
||
| 135 | |||
| 136 | <pre>-net tap,ifname=qmp1,macaddr=$(/etc/qemu-mac)</pre> |
||
| 137 | |||
| 138 | And another script is needed (make it executable too!) |
||
| 139 | |||
| 140 | */etc/qemu-mac* |
||
| 141 | <pre> |
||
| 142 | #!/bin/sh |
||
| 143 | # generate a random mac address for the qemu nic |
||
| 144 | printf 'CA:FE:BA:BE:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256)) |
||
| 145 | </pre> |
||
| 146 | |||
| 147 | I use this little script to launch all the virtual machines from a directory: |
||
| 148 | |||
| 149 | <pre> |
||
| 150 | #!/bin/sh |
||
| 151 | VMDIR="${1:-.}" |
||
| 152 | |||
| 153 | for IMG in $VMDIR/*.vdi |
||
| 154 | do |
||
| 155 | echo "Starting image $IMG" |
||
| 156 | sudo qemu -net nic,model=pcnet,macaddr=$(/etc/qemu-mac) \ |
||
| 157 | -net tap,ifname=qmp$(($RANDOM%30)) -m 64 -hda $IMG -nographic -serial pty -daemonize |
||
| 158 | done |
||
| 159 | </pre> |
||
| 160 | |||
| 161 | Example of execution: |
||
| 162 | |||
| 163 | <pre> |
||
| 164 | p4u@eni4c:~/virtual $ ls |
||
| 165 | qMp1.vdi qMp2.vdi qmpvirt.sh |
||
| 166 | |||
| 167 | p4u@eni4c:~/virtual $ sh qmpvirt.sh |
||
| 168 | Starting image ./qMp1.vdi |
||
| 169 | Executing /etc/qemu-ifup |
||
| 170 | Bringing up qmp4306 for bridged mode... |
||
| 171 | 16 | Pau Escrich | Adding qmp13 to br0... |
| 172 | 15 | Pau Escrich | char device redirected to /dev/pts/5 |
| 173 | |||
| 174 | Starting image ./qMp2.vdi |
||
| 175 | Executing /etc/qemu-ifup |
||
| 176 | Bringing up qmp21308 for bridged mode... |
||
| 177 | 16 | Pau Escrich | Adding qmp21 to br0... |
| 178 | 15 | Pau Escrich | char device redirected to /dev/pts/7 |
| 179 | </pre> |
||
| 180 | 17 | Pau Escrich | |
| 181 | A more advanced version of this scripts is attached as file to this article. |