aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qemu.html
diff options
context:
space:
mode:
authorSilvino Silva <silvino@bk.ru>2017-01-14 05:27:24 +0000
committerSilvino Silva <silvino@bk.ru>2017-01-14 05:27:24 +0000
commit5eeb7b45275d15b5562e07cdfd6738d76b1446a9 (patch)
treeffa41a5c7ea985a86581b6eece3f41fb553fe2ae /tools/qemu.html
parent836980a6f974f34d5e5f43aee7c5b5aa6a92c8a0 (diff)
downloaddoc-5eeb7b45275d15b5562e07cdfd6738d76b1446a9.tar.gz
network revision
Diffstat (limited to 'tools/qemu.html')
-rw-r--r--tools/qemu.html127
1 files changed, 86 insertions, 41 deletions
diff --git a/tools/qemu.html b/tools/qemu.html
index 0079dfc..86fb7aa 100644
--- a/tools/qemu.html
+++ b/tools/qemu.html
@@ -12,7 +12,9 @@
<h2 id="kern">1. Host System</h2>
- <p>Load modules, in this case kvm of intel cpu;</p>
+ <p>Prepare host system for virtual machines, this includes create new user,
+ loading necessary modules and configure network. Load kvm module, in this example
+ intel module is loaded but depends on host cpu;</p>
<pre>
# modprobe -a kvm-intel tun virtio
@@ -27,6 +29,7 @@
<h2 id="disk">2. Disk images</h2>
+ <p>Qemu supports multiple disk images types.</p>
<dl>
<dt>img</dt>
<dd>Raw disk image, allows dd to a physical device.</dd>
@@ -115,67 +118,109 @@
KERNEL=="tun", GROUP="kvm", MODE="0660", OPTIONS+="static_node=net/tun"
</pre>
+ <h3>2.1. Routing</h3>
- <h3>2.1. Public Bridge</h3>
-
- <p>Create <a href="network.html#bridge">bridge</a>, create new
- tap and add it to bridge;</p>
-
- <pre>
- # DEV="br0"
- # TAP="tap1"
- </pre>
-
- <pre>
- # ip tuntap add ${TAP} mode tap group kvm
- # ip link set ${TAP} up
- </pre>
+ <p>Create interface with correct permissions set for kvm group.</p>
<pre>
- # ip link set ${TAP} master ${DEV}
+ # sysctl -w net.ipv4.ip_forward=1
+ # iptables -A INPUT -i br0 -j ACCEPT
+ # iptables -A FORWARD -i br0 -j ACCEPT
+ # iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -d 10.0.0.0/24 -j ACCEPT
+ # iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -j MASQUERADE
</pre>
- <h3>2.2. Routing</h3>
+ <h3>2.2. Public Bridge</h3>
- <p>Create interface with correct permissions set for kvm group.</p>
+ <p>Create <a href="network.html#bridge">bridge</a>, create new
+ tap and add it to bridge;</p>
<pre>
- # sysctl -w net.ipv4.ip_forward=1
- # iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
+ DEV="br0"
+
+ ADDR=10.0.0.254
+ NET=10.0.0.0
+ GW=192.168.1.254
+ MASK=24
+
+ # one tap for each cpu core
+ NTAPS=$((`/usr/bin/nproc`))
+
+ case $1 in
+ start)
+ /sbin/ip link add name ${DEV} type bridge
+ /sbin/ip addr add ${ADDR}/${MASK} dev ${DEV} broadcast +
+ /sbin/ip link set dev ${DEV} up
+ /bin/sleep 0.2s
+
+ for i in `/usr/bin/seq $NTAPS`
+ do
+ TAP="tap$i"
+ echo "Setting up ${TAP} tap interface."
+ /sbin/ip tuntap add ${TAP} mode tap group kvm
+ /sbin/ip link set ${TAP} up
+ /bin/sleep 0.2s
+ /sbin/ip link set ${TAP} master ${DEV}
+ done
+
+ exit 0
+ ;;
+ stop)
+
+ for i in `/usr/bin/seq $NTAPS`
+ do
+ TAP="tap$i"
+ echo "Deleting ${TAP} tap interface."
+ /sbin/ip link del ${TAP}
+ done
+
+ /sbin/ip link set dev ${DEV} down
+ /sbin/ip route flush dev ${DEV}
+ /sbin/ip link del ${DEV}
+ exit 0
+ ;;
+ restart)
+ $0 stop
+ $0 start
+ ;;
+ *)
+ echo "Usage: $0 [start|stop|restart]"
+ ;;
+ esac
+
+ # End of file
</pre>
<h2 id="guest">Guest System</h2>
- <p>Start qemu with 512 of ram, mydisk.img as disk and boot from iso</p>
-
<p>See <a href="scripts/system-qemu.sh">scripts/system-qemu.sh</a>,
as template. Run virtual machine that uses above tap device;</p>
<pre>
- $ ISO=~/crux-3.2.iso
- $ IMG=~/crux-img.qcow2
- $ TAP="tap1"
+ #!/bin/bash
- $ qemu-system-x86_64 \
- -enable-kvm \
- -m 1024 \
- -boot d \
- -cdrom ${ISO} \
- -hda ${IMG} \
- -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=no
- </pre>
+ function rmac_addr (){
+ printf '54:60:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))
+ }
- <pre>
- $ ISO=~/crux-3.2.iso
- $ IMG=~/crux-img.qcow2
+ #boot=d
+ boot=$1
+ #iso=crux-3.2.iso
+ iso=$2
+ #image=crux-img.qcow2
+ image=$3
+ #tap="tap1"
+ tap=$4
+ mac=$(rmac_addr)
- $ qemu-system-x86_64 \
+ qemu-system-x86_64 \
-enable-kvm \
-m 1024 \
- -boot d \
- -cdrom ${ISO} \
- -hda ${IMG} \
- -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=no
+ -boot ${boot} \
+ -cdrom ${iso} \
+ -hda ${image} \
+ -device e1000,netdev=t0,mac=${mac} \
+ -netdev tap,id=t0,ifname=${tap},script=no,downscript=no
</pre>
<a href="index.html">Tools Index</a>