From d2083c622d9184a674e7c615fd51bc6e388b6d2e Mon Sep 17 00:00:00 2001 From: toby Date: Mon, 24 Sep 2018 21:02:44 +0000 Subject: [PATCH] re-structuring everything to make it look more like a package that one can build, also adding syslinux pxe configs and cleanup --- .drone.yml | 3 +- create_pxeinitrd.sh | 174 ++++++++++--------------------------- debian/compat | 1 + debian/control | 15 ++++ debian/rules | 25 ++++++ debian/wit-pxeboot.install | 5 ++ files/debcore | 9 ++ files/install | 9 ++ files/localboot | 8 ++ 9 files changed, 119 insertions(+), 130 deletions(-) create mode 100644 debian/compat create mode 100644 debian/control create mode 100755 debian/rules create mode 100644 debian/wit-pxeboot.install create mode 100644 files/debcore create mode 100644 files/install create mode 100644 files/localboot diff --git a/.drone.yml b/.drone.yml index ae2ca18..efb9bcb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,9 +3,8 @@ pipeline: image: registry.v1.cloud.wit.com/toby/packager:1.3 commands: - export DEBNAME=wit-pxeboot - - export RESULT_DIR=/tmp/result + - echo "$DEBNAME (1.0.$(date +%Y.%m.%d.%H.%M)) unstable; urgency=low\n\n$(git log --format=" * %s")\n\n -- wit $(date -R)" >debian/changelog - ./create_pxeinitrd.sh - - cd $RESULT_DIR - dpkg-buildpackage --no-sign - ls -lha ../$DEBNAME_*_all.deb - echo "$SSH_KEY" >/tmp/id_rsa diff --git a/create_pxeinitrd.sh b/create_pxeinitrd.sh index f234392..4dd507b 100755 --- a/create_pxeinitrd.sh +++ b/create_pxeinitrd.sh @@ -1,15 +1,13 @@ #!/bin/bash set -Eeuxo pipefail -DEBNAME=${DEBNAME:=wit-pxeboot} - SIZE=10000 HOSTNAME=localhost RELEASE=unstable -TMP_DIR=$(mktemp -d) +TMP_DIR=$PWD MNT_DIR=$TMP_DIR/newroot -RESULT_DIR=${RESULT_DIR:=/tmp/result} +RESULT_DIR=${RESULT_DIR:=$TMP_DIR/files} # Configs overwritable via environment variables @@ -19,12 +17,7 @@ MIRROR=${MIRROR:="https://mirrors.wit.com/debian"} ARCH=${ARCH:=amd64} -clean_debian() { - [ "$TMP_DIR" != "" ] && rm -r $TMP_DIR -} - fail() { - clean_debian echo "" echo "FAILED: $1" exit 1 @@ -167,73 +160,6 @@ chroot $MNT_DIR systemctl enable start-me-up || fail "failed to enable start-me- -############### -## deb build ## -############### - - -mkdir -p $RESULT_DIR/debian -echo -e "$DEBNAME (1.0.$(date +%Y.%m.%d.%H.%M)) unstable; urgency=low\n\n$(git log --format=" * %s")\n\n -- wit $(date -R)" >$RESULT_DIR/debian/changelog - -echo "11" >$RESULT_DIR/debian/compat - -cat <$RESULT_DIR/debian/$DEBNAME.install -./vmlinuz /srv/tftp/wit-pxeboot/ -./initramfs.gz /srv/tftp/wit-pxeboot/ -EOF - - -cat <$RESULT_DIR/debian/control -Source: $DEBNAME -Section: unknown -Priority: optional -Maintainer: wit -Build-Depends: debhelper (>= 11) -Standards-Version: 4.1.3 -Homepage: http://www.wit.com - -Package: $DEBNAME -Architecture: all -Depends: \${misc:Depends}, tftpd-hpa -Description: kernel and initrd to pxeboot debcore - kernel and initrd to boot a pxe image easily - it also includes a rootfs to quickly kickstart - a local install -EOF - - -cat <<"EOF" >$RESULT_DIR/debian/rules -#!/usr/bin/make -f -# See debhelper(7) (uncomment to enable) -# output every command that modifies files on the build system. -#export DH_VERBOSE = 1 - - -# see FEATURE AREAS in dpkg-buildflags(1) -#export DEB_BUILD_MAINT_OPTIONS = hardening=+all - -# see ENVIRONMENT in dpkg-buildflags(1) -# package maintainers to append CFLAGS -#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic -# package maintainers to append LDFLAGS -#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed - - -%: - dh $@ - - -# dh_make generated override targets -# This is example for Cmake (See https://bugs.debian.org/641051 ) -#override_dh_auto_configure: -# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) - -EOF - - - - - ################## ## build initrd ## @@ -244,69 +170,61 @@ mkdir -p $TMP_DIR/initramfs/bin wget -O $TMP_DIR/initramfs/bin/busybox https://www.busybox.net/downloads/binaries/1.26.1-defconfig-multiarch/busybox-x86_64 chmod +x $TMP_DIR/initramfs/bin/busybox -cat > $TMP_DIR/initramfs/init << EOF -#!/bin/busybox sh - -# Dump to sh if something fails -error() { - echo "Jumping into the shell..." - setsid cttyhack sh -} - -# Populate /bin with binaries from busybox -/bin/busybox --install /bin - -mkdir -p /proc -mount -t proc proc /proc - -mkdir -p /sys -mount -t sysfs sysfs /sys - -mkdir -p /sys/dev -mkdir -p /var/run -mkdir -p /dev - -mkdir -p /dev/pts -mount -t devpts devpts /dev/pts - -# Populate /dev -echo /bin/mdev > /proc/sys/kernel/hotplug -mdev -s - -mkdir -p /newroot -mount -t tmpfs -o size=${SIZE}m tmpfs /newroot || error - -echo "Extracting rootfs... " -xz -d -c -f rootfs.tar.xz | tar -x -f - -C /newroot || error - -mount --move /sys /newroot/sys -mount --move /proc /newroot/proc -mount --move /dev /newroot/dev - -exec switch_root /newroot /sbin/init || error +cat <<-"EOF" >$TMP_DIR/initramfs/init + #!/bin/busybox sh + + # Dump to sh if something fails + error() { + echo "Jumping into the shell..." + setsid cttyhack sh + } + + # Populate /bin with binaries from busybox + /bin/busybox --install /bin + + mkdir -p /proc + mount -t proc proc /proc + + mkdir -p /sys + mount -t sysfs sysfs /sys + + mkdir -p /sys/dev + mkdir -p /var/run + mkdir -p /dev + + mkdir -p /dev/pts + mount -t devpts devpts /dev/pts + + # Populate /dev + echo /bin/mdev > /proc/sys/kernel/hotplug + mdev -s + + mkdir -p /newroot + mount -t tmpfs -o size=${SIZE}m tmpfs /newroot || error + + echo "Extracting rootfs... " + xz -d -c -f rootfs.tar.xz | tar -x -f - -C /newroot || error + + mount --move /sys /newroot/sys + mount --move /proc /newroot/proc + mount --move /dev /newroot/dev + + exec switch_root /newroot /sbin/init || error EOF chmod +x $TMP_DIR/initramfs/init -cd $TMP_DIR/newroot -tar cJf $TMP_DIR/initramfs/rootfs.tar.xz . - -cd $TMP_DIR/initramfs -mkdir -p $RESULT_DIR -find . -print0 | cpio --null -ov --format=newc | gzip -9 > $RESULT_DIR/initramfs.gz +tar -cJf $TMP_DIR/initramfs/rootfs.tar.xz -C $TMP_DIR/newroot . cp $TMP_DIR/newroot/boot/vmlinuz-* $RESULT_DIR/vmlinuz +cd $TMP_DIR/initramfs +find . -print0 | cpio --null -ov --format=newc | gzip -9 > $RESULT_DIR/initramfs.gz + ls -la $RESULT_DIR/ -############# -## cleanup ## -############# - - -clean_debian exit 0 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b4de394 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +11 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..eb02734 --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: wit-pxeboot +Section: unknown +Priority: optional +Maintainer: wit +Build-Depends: debhelper (>= 11) +Standards-Version: 4.1.3 +Homepage: http://www.wit.com + +Package: wit-pxeboot +Architecture: all +Depends: ${misc:Depends}, tftpd-hpa +Description: kernel and initrd to pxeboot debcore + kernel and initrd to boot a pxe image easily + it also includes a rootfs to quickly kickstart + a local install diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..e1c367c --- /dev/null +++ b/debian/rules @@ -0,0 +1,25 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) + diff --git a/debian/wit-pxeboot.install b/debian/wit-pxeboot.install new file mode 100644 index 0000000..8fe0e7b --- /dev/null +++ b/debian/wit-pxeboot.install @@ -0,0 +1,5 @@ +files/vmlinuz /srv/tftp/wit-pxeboot/ +files/initramfs.gz /srv/tftp/wit-pxeboot/ +files/debcore /srv/tftp/wit-pxeconfig/ +files/install /srv/tftp/wit-pxeconfig/ +files/localboot /srv/tftp/wit-pxeconfig/ diff --git a/files/debcore b/files/debcore new file mode 100644 index 0000000..cb31bc6 --- /dev/null +++ b/files/debcore @@ -0,0 +1,9 @@ +serial 1 115200 +prompt 1 +timeout 100 +default debcore + + +label debcore + kernel wit-pxeboot/vmlinuz + append initrd=wit-pxeboot/initramfs.gz acpi=off console=tty0 console=ttyS1,115200n8 --- diff --git a/files/install b/files/install new file mode 100644 index 0000000..b255d26 --- /dev/null +++ b/files/install @@ -0,0 +1,9 @@ +serial 1 115200 +prompt 1 +timeout 100 +default install + + +label install + kernel wit-pxeboot/vmlinuz + append initrd=wit-pxeboot/initramfs.gz acpi=off console=tty0 console=ttyS1,115200n8 execstartup='sleep 60; /root/install.sh wit-network-config && echo -e "======\nSUCCESS\n======" || exit 1' --- diff --git a/files/localboot b/files/localboot new file mode 100644 index 0000000..6409da8 --- /dev/null +++ b/files/localboot @@ -0,0 +1,8 @@ +serial 1 115200 +prompt 1 +timeout 100 +default local + + +label local + LOCALBOOT -1