From 30a7e86bd788f900119f4becadf211884e060efc Mon Sep 17 00:00:00 2001 From: Bernhard Ehlers Date: Thu, 21 Jan 2016 11:05:02 +0100 Subject: [PATCH] move NETem packer files to tinycore-linux --- appliances/netem.gns3a | 16 ++--- packer/NETem/NETem.json | 60 ------------------- packer/NETem/scripts/hd-install.sh | 43 ------------- packer/NETem/scripts/post_setup.sh | 9 --- packer/NETem/scripts/serial.sh | 21 ------- packer/NETem/uploads/boot_script | 26 -------- packer/tinycore-linux/NETem.json | 5 ++ packer/tinycore-linux/README.rst | 10 ++++ packer/tinycore-linux/core-linux.json | 2 +- .../http/NETem}/netem-conf.py | 0 .../scripts/NETem.sh | 50 +++++++++++----- 11 files changed, 59 insertions(+), 183 deletions(-) delete mode 100644 packer/NETem/NETem.json delete mode 100644 packer/NETem/scripts/hd-install.sh delete mode 100644 packer/NETem/scripts/post_setup.sh delete mode 100644 packer/NETem/scripts/serial.sh delete mode 100644 packer/NETem/uploads/boot_script create mode 100644 packer/tinycore-linux/NETem.json rename packer/{NETem/uploads => tinycore-linux/http/NETem}/netem-conf.py (100%) rename packer/{NETem => tinycore-linux}/scripts/NETem.sh (76%) diff --git a/appliances/netem.gns3a b/appliances/netem.gns3a index f5439fb..b9afb71 100644 --- a/appliances/netem.gns3a +++ b/appliances/netem.gns3a @@ -23,19 +23,19 @@ }, "images": [ { - "filename": "NETem-v3.qcow2", - "version": "0.3", - "md5sum": "88297839b5f014ac15a434053f51690f", - "filesize": 23461888, - "download_url": "http://bernhard-ehlers.de/projects/netem/NETem-v3.qcow2", - "direct_download_url": "http://bernhard-ehlers.de/projects/netem/NETem-v3.qcow2" + "filename": "NETem-v4.qcow2", + "version": "0.4", + "md5sum": "e678698c97804901c7a53f6b68c8b861", + "filesize": 26476544, + "download_url": "http://bernhard-ehlers.de/projects/netem/index.html", + "direct_download_url": "http://bernhard-ehlers.de/projects/netem/NETem-v4.qcow2" } ], "versions": [ { - "name": "0.3", + "name": "0.4", "images": { - "hda_disk_image": "NETem-v3.qcow2" + "hda_disk_image": "NETem-v4.qcow2" } } ] diff --git a/packer/NETem/NETem.json b/packer/NETem/NETem.json deleted file mode 100644 index 571d10c..0000000 --- a/packer/NETem/NETem.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "variables": { - "tc_iso_url": "http://distro.ibiblio.org/tinycorelinux/6.x/x86/archive/6.4/Core-6.4.iso", - "tc_iso_checksum": "c8e04e26de234e5528e6eac8ecb1bdda", - "vm_name": "NETem.qcow2", - "setup_script": "NETem.sh", - "upload_dir": "uploads", - "disk_size": "32" - }, - "builders": [ - { - "type": "qemu", - "iso_url": "{{user `tc_iso_url`}}", - "iso_checksum": "{{user `tc_iso_checksum`}}", - "iso_checksum_type": "md5", - "shutdown_command": "sudo poweroff", - "format": "qcow2", - "headless": false, - "ssh_username": "gns3", - "ssh_password": "gns3", - "accelerator": "none", - "vm_name": "{{user `vm_name`}}", - "disk_interface": "ide", - "disk_size": "{{user `disk_size`}}", - "net_device": "e1000", - "http_directory": "http", - "boot_wait": "5s", - "boot_command": [ - "mc user=gns3", - "sudo passwd gns3gns3gns3", - "tce-load -wi openssh", - "cd /usr/local/etc/ssh; [ -f sshd_config.example ] && sudo cp -a sshd_config.example sshd_config; cd", - "sudo /usr/local/etc/init.d/openssh start" - ] - } - ], - "provisioners": [ - { - "type": "shell", - "script": "scripts/hd-install.sh" - }, - { - "type": "shell", - "script": "scripts/serial.sh" - }, - { - "type": "file", - "source": "{{user `upload_dir`}}/", - "destination": "/tmp" - }, - { - "type": "shell", - "script": "scripts/{{user `setup_script`}}" - }, - { - "type": "shell", - "script": "scripts/post_setup.sh" - } - ] -} diff --git a/packer/NETem/scripts/hd-install.sh b/packer/NETem/scripts/hd-install.sh deleted file mode 100644 index 652e9cb..0000000 --- a/packer/NETem/scripts/hd-install.sh +++ /dev/null @@ -1,43 +0,0 @@ -# Install tinycore on harddisk - -set -x - -# format harddisk -echo -e 'n\np\n1\n\n\na\n1\nw' | sudo fdisk -H16 -S32 /dev/sda -sudo mkfs.ext2 /dev/sda1 - -# copy system to harddisk -sudo mkdir /mnt/sda1 -sudo mount /dev/sda1 /mnt/sda1 -sudo mount /mnt/sr0 -sudo cp -a /mnt/sr0/boot /mnt/sda1/ -sudo umount /mnt/sr0 - -# modify bootloader config -sudo mv /mnt/sda1/boot/isolinux /mnt/sda1/boot/extlinux -cd /mnt/sda1/boot/extlinux -sudo rm boot.cat isolinux.bin -sudo mv isolinux.cfg extlinux.conf -sudo sed -i -e '/append / s/$/ user=gns3/' -e 's/timeout .*/timeout 1/' extlinux.conf -cd - -# make disk bootable -tce-load -wi syslinux -sudo sh -c 'cat /usr/local/share/syslinux/mbr.bin > /dev/sda' -sudo /usr/local/sbin/extlinux --install /mnt/sda1/boot/extlinux - -# create extensions directory -sudo mkdir /mnt/sda1/tce -sudo chgrp staff /mnt/sda1/tce -sudo chmod 775 /mnt/sda1/tce - -# change tcedir to harddisk -mv /etc/sysconfig/tcedir /etc/sysconfig/tcedir.bak -ln -s /mnt/sda1/tce /etc/sysconfig/tcedir -rm -rf /usr/local/tce.installed/* - -# base system modifications -sudo sed -i -e '/^\/opt\/bootlocal/ i' /opt/bootsync.sh -echo -e "\nusername 'gns3', password 'gns3'\n" >> /etc/issue -echo 'etc/issue' >> /opt/.filetool.lst -echo 'etc/shadow' >> /opt/.filetool.lst diff --git a/packer/NETem/scripts/post_setup.sh b/packer/NETem/scripts/post_setup.sh deleted file mode 100644 index f19e0d0..0000000 --- a/packer/NETem/scripts/post_setup.sh +++ /dev/null @@ -1,9 +0,0 @@ -# post-installation script -set -x - -# save changes -rm -f .ash_history -filetool.sh -b sda1 - -# write 0, not really necessary -#sudo dd if=/dev/zero of=/mnt/sda1/zero ; sudo rm -f /mnt/sda1/zero diff --git a/packer/NETem/scripts/serial.sh b/packer/NETem/scripts/serial.sh deleted file mode 100644 index 8284fd9..0000000 --- a/packer/NETem/scripts/serial.sh +++ /dev/null @@ -1,21 +0,0 @@ -# Add serial console support - -set -x - -# Boot configuration -# Serial interface is secondary console, the vga console remains main console -# To change that, swap the two 'console=' boot parameter -sudo sed -i -e '1 i serial 0 38400' -e '/label microcore/,/append / s/\(append .*\)/\1 console=ttyS0,38400 console=tty0/' /mnt/sda1/boot/extlinux/extlinux.conf - -# /etc/inittab -sudo sed -i -e '/tty6/ a ttyS0::respawn:/sbin/getty 38400 ttyS0 xterm' /etc/inittab - -# /etc/securetty -sudo sed -i -e 's/^# *ttyS0/ttyS0/' /etc/securetty - -# reload inittab on startup -sudo sed -i -e '/^\/opt\/bootlocal/ i # reload inittab' -e '/^\/opt\/bootlocal/ i kill -HUP 1' -e '/^\/opt\/bootlocal/ i' /opt/bootsync.sh - -# add modified files to backup list -echo 'etc/inittab' >> /opt/.filetool.lst -echo 'etc/securetty' >> /opt/.filetool.lst diff --git a/packer/NETem/uploads/boot_script b/packer/NETem/uploads/boot_script deleted file mode 100644 index 93a9378..0000000 --- a/packer/NETem/uploads/boot_script +++ /dev/null @@ -1,26 +0,0 @@ -. /etc/init.d/tc-functions - -# default LANG=C.UTF-8 -[ ! -f /etc/sysconfig/language ] || [ "`cat /etc/sysconfig/language`" = "LANG=C" ] && \ - echo "LANG=C.UTF-8" > /etc/sysconfig/language - -# Configure network interfaces only when boot parameter "nodhcp" is used -if grep -q -w nodhcp /proc/cmdline; then - echo -en "${BLUE}Configuring network interfaces... ${NORMAL}" - - # This waits until all devices have registered - /sbin/udevadm settle --timeout=10 - - ip link add name br0 type bridge - ip link set dev eth0 promisc on - ip link set dev eth0 mtu 2000 - ip link set dev eth0 up - ip link set dev eth0 master br0 - ip link set dev eth1 promisc on - ip link set dev eth1 mtu 2000 - ip link set dev eth1 up - ip link set dev eth1 master br0 - ip link set dev br0 up - - echo -e "${GREEN}Done.${NORMAL}" -fi diff --git a/packer/tinycore-linux/NETem.json b/packer/tinycore-linux/NETem.json new file mode 100644 index 0000000..14deab2 --- /dev/null +++ b/packer/tinycore-linux/NETem.json @@ -0,0 +1,5 @@ +{ + "vm_name": "NETem.qcow2", + "setup_script": "NETem.sh", + "disk_size": "32" +} diff --git a/packer/tinycore-linux/README.rst b/packer/tinycore-linux/README.rst index 4d0a9dc..67f8869 100644 --- a/packer/tinycore-linux/README.rst +++ b/packer/tinycore-linux/README.rst @@ -47,6 +47,16 @@ An appliance for simulating a domestic modem. eth0 as a dhcp and eth1 should be packer build -var-file=core-linux-internet.json core-linux.json +NETem +'''''' + +A build of Core with the NETem (Network link emulator) preinstalled. + +.. code:: bash + + packer build -var-file=NETem.json core-linux.json + + Tiny Core Linux installation **************************** diff --git a/packer/tinycore-linux/core-linux.json b/packer/tinycore-linux/core-linux.json index d1fe7a2..ef2b8cf 100644 --- a/packer/tinycore-linux/core-linux.json +++ b/packer/tinycore-linux/core-linux.json @@ -25,7 +25,7 @@ "http_directory": "http", "boot_wait": "5s", "boot_command": [ - "mc user=gns3", + "mc user=gns3 http={{ .HTTPIP }}:{{ .HTTPPort }}", "sudo udhcpc", "sudo passwd gns3gns3gns3", "tce-load -wi openssh", diff --git a/packer/NETem/uploads/netem-conf.py b/packer/tinycore-linux/http/NETem/netem-conf.py similarity index 100% rename from packer/NETem/uploads/netem-conf.py rename to packer/tinycore-linux/http/NETem/netem-conf.py diff --git a/packer/NETem/scripts/NETem.sh b/packer/tinycore-linux/scripts/NETem.sh similarity index 76% rename from packer/NETem/scripts/NETem.sh rename to packer/tinycore-linux/scripts/NETem.sh index 38271bc..b208b4d 100644 --- a/packer/NETem/scripts/NETem.sh +++ b/packer/tinycore-linux/scripts/NETem.sh @@ -1,10 +1,6 @@ set -e set -x -# get TinyCore mirror -. /etc/init.d/tc-functions -getMirror - # TCE directory back to ramdisk mv /etc/sysconfig/tcedir /etc/sysconfig/tcedir.hd ln -s /tmp/tce /etc/sysconfig/tcedir @@ -66,21 +62,14 @@ echo "net-bridging-$KERNEL.tcz" >> /etc/sysconfig/tcedir/onboot.lst tce-load -w net-sched-$KERNEL echo "net-sched-$KERNEL.tcz" >> /etc/sysconfig/tcedir/onboot.lst -# iproute2 without db library -# Bug in TinyCore 6.x, which makes arpd non-working: -# There is a mismatch of the library version between arpd and the db library. -# Therefore loading the db library has no advantage, it uses only disk space. -wget $MIRROR/iproute2.tcz -wget $MIRROR/iproute2.tcz.md5.txt -cp -p iproute2.tcz* /etc/sysconfig/tcedir/optional/ -echo 'iproute2.tcz' >> /etc/sysconfig/tcedir/onboot.lst - # clean up build environment cd .. rm -r build # NETem menu system -mv /tmp/netem-conf.py . +. /etc/init.d/tc-functions +http=http://`getbootparam http` +wget $http/NETem/netem-conf.py chmod +x netem-conf.py # autologin on serial console @@ -103,10 +92,41 @@ EOF sudo sed -i -e '/label microcore/,/append / s/\(append .*\)/\1 nodhcp/' /mnt/sda1/boot/extlinux/extlinux.conf # set locale and configure network at startup +sed -i -e '3,$ d' /opt/bootlocal.sh sed -n -e '1,/^\/opt\/bootlocal/ p' /opt/bootsync.sh | head -n -1 > /tmp/bootsync.head sed -n -e '/^\/opt\/bootlocal/,$ p' /opt/bootsync.sh > /tmp/bootsync.tail cat /tmp/bootsync.head > /opt/bootsync.sh -cat /tmp/boot_script >> /opt/bootsync.sh; echo >> /opt/bootsync.sh +cat >> /opt/bootsync.sh <<'EOF' +. /etc/init.d/tc-functions + +# default LANG=C.UTF-8 +[ ! -f /etc/sysconfig/language ] || [ "`cat /etc/sysconfig/language`" = "LANG=C" ] && \ + echo "LANG=C.UTF-8" > /etc/sysconfig/language + +# Configure network interfaces only when boot parameter "nodhcp" is used +if grep -q -w nodhcp /proc/cmdline; then + echo -en "${BLUE}Configuring network interfaces... ${NORMAL}" + + # This waits until all devices have registered + /sbin/udevadm settle --timeout=10 + + ip link add name br0 type bridge + sysctl -q -w net.ipv6.conf.br0.disable_ipv6=1 + sysctl -q -w net.ipv6.conf.eth0.disable_ipv6=1 + ip link set dev eth0 promisc on + ip link set dev eth0 mtu 2000 + ip link set dev eth0 up + ip link set dev eth0 master br0 + sysctl -q -w net.ipv6.conf.eth1.disable_ipv6=1 + ip link set dev eth1 promisc on + ip link set dev eth1 mtu 2000 + ip link set dev eth1 up + ip link set dev eth1 master br0 + ip link set dev br0 up + + echo -e "${GREEN}Done.${NORMAL}" +fi +EOF cat /tmp/bootsync.tail >> /opt/bootsync.sh # Done