aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-04-24 21:32:39 +0200
committerHarald Welte <laforge@gnumonks.org>2018-06-03 13:29:05 +0200
commit9f2f265e3b6539884cd403909b90e47a5dd9499b (patch)
tree6c75ba3a301464e5851785355531460b3eb99dd9
parentcd23e09f360e92680ebcd0518ea6fa8bb5c7d97c (diff)
add script to create virtual machine with kernel gtp ggsn for qemu-kvm
-rw-r--r--qemu-kvm/ggsn-kernel-gtp/.gitignore2
-rwxr-xr-xqemu-kvm/ggsn-kernel-gtp/create-vm.sh23
-rwxr-xr-xqemu-kvm/ggsn-kernel-gtp/postinst.sh74
-rw-r--r--qemu-kvm/ggsn-kernel-gtp/postinst/Release.key20
-rw-r--r--qemu-kvm/ggsn-kernel-gtp/postinst/authorized_keys2
-rw-r--r--qemu-kvm/ggsn-kernel-gtp/preseed.cfg66
6 files changed, 187 insertions, 0 deletions
diff --git a/qemu-kvm/ggsn-kernel-gtp/.gitignore b/qemu-kvm/ggsn-kernel-gtp/.gitignore
new file mode 100644
index 0000000..caa7b5c
--- /dev/null
+++ b/qemu-kvm/ggsn-kernel-gtp/.gitignore
@@ -0,0 +1,2 @@
+postinst.tar.gz
+*.qcow2
diff --git a/qemu-kvm/ggsn-kernel-gtp/create-vm.sh b/qemu-kvm/ggsn-kernel-gtp/create-vm.sh
new file mode 100755
index 0000000..f6757ce
--- /dev/null
+++ b/qemu-kvm/ggsn-kernel-gtp/create-vm.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e -x
+
+tar czvf postinst.tar.gz postinst
+
+virt-install \
+ --connect qemu:///system \
+ --virt-type kvm \
+ --name debian9 \
+ --memory 1024 \
+ --disk path=./debian9.qcow2,size=8 \
+ --vcpus 1 \
+ --os-type linux \
+ --os-variant debian9 \
+ --network bridge=lxcbr0 \
+ --graphics none \
+ --console pty,target_type=serial \
+ --location 'http://ftp.de.debian.org/debian/dists/stretch/main/installer-amd64/' \
+ --initrd-inject ./preseed.cfg \
+ --initrd-inject ./postinst.sh \
+ --initrd-inject ./postinst.tar.gz \
+ --extra-args 'auto=true hostname=ggsn domain="" console=ttyS0,115200n8 serial'
diff --git a/qemu-kvm/ggsn-kernel-gtp/postinst.sh b/qemu-kvm/ggsn-kernel-gtp/postinst.sh
new file mode 100755
index 0000000..4cbe64c
--- /dev/null
+++ b/qemu-kvm/ggsn-kernel-gtp/postinst.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+# This script is run by debian installer using preseed/late_command
+# directive, see preseed.cfg
+
+# Setup console, remove timeout on boot.
+sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"/g; s/TIMEOUT=5/TIMEOUT=0/g' /etc/default/grub
+update-grub
+
+# Members of `sudo` group are not asked for password.
+sed -i 's/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL:ALL) NOPASSWD:ALL/g' /etc/sudoers
+
+# Empty message of the day.
+echo -n > /etc/motd
+
+# Unpack postinst tarball.
+tar -x -v -z -C/tmp -f /tmp/postinst.tar.gz
+
+# Install SSH key for ggsn.
+mkdir -m700 /home/ggsn/.ssh
+cat /tmp/postinst/authorized_keys > /home/ggsn/.ssh/authorized_keys
+chown -R ggsn:ggsn /home/ggsn/.ssh
+
+# Install SSH key for root.
+mkdir -m700 /root/.ssh
+cat /tmp/postinst/authorized_keys > /root/.ssh/authorized_keys
+chown -R root:root /root/.ssh
+
+# Install misc packages required for building osmocom code
+apt-get install -y --no-install-recommends \
+ autoconf \
+ autoconf-archive \
+ autogen \
+ automake \
+ build-essential \
+ gcc \
+ git \
+ libc-ares-dev \
+ libgnutls28-dev \
+ libncurses5-dev \
+ libtalloc-dev \
+ libreadline-dev \
+ libsctp-dev \
+ libtool \
+ make \
+ pkg-config
+apt-get clean
+
+# add osmocom:nightly feed + install libosmocore-dev
+apt-key add /tmp/postinst/Release.key
+echo "deb http://download.opensuse.org/repositories/network:/osmocom:/nightly/Debian_9.0/ ./" > /etc/apt/sources.list.d/osmocom-nightly.list
+apt-get update
+apt-get install -y --no-install-recommends \
+ libosmocore-dev
+apt-get clean
+
+# Remove some non-essential packages.
+DEBIAN_FRONTEND=noninteractive apt-get purge -y nano laptop-detect tasksel dictionaries-common emacsen-common iamerican ibritish ienglish-common ispell
+
+# Set domain name in hosts file
+#sed -i 's/127.0.1.1\t\([a-z]*\).*/127.0.1.1\t\1\.dp\-net\.com\t\1/' /etc/hosts
+
+# Avoid using DHCP-server provided domain name.
+#sed -i 's/#supersede.*/supersede domain-name "dp-net.com";/' /etc/dhcp/dhclient.conf
+
+# check out sources we need from their respective repositories
+cd /usr/local/src
+git clone git://git.netfilter.org/libmnl
+(cd libmnl && autoreconf -fi && ./configure && make && make install)
+git clone git://git.osmocom.org/libgtpnl
+(cd libgtpnl && autoreconf -fi && ./configure && make && make install)
+git clone git://git.osmocom.org/osmo-ggsn
+(cd osmo-ggsn && autoreconf -fi && ./configure --enable-gtp-linux && make && make install)
+ldconfig
diff --git a/qemu-kvm/ggsn-kernel-gtp/postinst/Release.key b/qemu-kvm/ggsn-kernel-gtp/postinst/Release.key
new file mode 100644
index 0000000..e656238
--- /dev/null
+++ b/qemu-kvm/ggsn-kernel-gtp/postinst/Release.key
@@ -0,0 +1,20 @@
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Version: GnuPG v1.4.5 (GNU/Linux)
+
+mQENBFJBt/wBCADAht3d/ilNuyzaXYw/QwTRvmjyoDvfXw+H/3Fvk1zlDZoiKPPc
+a1wCVBINUZl7vYM2OXqbJwYa++JP2Q48xKSvC6thbRc/YLievkbcvTemf7IaREfl
+CTjoYpoqXHa9kHMw1aALDm8CNU88jZmnV7v9L6hKkbYDxie+jpoj7D6B9JlxgNJ4
+5dQyRNsFGVcIl4Vplt1HyGc5Q5nQI/VgS2rlF/IOXmhRQBc4LEDdU8R2IKnkU4ee
+S7TWanAigGAQhxGuCkS39/CWzc1DhLhjlNhBl/+RTPejkqJtAy00ZLps3+RqUN1Y
+CU/Fsr7aRlYVGqQ/BlptwV0XQ2VVYJX2oEBBABEBAAG0MG5ldHdvcmsgT0JTIFBy
+b2plY3QgPG5ldHdvcmtAYnVpbGQub3BlbnN1c2Uub3JnPokBPAQTAQIAJgUCWmMc
+aQIbAwUJDEAUbQYLCQgHAwIEFQIIAwQWAgMBAh4BAheAAAoJEGLrGgkXKA3fjsoI
+ALSXmXzFCpTxg8a6tvXkqddY/qAmeBMNUf7hslI9wN3leNmCrnuHS8TbHWYJZgtw
+8M5fKL3aRQYaIiqqm1XOUF0OqwYNDj5V3y38mM68NYOkzgSP7foMwZp9Y0TlGhtI
+L8weA+2RUjB4hwwGMAYMqkRZyKW3NhPqdlGGoXac1ilwEyGXFHdOLbkhtyS+P2yb
+/EvaKIN5cMLzRZKeYgdp9WuAirV+yV/SDbgvabW098lrWhGLltlRRDQgMV883p8I
+ERMI1wlLFZGnHL3mfBWGeQ24M/DaBOdXQDtfBLCJ9nGztmDBUb8i6GFWU7nD2TGi
+8mYUsED1ZDwO/0jdvJ4gSluIRgQTEQIABgUCUkG3/AAKCRA7MBG3a51lIzhdAJ9v
+d6XPffMZRcCGgDEY5OaTn/MsCQCgrXbeZpFJgnirSrc8rRonvzYFiF4=
+=Gvly
+-----END PGP PUBLIC KEY BLOCK-----
diff --git a/qemu-kvm/ggsn-kernel-gtp/postinst/authorized_keys b/qemu-kvm/ggsn-kernel-gtp/postinst/authorized_keys
new file mode 100644
index 0000000..817a537
--- /dev/null
+++ b/qemu-kvm/ggsn-kernel-gtp/postinst/authorized_keys
@@ -0,0 +1,2 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCmaAZWIdZZjFZHq7Xm5OCUz/Cm46haad+pm2iZ2uSQCIXubjN8HGz1XujBMH1DHhSDK+L0JOBEtxHaY4JR7F177V5R8o50VNwmtTrTaNBPS8WPyVBDuHjjDVSZA+d6QT3Y+3X/FhfoFKmGc2a8MZ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4KqEid2cHI4qu8YLBns5X+GE1BB9o/ix5eSYFTBju0FlgzLaYEmo6zIURpKKvKfPEgpU/ZYWRX1SaUlohXaJxB60k87eyHNDCFwyIFDklZ8LB0WBvTJGqJaDmRcR9Idz4dP8UWCHD0hiShSLKW5sOFzkJflFRmaTWmBV8W/mwc9lVJrYuaSd7S4w== laforge@sunbeam.rsa
diff --git a/qemu-kvm/ggsn-kernel-gtp/preseed.cfg b/qemu-kvm/ggsn-kernel-gtp/preseed.cfg
new file mode 100644
index 0000000..3e70010
--- /dev/null
+++ b/qemu-kvm/ggsn-kernel-gtp/preseed.cfg
@@ -0,0 +1,66 @@
+# Preconfiguration file for jessie.
+# For more details see https://www.debian.org/releases/jessie/example-preseed.txt
+d-i debian-installer/locale string en_US
+d-i keyboard-configuration/xkb-keymap select us
+
+# Choose an network interface that has link if possible.
+d-i netcfg/choose_interface select auto
+
+# Disable that annoying WEP key dialog.
+d-i netcfg/wireless_wep string
+
+# Mirror settings.
+d-i mirror/country string manual
+d-i mirror/http/hostname string ftp.de.debian.org
+d-i mirror/http/directory string /debian
+d-i mirror/http/proxy string
+
+# Root account setup. You can set password in plain-text or pre-encrypted.
+d-i passwd/root-login boolean true
+d-i passwd/root-password password ggsn
+d-i passwd/root-password-again password ggsn
+#d-i passwd/root-password-crypted password $6$1LCVFshS/kbYVg$M1QS1ZJ3.E7NkAD8sqkqhqExA2HWQ5/iDE.l23Xbr89Z7hTg/jUuBMyrYzANLmRybYcH8Smcy.yGDKMAX3okd0
+
+# User account setup.
+#d-i passwd/make-user boolean false
+d-i passwd/user-fullname string Osmo GGSN
+d-i passwd/username string ggsn
+d-i passwd/user-password password ggsn
+d-i passwd/user-password-again password ggsn
+#d-i passwd/user-password-crypted password $6$dU9we2Mm$Btq1Tk1WkFx3/8YsXWbZr13m56uv0PabJKxk5teKAImLLQhtniOURXuOVLmbiBl0O3iS6xQBctNIc9Dn5b3vR.
+# Password login is disabled.
+#d-i passwd/user-password-crypted password !
+
+# Controls whether or not the hardware clock is set to UTC.
+d-i clock-setup/utc boolean true
+# See the contents of /usr/share/zoneinfo/ for valid values.
+d-i time/zone string Europe/Berlin
+# Controls whether to use NTP to set the clock during the install.
+d-i clock-setup/ntp boolean true
+
+# Simple non-LVM, all files in one partition.
+# For more examples see https://www.debian.org/releases/jessie/example-preseed.txt
+d-i partman-auto/method string regular
+d-i partman-auto/choose_recipe select atomic
+d-i partman-partitioning/confirm_write_new_label boolean true
+d-i partman/choose_partition select finish
+d-i partman/confirm boolean true
+d-i partman/confirm_nooverwrite boolean true
+
+# Do not install recommended packages by default.
+d-i base-installer/install-recommends boolean false
+tasksel tasksel/first multiselect
+# Individual additional packages to install. acpid and acpi-support-base are required to make virsh shutdown to work.
+# ACPI packages are needed for `virsh shutdown <domain>` to work.
+d-i pkgsel/include string openssh-server ca-certificates acpid acpi-support-base
+popularity-contest popularity-contest/participate boolean false
+
+# Boot loader installation.
+d-i grub-installer/only_debian boolean true
+d-i grub-installer/bootdev string /dev/vda
+
+# Run postinst.sh in /target just before the install finishes.
+d-i preseed/late_command string cp postinst.sh postinst.tar.gz /target/tmp/ && chmod 755 /target/tmp/postinst.sh && in-target /tmp/postinst.sh
+
+# Avoid that last message about the install being complete.
+d-i finish-install/reboot_in_progress note