From c8a729246154420f1f8dc04fd2fb0370ab546e1a Mon Sep 17 00:00:00 2001 From: Johan Gunnarsson Date: Sun, 12 May 2019 23:46:20 +0200 Subject: [PATCH] Add support for building Ubuntu images --- .../post-2nd-stage-files/etc/hostname | 1 - .../initramfs/post-update.d/zz-update-uimg | 6 ++- .../initramfs/post-update.d/zz-update-uimg | 6 ++- Dockerfile | 1 + debians.csv | 26 +++++++---- dockerfiles/Dockerfile.arm32v7 | 1 + dockerfiles/Dockerfile.arm32v7-on-amd64 | 1 + dockerfiles/Dockerfile.arm64v8 | 1 + dockerfiles/Dockerfile.arm64v8-on-amd64 | 1 + metascripts/rebuild-debians | 8 ++-- scripts/build-debian | 43 ++++++++++++++----- 11 files changed, 69 insertions(+), 26 deletions(-) delete mode 100755 2nd-stage-files/post-2nd-stage-files/etc/hostname diff --git a/2nd-stage-files/post-2nd-stage-files/etc/hostname b/2nd-stage-files/post-2nd-stage-files/etc/hostname deleted file mode 100755 index 2dee175..0000000 --- a/2nd-stage-files/post-2nd-stage-files/etc/hostname +++ /dev/null @@ -1 +0,0 @@ -debian diff --git a/2nd-stage-files/pre-2nd-stage-files-arm64/etc/initramfs/post-update.d/zz-update-uimg b/2nd-stage-files/pre-2nd-stage-files-arm64/etc/initramfs/post-update.d/zz-update-uimg index 046fa70..b3d2841 100755 --- a/2nd-stage-files/pre-2nd-stage-files-arm64/etc/initramfs/post-update.d/zz-update-uimg +++ b/2nd-stage-files/pre-2nd-stage-files-arm64/etc/initramfs/post-update.d/zz-update-uimg @@ -7,12 +7,16 @@ ABI="${1}" # Create U-Boot ramdisk image mkimage -A arm64 -T ramdisk -C none -d "/boot/initrd.img-${ABI}" "/boot/initrd.uimg-${ABI}" +FDT=/usr/lib/linux +[ -d "/lib/firmware/${ABI}/device-tree" ] && FDT="/lib/firmware/${ABI}/device-tree" +[ -d "/usr/lib/linux-image-${ABI}" ] && FDT="/usr/lib/linux-image-${ABI}" + # Create U-Boot boot script cat << EOF > /boot/boot.cmd mmc dev 0 ext4load mmc 0:2 \${kernel_addr_r} /boot/vmlinuz-${ABI} ext4load mmc 0:2 \${ramdisk_addr_r} /boot/initrd.uimg-${ABI} -ext4load mmc 0:2 \${fdt_addr_r} /usr/lib/linux-image-${ABI}/\${fdtfile} +ext4load mmc 0:2 \${fdt_addr_r} ${FDT}/\${fdtfile} setenv bootargs "root=/dev/mmcblk0p2 rw rootwait" booti \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r} EOF diff --git a/2nd-stage-files/pre-2nd-stage-files-armhf/etc/initramfs/post-update.d/zz-update-uimg b/2nd-stage-files/pre-2nd-stage-files-armhf/etc/initramfs/post-update.d/zz-update-uimg index d1e26c9..e192505 100755 --- a/2nd-stage-files/pre-2nd-stage-files-armhf/etc/initramfs/post-update.d/zz-update-uimg +++ b/2nd-stage-files/pre-2nd-stage-files-armhf/etc/initramfs/post-update.d/zz-update-uimg @@ -7,12 +7,16 @@ ABI="${1}" # Create U-Boot ramdisk image mkimage -A arm -T ramdisk -C none -d "/boot/initrd.img-${ABI}" "/boot/initrd.uimg-${ABI}" +FDT=/usr/lib/linux +[ -d "/lib/firmware/${ABI}/device-tree" ] && FDT="/lib/firmware/${ABI}/device-tree" +[ -d "/usr/lib/linux-image-${ABI}" ] && FDT="/usr/lib/linux-image-${ABI}" + # Create U-Boot boot script cat << EOF > /boot/boot.cmd mmc dev 0 ext4load mmc 0:2 \${kernel_addr_r} /boot/vmlinuz-${ABI} ext4load mmc 0:2 \${ramdisk_addr_r} /boot/initrd.uimg-${ABI} -ext4load mmc 0:2 \${fdt_addr_r} /usr/lib/linux-image-${ABI}/\${fdtfile} +ext4load mmc 0:2 \${fdt_addr_r} ${FDT}/\${fdtfile} setenv bootargs "root=/dev/mmcblk0p2 rw rootwait" bootz \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r} EOF diff --git a/Dockerfile b/Dockerfile index 203e7c5..0a7359c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ RUN apt-get update && \ --no-install-recommends \ install debootstrap \ debian-archive-keyring \ + ubuntu-archive-keyring \ ca-certificates \ qemu-user-static \ device-tree-compiler \ diff --git a/debians.csv b/debians.csv index c983075..435ceeb 100644 --- a/debians.csv +++ b/debians.csv @@ -1,11 +1,19 @@ -# Stable -stretch,armhf -stretch,arm64 +# Debian Stable +debian,stretch,armhf +debian,stretch,arm64 -# Testing -buster,armhf -buster,arm64 +# Debian Testing +debian,buster,armhf +debian,buster,arm64 -# Unstable -sid,armhf -sid,arm64 +# Debian Unstable +debian,sid,armhf +debian,sid,arm64 + +# Ubuntu 18.04 (LTS) +ubuntu,bionic,armhf +ubuntu,bionic,arm64 + +# Ubuntu 19.04 +ubuntu,disco,armhf +ubuntu,disco,arm64 diff --git a/dockerfiles/Dockerfile.arm32v7 b/dockerfiles/Dockerfile.arm32v7 index 2915074..fdddeb7 100644 --- a/dockerfiles/Dockerfile.arm32v7 +++ b/dockerfiles/Dockerfile.arm32v7 @@ -6,6 +6,7 @@ RUN apt-get update && \ --no-install-recommends \ install debootstrap \ debian-archive-keyring \ + ubuntu-archive-keyring \ ca-certificates \ device-tree-compiler \ gcc \ diff --git a/dockerfiles/Dockerfile.arm32v7-on-amd64 b/dockerfiles/Dockerfile.arm32v7-on-amd64 index d52146e..ad74505 100644 --- a/dockerfiles/Dockerfile.arm32v7-on-amd64 +++ b/dockerfiles/Dockerfile.arm32v7-on-amd64 @@ -16,6 +16,7 @@ RUN apt-get update && \ --no-install-recommends \ install debootstrap \ debian-archive-keyring \ + ubuntu-archive-keyring \ ca-certificates \ device-tree-compiler \ gcc \ diff --git a/dockerfiles/Dockerfile.arm64v8 b/dockerfiles/Dockerfile.arm64v8 index c73a2ff..7607ec9 100644 --- a/dockerfiles/Dockerfile.arm64v8 +++ b/dockerfiles/Dockerfile.arm64v8 @@ -6,6 +6,7 @@ RUN apt-get update && \ --no-install-recommends \ install debootstrap \ debian-archive-keyring \ + ubuntu-archive-keyring \ ca-certificates \ device-tree-compiler \ gcc \ diff --git a/dockerfiles/Dockerfile.arm64v8-on-amd64 b/dockerfiles/Dockerfile.arm64v8-on-amd64 index 5a225a7..7ba47f0 100644 --- a/dockerfiles/Dockerfile.arm64v8-on-amd64 +++ b/dockerfiles/Dockerfile.arm64v8-on-amd64 @@ -16,6 +16,7 @@ RUN apt-get update && \ --no-install-recommends \ install debootstrap \ debian-archive-keyring \ + ubuntu-archive-keyring \ ca-certificates \ device-tree-compiler \ gcc \ diff --git a/metascripts/rebuild-debians b/metascripts/rebuild-debians index a0da5dc..27bde39 100755 --- a/metascripts/rebuild-debians +++ b/metascripts/rebuild-debians @@ -12,14 +12,14 @@ mkdir -p /tmp/debimg/log || exit D=$(mktemp -d -p "${LOG_DIR}" rebuild-debians-XXXXXX) IFS=, -grep -vE "^#|^\s*$" debians.csv | while read DIST ARCH _ +grep -vE "^#|^\s*$" debians.csv | while read OS DIST ARCH _ do docker run --rm \ -v "${ARTIFACTS_DIR}":/artifacts \ --privileged \ debimg \ - build-debian /artifacts/debian-"${DIST}"-"${ARCH}" "${ARCH}" "${DIST}" \ - >"${D}"/"log-${DIST}-${ARCH}.txt" 2>&1 && - rm "${D}"/"log-${DIST}-${ARCH}.txt" + build-debian "${OS}" "${ARCH}" "${DIST}" + >"${D}"/"log-${OS}-${DIST}-${ARCH}.txt" 2>&1 && + rm "${D}"/"log-${OS}-${DIST}-${ARCH}.txt" done unset IFS diff --git a/scripts/build-debian b/scripts/build-debian index 171b267..ba70f15 100755 --- a/scripts/build-debian +++ b/scripts/build-debian @@ -1,18 +1,27 @@ #!/bin/sh # Build Debian root filesystem -IMAGE2="$1" # For example "/artifacts/debian-buster-armhf" +OS="$1" # For example "debian" ARCH="$2" # For example "armhf" DIST="$3" # For example "buster" set -e -case "${ARCH}" in -armhf) +case "${OS}-${ARCH}" in +debian-armhf) KERNEL=linux-image-armmp + URL=http://deb.debian.org/debian + SCRIPT=/usr/share/debootstrap/scripts/sid ;; -arm64) +debian-arm64) KERNEL=linux-image-arm64 + URL=http://deb.debian.org/debian + SCRIPT=/usr/share/debootstrap/scripts/sid + ;; +ubuntu-armhf|ubuntu-arm64) + KERNEL=linux-image-generic + URL=http://ports.ubuntu.com/ubuntu-ports + SCRIPT=/usr/share/debootstrap/scripts/gutsy ;; *) echo "Can't decide kernel package for \"${ARCH}\"" @@ -41,20 +50,21 @@ initramfs-tools,\ openssh-server \ "${DIST}" \ debian \ - "http://deb.debian.org/debian/" + "${URL}" \ + "${SCRIPT}" # Randomly generated root password PASSWORD=$(pwgen -B -A 6 1) # Write apt sources config -case "${DIST}" in -sid) +case "${OS}-${DIST}" in +debian-sid) tee debian/tmp/sources.list <<- EOF deb http://deb.debian.org/debian ${DIST} main deb-src http://deb.debian.org/debian ${DIST} main EOF ;; -*) +debian-*) tee debian/tmp/sources.list <<- EOF deb http://deb.debian.org/debian ${DIST} main deb-src http://deb.debian.org/debian ${DIST} main @@ -62,6 +72,16 @@ deb http://deb.debian.org/debian ${DIST}-updates main deb-src http://deb.debian.org/debian ${DIST}-updates main deb http://security.debian.org/debian-security ${DIST}/updates main deb-src http://security.debian.org/debian-security ${DIST}/updates main +EOF + ;; +ubuntu-*) + tee debian/tmp/sources.list <<- EOF +deb http://ports.ubuntu.com/ubuntu-ports ${DIST} main universe +deb-src http://ports.ubuntu.com/ubuntu-ports ${DIST} main universe +deb http://ports.ubuntu.com/ubuntu-ports ${DIST}-updates main universe +deb-src http://ports.ubuntu.com/ubuntu-ports ${DIST}-updates main universe +deb http://ports.ubuntu.com/ubuntu-ports ${DIST}-security main universe +deb-src http://ports.ubuntu.com/ubuntu-ports ${DIST}-security main universe EOF ;; esac @@ -91,8 +111,11 @@ rm -v debian/usr/bin/qemu-*-static || : cp -rv --preserve=mode ../2nd-stage-files/post-2nd-stage-files/* debian +# Set hostname +echo "${OS}" > debian/etc/hostname + # List all files -find debian ! -type d -printf "/%P\n" | sort > "/artifacts/debian-${DIST}-${ARCH}.files.txt" +find debian ! -type d -printf "/%P\n" | sort > "/artifacts/${OS}-${DIST}-${ARCH}.files.txt" # Make a ext4 filesystem of this and put it into the image rm -f ext4.img @@ -100,4 +123,4 @@ fallocate -l 900MiB ext4.img mkfs.ext4 -d debian ext4.img gzip ext4.img -cp -v ext4.img.gz "${IMAGE2}-${PASSWORD}.bin.gz" +cp -v ext4.img.gz "/artifacts/${OS}-${DIST}-${ARCH}-${PASSWORD}.bin.gz"