From c12ba1cdb1b565a1897df25ddd5bc9afc2565150 Mon Sep 17 00:00:00 2001 From: Bernhard Ehlers Date: Thu, 6 Aug 2020 11:57:05 +0200 Subject: [PATCH 1/2] Reduce image size of FRR appliance --- appliances/frr.gns3a | 32 ++++++------ packer/alpine-linux/README.rst | 19 +++++-- packer/alpine-linux/frr.json | 4 ++ packer/alpine-linux/scripts/frr.sh | 78 ++++++++++++++++++++++++++++ packer/alpine-linux/scripts/setup.sh | 4 +- 5 files changed, 114 insertions(+), 23 deletions(-) create mode 100644 packer/alpine-linux/frr.json create mode 100644 packer/alpine-linux/scripts/frr.sh diff --git a/appliances/frr.gns3a b/appliances/frr.gns3a index 24438c5..a00a311 100644 --- a/appliances/frr.gns3a +++ b/appliances/frr.gns3a @@ -1,41 +1,39 @@ { "name": "FRR", "category": "router", - "description": "FRRouting (FRR) is an IP routing protocol suite for Linux and Unix platforms which includes protocol daemons for BGP, IS-IS, LDP, OSPF, PIM, and RIP.\n\nFRR’s seamless integration with the native Linux/Unix IP networking stacks makes it applicable to a wide variety of use cases including connecting hosts/VMs/containers to the network, advertising network services, LAN switching and routing, Internet access routers, and Internet peering.\n\nThis is an unofficial VM or FRR.", + "description": "FRRouting (FRR) is an IP routing protocol suite for Linux and Unix platforms which includes protocol daemons for BGP, IS-IS, LDP, OSPF, PIM, and RIP.\n\nFRR’s seamless integration with the native Linux/Unix IP networking stacks makes it applicable to a wide variety of use cases including connecting hosts/VMs/containers to the network, advertising network services, LAN switching and routing, Internet access routers, and Internet peering.\n\nThis is an unofficial VM of FRR.", "vendor_name": "FRRouting Project", "vendor_url": "https://frrouting.org", "product_name": "FRR", "registry_version": 3, "status": "stable", - "maintainer": "Andras Dosztal", + "maintainer": "GNS3 Team", "maintainer_email": "developers@gns3.net", - "usage": "Credentials: frradmin / frr\nIf you exit from the router CLI, you can get back by typing 'vtysh' to the console.", - "port_name_format": "ens{port3}", + "usage": "Credentials: root / root\nIf you exit from the router CLI, you can get back by typing 'vtysh' to the console.", + "port_name_format": "eth{0}", "qemu": { - "adapter_type": "virtio-net-pci", + "adapter_type": "e1000", "adapters": 8, - "ram": 512, - "hda_disk_interface": "virtio", + "ram": 256, "arch": "x86_64", "console_type": "telnet", - "kvm": "require" + "kvm": "allow" }, "images": [ { - "filename": "frr7.1-vm0.4.qcow2", - "version": "7.1 - VM0.4", - "md5sum": "08390f257203126e5edffb9710e47974", - "filesize": 2051801088, - "download_url": "https://sourceforge.net/projects/frr/files/", - "direct_download_url": "https://sourceforge.net/projects/frr/files/frr7.1-vm0.4.qcow2.bz2/download", - "compression": "bzip2" + "filename": "frr-7.3.1.qcow2", + "version": "7.3.1", + "md5sum": "5ed9434e6b87df86704145d77fb7d687", + "filesize": 47535104, + "download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/", + "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/frr-7.3.1.qcow2" } ], "versions": [ { - "name": "7.1 - VM0.4", + "name": "7.3.1", "images": { - "hda_disk_image": "frr7.1-vm0.4.qcow2" + "hda_disk_image": "frr-7.3.1.qcow2" } } ] diff --git a/packer/alpine-linux/README.rst b/packer/alpine-linux/README.rst index 9a0b27b..ce6adec 100644 --- a/packer/alpine-linux/README.rst +++ b/packer/alpine-linux/README.rst @@ -5,10 +5,11 @@ For building an Alpine appliance. https://alpinelinux.org/ -CLI Linux installation -********************** +Alpine CLI installation +*********************** The only added packages are: + * busybox-extras * nano @@ -17,8 +18,18 @@ The only added packages are: packer build alpine_cli.json -GUI Linux installation -********************** +FRR +'''' + +A build of Alpine with FRRouting preinstalled. + +.. code:: bash + + packer build -var-file=frr.json alpine_cli.json + + +Alpine GUI installation +*********************** The GUI version has XFCE4 installed. diff --git a/packer/alpine-linux/frr.json b/packer/alpine-linux/frr.json new file mode 100644 index 0000000..0e502fe --- /dev/null +++ b/packer/alpine-linux/frr.json @@ -0,0 +1,4 @@ +{ + "vm_name": "frr.qcow2", + "setup_script": "frr.sh" +} diff --git a/packer/alpine-linux/scripts/frr.sh b/packer/alpine-linux/scripts/frr.sh new file mode 100644 index 0000000..b0a9c0a --- /dev/null +++ b/packer/alpine-linux/scripts/frr.sh @@ -0,0 +1,78 @@ +# add community repository +sed -i 's/^#\(.*\/v.*\/community\)$/\1/' /etc/apk/repositories +apk update + +# install packages +apk add nano less busybox-extras +apk add frr frr-openrc +rc-update add frr + +# enable IP forwarding +cat > /etc/sysctl.d/50-ip_forwarding.conf << EOF +net.ipv4.conf.all.forwarding=1 +net.ipv6.conf.all.forwarding=1 +EOF + +# change hostname +cat > /root/set_hostname << 'EOF' +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "usage: set_hostname hostname" >&2 + exit 1 +fi + +hostname=$1 +domain=$(hostname -d) +hostname "$hostname" +echo "$hostname" > /etc/hostname +sed -i -e "s/^127\.0\.0\.1.*/127.0.0.1\t${hostname}.${domain} ${hostname} localhost.localdomain localhost/" /etc/hosts +EOF +chmod +x /root/set_hostname +/root/set_hostname frr + +# modify FRR configuration +sed -i -E '/zebra|bgp|ospf|rip|isis|pim|ldp|eigrp|static|bfd/ s/= *no/=yes/' /etc/frr/daemons +echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf +chown frr:frr /etc/frr/vtysh.conf + +# run vtysh in .profile +cat > /root/.profile << EOF +# ~/.profile: executed by Bourne-compatible login shells. + +if [ "$BASH" ]; then + if [ -f ~/.bashrc ]; then + . ~/.bashrc + fi +fi + +mesg n || true + +export VTYSH_PAGER="less -M -i -EFX" +vtysh +EOF + +# network configuration +cat > /etc/network/interfaces << EOF +# +# This is a sample network config, uncomment lines to configure the network +# +# Loopback interface +auto lo +iface lo inet loopback +# Static config for eth0 +#auto eth0 +#iface eth0 inet static +# address 192.168.0.2 +# netmask 255.255.255.0 +# gateway 192.168.0.1 +# up echo nameserver 192.168.0.1 > /etc/resolv.conf + +# DHCP config for eth0 +#auto eth0 +#iface eth0 inet dhcp +# hostname $(hostname) +EOF + +cat > /etc/resolv.conf << EOF +EOF diff --git a/packer/alpine-linux/scripts/setup.sh b/packer/alpine-linux/scripts/setup.sh index 57f2cfc..5d22b2e 100644 --- a/packer/alpine-linux/scripts/setup.sh +++ b/packer/alpine-linux/scripts/setup.sh @@ -20,8 +20,8 @@ iface lo inet loopback # up echo nameserver 192.168.0.1 > /etc/resolv.conf # DHCP config for eth0 -# auto eth0 -# iface eth0 inet dhcp +#auto eth0 +#iface eth0 inet dhcp # hostname $(hostname) EOF From 68c9e58cf1bc93b19481368b6df53a3900d91c4f Mon Sep 17 00:00:00 2001 From: Bernhard Ehlers Date: Fri, 7 Aug 2020 10:52:36 +0200 Subject: [PATCH 2/2] Alpine packer fixes: autologin, reset terminal modes --- appliances/frr.gns3a | 4 ++-- packer/alpine-linux/scripts/frr.sh | 17 +++++++++++++---- packer/alpine-linux/scripts/serial.sh | 2 +- packer/alpine-linux/scripts/setup.sh | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/appliances/frr.gns3a b/appliances/frr.gns3a index a00a311..22b6579 100644 --- a/appliances/frr.gns3a +++ b/appliances/frr.gns3a @@ -23,8 +23,8 @@ { "filename": "frr-7.3.1.qcow2", "version": "7.3.1", - "md5sum": "5ed9434e6b87df86704145d77fb7d687", - "filesize": 47535104, + "md5sum": "e6bd9591a5c630bfe2c8688dc043b20b", + "filesize": 47348224, "download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/", "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/frr-7.3.1.qcow2" } diff --git a/packer/alpine-linux/scripts/frr.sh b/packer/alpine-linux/scripts/frr.sh index b0a9c0a..001e076 100644 --- a/packer/alpine-linux/scripts/frr.sh +++ b/packer/alpine-linux/scripts/frr.sh @@ -18,12 +18,18 @@ cat > /root/set_hostname << 'EOF' #!/bin/sh if [ $# -ne 1 ]; then - echo "usage: set_hostname hostname" >&2 + echo "usage: set_hostname host" >&2 exit 1 fi -hostname=$1 -domain=$(hostname -d) +host=$1 +hostname=${host%%.*} +if [ "$host" = "$hostname" ]; then + domain=$(hostname -d) +else + domain=${host#*.} +fi + hostname "$hostname" echo "$hostname" > /etc/hostname sed -i -e "s/^127\.0\.0\.1.*/127.0.0.1\t${hostname}.${domain} ${hostname} localhost.localdomain localhost/" /etc/hosts @@ -37,9 +43,12 @@ echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf chown frr:frr /etc/frr/vtysh.conf # run vtysh in .profile -cat > /root/.profile << EOF +cat > /root/.profile << 'EOF' # ~/.profile: executed by Bourne-compatible login shells. +# reset terminal modes +[ -t 1 ] && printf '\e[?5l\e[?7h\e[?8h' + if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc diff --git a/packer/alpine-linux/scripts/serial.sh b/packer/alpine-linux/scripts/serial.sh index 7d99fb4..f9cd3c4 100644 --- a/packer/alpine-linux/scripts/serial.sh +++ b/packer/alpine-linux/scripts/serial.sh @@ -2,4 +2,4 @@ sed -i 's/\(APPEND .*\)/\1 console=ttyS0/' /boot/extlinux.conf # autologin on serial console -sed -i 's/^#* *ttyS0.*/ttyS0::respawn:\/bin\/login -f root/' /etc/inittab +sed -i 's/^ttyS0.*/ttyS0::respawn:\/bin\/login -f root/' /etc/inittab diff --git a/packer/alpine-linux/scripts/setup.sh b/packer/alpine-linux/scripts/setup.sh index 5d22b2e..015ea07 100644 --- a/packer/alpine-linux/scripts/setup.sh +++ b/packer/alpine-linux/scripts/setup.sh @@ -1,6 +1,27 @@ # install additional packages apk add nano busybox-extras +# create .profile +cat > /root/.profile << 'EOF' +# ~/.profile: executed by Bourne-compatible login shells. + +# reset terminal modes +[ -t 1 ] && printf '\e[?5l\e[?7h\e[?8h' + +if [ "$BASH" ]; then + if [ -f ~/.bashrc ]; then + . ~/.bashrc + fi +fi + +mesg n || true +EOF + +find /home -type d -mindepth 1 -maxdepth 1 | while read -r home; do + cp -p /root/.profile "$home/" + chown $(stat -c '%u:%g' "$home") "$home/.profile" +done + # network configuration cat > /etc/network/interfaces << EOF #