From 0d1e53667f2bee5be091f0beb533bd5bf3b9f8f0 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 12 Feb 2018 01:25:21 +0000 Subject: [PATCH] clean up imagesync, fix build --- build.sh | 2 +- imagesync.sh | 92 +++++++++++++++++++++++++++++++++++++++------------- qemu.sh | 6 ++-- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/build.sh b/build.sh index a8e346c..feef0a4 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,3 @@ #!/bin/sh -docker build --no-cache -t initramfs:debian . +docker build -t initramfs:debian . docker run --rm -v "$PWD:/artifacts" initramfs:debian sh -c 'cp /boot/vmlinuz-* /artifacts/vmlinuz && cp /tmp/initrd.gz /artifacts' diff --git a/imagesync.sh b/imagesync.sh index e2e0549..9270e67 100755 --- a/imagesync.sh +++ b/imagesync.sh @@ -1,30 +1,45 @@ #!/bin/sh -PREREQ="" -prereqs() -{ - echo "$PREREQ" - . /usr/share/initramfs-tools/hook-functions - copy_exec /usr/bin/aria2c - copy_exec /sbin/sfdisk - copy_exec /sbin/mke2fs -} case $1 in -# get pre-requisites prereqs) - prereqs + ## + # GET EXECUTED WHEN BUILDING INITRAMFS + # + . /usr/share/initramfs-tools/hook-functions + copy_exec /usr/bin/aria2c + copy_exec /sbin/sfdisk + copy_exec /sbin/mke2fs + copy_file cert /etc/ssl/certs/ca-certificates.crt exit 0 ;; esac +## +# FUNCTION DEFINITIONS +## +print_waiting() { + echo -en "\033[36m${1}... \033[0m" +} + +print_done() { + echo -e "\033[32mdone.\033[0m" +} + +## +# HARDCODED DISK PARAMETERS +## disk=/dev/sda - size_part_1=$((3072 * 1024 * 1024 / 512)) -sfdisk /dev/sda << PARTTABLE +## +# PARTITIONING OF DISK +## + +print_waiting "Partitioning disk" +sfdisk -q /dev/sda << PARTTABLE label: dos label-id: 0xdeadbeef device: /dev/sda @@ -32,20 +47,53 @@ unit: sectors /dev/sda1 : start= 2048, size= $size_part_1, type=83 PARTTABLE +print_done -mke2fs -F -t ext4 ${disk}1 +print_waiting "Creating Filesystem" +mke2fs -q -F -t ext4 ${disk}1 +print_done -mkdir -p /tmp_root -mount -t ext4 ${disk}1 /tmp_root -ls -lah /dev/sd* /tmp_root - -ip a +## +# TEMPORARY NETWORK CONFIG (only for qemu) +## +print_waiting "Setting up temporary network config" ip addr add 10.2.2.2/24 dev ens3 ip link set ens3 up -#ping 10.2.2.1 +print_done -aria2c -V --check-certificate=false --seed-ratio=0 'http://10.2.2.1/image.torrent' +## +# MOUNT TEMPORARY ROOTFS +## -sleep 3600 +print_waiting "Mounting temporary root filesystem" +mkdir -p /tmp_root +mount -t ext4 ${disk}1 /tmp_root +cd /tmp_root +print_done +## +# DOWNLOAD FS IMAGE +## + +print_waiting "Downloading root filesystem image" +# (DHT error seems normal, because it is aria2c’s first run) + +# --check-integrity: verify downloaded file and do not complain about missing controll file +# --seed-time=0: do not wait until ratio 1, we seed when we’re booted +# --quiet: no console output +aria2c --check-integrity --seed-time=0 --quiet=true 'http://10.2.2.1:8081/image.torrent' +print_done + +## +# UNMOUNT TEMPORARY ROOTFS +## + +print_waiting "Unmounting temporary root filesystem" +cd / +umount /tmp_root +print_done + +print_waiting "Waiting for implementation of more features" + +while sleep 3600;do sleep 3600;done diff --git a/qemu.sh b/qemu.sh index 6d5f8bc..cb8e43a 100755 --- a/qemu.sh +++ b/qemu.sh @@ -12,11 +12,13 @@ sudo ip addr add 10.2.2.1/24 dev brtstsync sudo ip link set taptstsync up sudo ip link set brtstsync up +# -append "root=/dev/sda1 quiet" \ + qemu-system-x86_64 \ -kernel vmlinuz \ -initrd initrd.gz \ - -drive format=raw,if=scsi,file=pladde.img \ - -append root=/dev/sda1 \ + -drive format=raw,file=pladde.img \ + -append "root=/dev/sda1" \ -m 1G \ -net nic \ -net tap,ifname=$ifname_tap,script=no,downscript=no