Commit 4ecadc17 authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

Improving qemus example

1. Automate the build of a base testing image

This uses packer and a debian template.
Uses tansiv/tansiv as login/mdp by default

2. boot_and_log launcher script has been modified

Start the VMs using two network interfaces.
The first interface uses tantap while the second can serve as a
management interface.

```
ping t10[t11] # will go over the tantap network
pint m10[m11] # will go over a regular tap (bridged network)
```

3. the platform xml file force the latency-factor to 1.

For #6
parent 537b69fd
Pipeline #188841 passed with stages
in 10 minutes and 53 seconds
......@@ -4,28 +4,40 @@ set -x
usage() {
cat <<EOF
Start an UDP listener and an UDP client inside the VM.
Use $(tmux a) inside the vm to start using.
USAGE:
./boot_and_log.sh IP MAC
./boot_and_log.sh IP MAC MAC2
Positional Arguments:
IP: the ip to use (this is likely to be correlated to the MAC but it's good enough for now)
MAC: the mac address to use
Boots a VM. Use two nics: one for tantap the other for a regular tap (management interface).
The mapping mac <-> ip must be set in your dhcp.
You can use libvirt network to get the bridge and dhcp up and running.
Positional Arguments:
IP : The IP to use for the tantap interface. This will the source of the vsg packet.
MAC : The mac address to use for the tantap interface.
The tap to use is named based on the last byte of the mac.
MAC2 : The mac address to use for the management interface (regular tantap).
The tap to use is named based on the last byte of the mac.
Environment Variables:
owned:
QEMU: path to the qemu binary (useful to test a modified version)
IMAGE: path to a qcow2 or raw image disk (to serve as backing file for the disk images)
from third party (examples)
SLIRP_DEBUG="all": activate all debug message from slirp
G_MESSAGES_DEBUG="Slirp": glib debug filter
NOTE:
- create tuntap /a priori/:
e.g: sudo ip tuntap add tap11 mode tap user $USER && sudo ip link set tap11 master virbr0 && sudo ip link set tap11 up
- create tuntap before:
- for tap in {tap10,tap11}
do
sudo ip tuntap add $tap mode tap user msimonin && sudo ip link set $tap master tantap0 && sudo ip link set $tap up
done
- for tap in {tap20,tap21}
do
sudo ip tuntap add $tap mode tap user msimonin && sudo ip link set $tap master tantap0-mgmt && sudo ip link set $tap up
done
EOF
}
......@@ -35,7 +47,13 @@ then
exit 1
fi
if (( "$#" != "2" ))
if [ -z $IMAGE ]
then
echo "IMAGE disk isn't set"
exit 1
fi
if (( "$#" != "3" ))
then
usage
exit 1
......@@ -43,6 +61,7 @@ fi
IP=$1
MAC=$2
MAC2=$3
VM_NAME="vm-${MAC//:/-}"
......@@ -68,28 +87,41 @@ disable_root: false
bootcmd:
- echo "-----> START of MY CLOUD INIT <---------- \n"
- echo "-----> END of MY CLOUD INIT <---------- \n"
- echo "192.168.122.10 m10" >> /etc/hosts
- echo "192.168.122.11 m11" >> /etc/hosts
- echo "192.168.120.10 t10" >> /etc/hosts
- echo "192.168.120.11 t11" >> /etc/hosts
- echo "192.168.121.20 m10" >> /etc/hosts
- echo "192.168.121.21 m11" >> /etc/hosts
- echo 127.0.0.1 $VM_NAME >> /etc/hosts
EOF
genisoimage -output $CLOUD_INIT_ISO -volid cidata -joliet -rock $CLOUD_INIT_DIR/user-data $CLOUD_INIT_DIR/meta-data
cat <<EOF > $CLOUD_INIT_DIR/network-config
version: 2
ethernets:
ens3:
dhcp4: true
ens4:
dhcp4: true
EOF
if [ ! -f debian10-x64-min.qcow2 ]; then
scp rennes:/grid5000/virt-images/debian10-x64-min.qcow2 .
fi
genisoimage -output $CLOUD_INIT_ISO -volid cidata -joliet -rock $CLOUD_INIT_DIR/user-data $CLOUD_INIT_DIR/meta-data $CLOUD_INIT_DIR/network-config
# Create the qcow2 to boot from
qemu-img create -f qcow2 -o backing_file=./debian10-x64-min.qcow2 $VM_NAME.qcow2
qemu-img create -f qcow2 -o backing_file=$IMAGE $VM_NAME.qcow2
VM_IMAGE=$VM_NAME.qcow2
# start on the base one
# VM_IMAGE=debian10-x64-min.qcow2
TAP_NAME=tap${MAC:(-2)}
TAP2_NAME=tap${MAC2:(-2)}
$QEMU \
--icount shift=1 \
--icount shift=1,sleep=on \
-rtc clock=vm \
--vsg mynet0,src=$IP \
-m 1g \
-drive file=$VM_IMAGE \
-cdrom $CLOUD_INIT_ISO \
-netdev tantap,src=$IP,id=mynet0,ifname=$TAP_NAME,script=no,downscript=no \
-device e1000,netdev=mynet0,mac=$MAC
\ No newline at end of file
-device e1000,netdev=mynet0,mac=$MAC \
-netdev tap,id=mynet1,ifname=$TAP2_NAME,script=no,downscript=no \
-device e1000,netdev=mynet1,mac=$MAC2
\ No newline at end of file
......@@ -3,17 +3,19 @@
<platform version="4.1">
<actor host="nova-1.lyon.grid5000.fr" function="vsg_vm">
<argument value="192.168.122.10"/> <!-- how simgrid knows me-->
<argument value="192.168.120.10"/> <!-- how simgrid knows me-->
<argument value="./examples/qemus/boot_and_log.sh"/>
<argument value="192.168.122.10"/> <!-- how vsg knows me-->
<argument value="192.168.120.10"/> <!-- how vsg knows me-->
<argument value="52:54:00:00:00:10"/> <!-- my mac address so that the dhcp give the above IP -->
<argument value="52:54:00:00:01:20"/> <!-- secondary mac address-->
</actor>
<actor host="nova-2.lyon.grid5000.fr" function="vsg_vm">
<argument value="192.168.122.11"/> <!-- how simgrid knows me-->
<argument value="192.168.120.11"/> <!-- how simgrid knows me-->
<argument value="./examples/qemus/boot_and_log.sh"/>
<argument value="192.168.122.11"/> <!-- how vsg knows me-->
<argument value="192.168.120.11"/> <!-- how vsg knows me-->
<argument value="52:54:00:00:00:11"/> <!-- my mac address so that the dhcp give the above IP -->
<argument value="52:54:00:00:01:21"/> <!-- secondary mac address -->
</actor>
</platform>
\ No newline at end of file
<?xml version='1.0'?>
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
<platform version="4.1">
<zone id="AS0" routing="Full">
<cluster id="nova" prefix="nova-" suffix=".lyon.grid5000.fr" radical="0-200" speed="16120000000.0f,0.0f,0.0f" core="16" bw="10Gbps" lat="1.0E-1s" router_id="router1">
<prop id="watt_per_state" value="75.83:81.97:174.04, 123.86:123.86:123.86, 66:66:66" />
<prop id="watt_off" value="8.81" />
</cluster>
</zone>
<config>
<prop id ="network/latency-factor" value = "1" />
</config>
<zone id="AS0" routing="Full">
<!--
https://simgrid.org/doc/latest/Configuring_SimGrid.html#choosing-the-platform-models
We are transfering only small packets so we don't want to pay the slow start every time
-->
<cluster id="nova" prefix="nova-" suffix=".lyon.grid5000.fr" radical="0-200" speed="16120000000.0f,0.0f,0.0f" core="16" bw="10Gbps" lat="1.0E-1s" router_id="router1">
<prop id="watt_per_state" value="75.83:81.97:174.04, 123.86:123.86:123.86, 66:66:66" />
<prop id="watt_off" value="8.81" />
</cluster>
</zone>
</platform>
<network>
<name>tantap-management</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='tantap0-mgmt' stp='on' delay='0'/>
<mac address='52:54:00:0c:45:bf'/>
<ip address='192.168.121.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.121.2' end='192.168.121.254'/>
<host mac='52:54:00:00:01:20' ip='192.168.121.20'/>
<host mac='52:54:00:00:01:21' ip='192.168.121.21'/>
</dhcp>
</ip>
</network>
<network>
<name>tantap</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='tantap0' stp='on' delay='0'/>
<mac address='52:54:00:0c:45:bf'/>
<ip address='192.168.120.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.120.2' end='192.168.120.254'/>
<host mac='52:54:00:00:00:10' ip='192.168.120.10'/>
<host mac='52:54:00:00:00:11' ip='192.168.120.11'/>
</dhcp>
</ip>
</network>
packer*
\ No newline at end of file
Create a base image for our test (login: tansiv/ psswd: tansiv)
```
packer build -only qemu debian-10.3.0-x86_64.json
```
https://learn.hashicorp.com/tutorials/packer/getting-started-install
\ No newline at end of file
{
"builders": [
{
"accelerator": "{{user `qemu_accelerator`}}",
"boot_command": [
"<esc><wait>",
"install <wait>",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg <wait>",
"debian-installer=en_US.UTF-8 <wait>",
"auto <wait>",
"locale=en_US.UTF-8 <wait>",
"kbd-chooser/method=us <wait>",
"keyboard-configuration/xkb-keymap=us <wait>",
"netcfg/get_hostname=vm <wait>",
"netcfg/get_domain=tansiv <wait>",
"fb=false <wait>",
"debconf/frontend=noninteractive <wait>",
"console-setup/ask_detect=false <wait>",
"console-keymaps-at/keymap=us <wait>",
"grub-installer/bootdev=/dev/vda <wait>",
"<enter><wait>"
],
"boot_wait": "15s",
"disk_size": "{{user `disk_size`}}",
"headless": "{{user `headless`}}",
"http_directory": "{{user `http_directory`}}",
"iso_checksum": "{{user `iso_checksum_type`}}:{{user `iso_checksum`}}",
"iso_url": "{{user `iso_url`}}",
"output_directory": "packer-{{user `template`}}-qemu",
"qemuargs": [
[
"-m",
"1024M"
]
],
"shutdown_command": "{{user `shutdown_command`}}",
"ssh_password": "{{user `ssh_password`}}",
"ssh_timeout": "10000s",
"ssh_username": "{{user `ssh_username`}}",
"type": "qemu",
"vm_name": "{{ user `template` }}.qcow2"
}
],
"description": "Debian 10.3.0 amd64",
"provisioners": [
{
"execute_command": "echo 'tansiv' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'",
"scripts": [
"scripts/debian.sh",
"scripts/minimize.sh"
],
"type": "shell"
}
],
"variables": {
"disk_size": "102400",
"headless": "true",
"http_directory": "http/",
"iso_checksum": "2af8f43d4a7ab852151a7f630ba596572213e17d3579400b5648eba4cc974ed0",
"iso_checksum_type": "sha256",
"iso_url": "https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.6.0-amd64-netinst.iso",
"qemu_accelerator": "kvm",
"shutdown_command": "echo 'tansiv' | sudo -S shutdown -P now",
"ssh_password": "tansiv",
"ssh_username": "tansiv",
"template": "debian-10.3.0-x86_64",
"vm_basename": "debian-10.3.0"
}
}
choose-mirror-bin mirror/http/proxy string
d-i apt-setup/use_mirror boolean true
d-i base-installer/kernel/override-image string linux-server
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i finish-install/reboot_in_progress note
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i keymap select us
d-i mirror/country string manual
d-i mirror/http/directory string /debian
d-i mirror/http/hostname string httpredir.debian.org
d-i mirror/http/proxy string
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true
d-i passwd/root-login boolean false
d-i passwd/root-password-again password tansiv
d-i passwd/root-password password tansiv
d-i passwd/user-fullname string tansiv
d-i passwd/user-uid string 1000
d-i passwd/user-password password tansiv
d-i passwd/user-password-again password tansiv
d-i passwd/username string tansiv
d-i pkgsel/include string sudo bzip2 acpid cryptsetup zlib1g-dev wget curl dkms make nfs-common
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select full-upgrade
d-i time/zone string UTC
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list
apt-cdrom-setup apt-setup/cdrom/set-first boolean false
apt-mirror-setup apt-setup/use_mirror boolean true
popularity-contest popularity-contest/participate boolean false
tasksel tasksel/first multiselect standard, ssh-server
#!/bin/sh -eux
apt-get -y update
# netperf
apt-get -y install software-properties-common
apt-add-repository non-free
apt-get -y update
apt-get -y install cloud-init iperf
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6
apt-get -y purge ppp pppconfig pppoeconf
apt-get -y purge popularity-contest
apt-get -y autoremove
apt-get -y clean;
rm -rf /usr/share/doc/*
find /var/cache -type f -exec rm -rf {} \;
find /var/log/ -name *.log -exec rm -f {} \;
#!/bin/sh -ux
case "$PACKER_BUILDER_TYPE" in
qemu) exit 0 ;;
esac
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
sync
sync
sync
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment