diff --git a/debian/changelog b/debian/changelog index a898d2de..4879ef7a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +livecd-rootfs (2.719) UNRELEASED; urgency=medium + + * Add support for generic preinstalled images. LP: #1923832 + + -- Dimitri John Ledkov Wed, 14 Apr 2021 14:18:34 +0100 + livecd-rootfs (2.719) hirsute; urgency=medium * Our raspi server images should have used the raspi-server seed in hirsute, diff --git a/live-build/auto/config b/live-build/auto/config index c02c47c2..9941c2e5 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -295,6 +295,19 @@ if [ -z "${IMAGEFORMAT:-}" ]; then esac fi +# Configure preinstalled ubuntu-cpc images with included password +# one also must request disk1-img-xz image format +if [ "$IMAGEFORMAT" = "ext4" ] && [ "$PROJECT" = "ubuntu-cpc" ]; then + case $ARCH:$SUBARCH in + armhf:raspi2|riscv64:sifive_*|*:generic) + IMAGE_HAS_HARDCODED_PASSWORD=1 + if [ -z "${IMAGE_TARGETS:-}" ]; then + export IMAGE_TARGETS="disk1-img-xz" + fi + ;; + esac +fi + skip_lb_stage() { STAGE="$1" mkdir -p .build @@ -821,6 +834,14 @@ case $PROJECT in ;; arm64) add_package install flash-kernel + if [ "${SUBARCH:-}" = "generic" ]; then + KERNEL_FLAVOURS=generic + fi + ;; + amd64) + if [ "${SUBARCH:-}" = "generic" ]; then + KERNEL_FLAVOURS=generic + fi ;; riscv64) if [ -n "$SUBARCH" ]; then @@ -1028,6 +1049,13 @@ echo "BUILDSTAMP=\"$NOW\"" >> config/binary echo "SUBPROJECT=\"${SUBPROJECT:-}\"" >> config/binary echo "LB_DISTRIBUTION=\"$SUITE\"" >> config/binary +if [ "${IMAGE_HAS_HARDCODED_PASSWORD:-}" = "1" ]; then + echo IMAGE_HAS_HARDCODED_PASSWORD=1 >> config/binary + if [ -n "${IMAGE_TARGETS:-}" ]; then + echo "IMAGE_TARGETS=\"${IMAGE_TARGETS:-}\"" >> config/binary + fi +fi + case $PROJECT in ubuntu-cpc|ubuntu-core|ubuntu-base|base) # ubuntu-cpc gets this added in 025-create-groups.chroot, and we do diff --git a/live-build/functions b/live-build/functions index ffeeeaec..ee46a467 100644 --- a/live-build/functions +++ b/live-build/functions @@ -1004,6 +1004,42 @@ END umount ${mountpoint} } +setup_cinocloud() { + if [ "${IMAGE_HAS_HARDCODED_PASSWORD:-}" != "1" ] || [ "${IMAGE_TARGETS:-}" != "disk1-img-xz" ]; then + echo "unexpected attempt to add a hardcoded password to an image" + exit 1 + fi + local mountpoint=$1 + mkdir -p $mountpoint/var/lib/cloud/seed/nocloud-net + cat <$mountpoint/var/lib/cloud/seed/nocloud-net/meta-data +instance-id: iid-$(openssl rand -hex 8) +EOF + cat <$mountpoint/var/lib/cloud/seed/nocloud-net/user-data +#cloud-config +chpasswd: + expire: True + list: + - ubuntu:ubuntu +ssh_pwauth: True +EOF + cat <$mountpoint/var/lib/cloud/seed/nocloud-net/network-config +# This is the initial network config. +# It can be overwritten by cloud-init. +version: 2 +ethernets: + zz-all-en: + match: + name: "en*" + dhcp4: true + optional: true + zz-all-eth: + match: + name: "eth*" + dhcp4: true + optional: true +EOF +} + replace_kernel () { mountpoint=$1 new_kernel=$2 diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary index a619299b..c73d0fe2 100755 --- a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary +++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary @@ -21,8 +21,11 @@ case ${PROJECT:-} in ;; esac -if [ "$ARCH" = "riscv64" ] && [ -n "${SUBARCH:-}" ]; then - IMAGE_SIZE=3758096384 # bump to 3.5G (3584*1024**2), due to linux-generic instead of virtual +# Change image size for preinstalled generic images & all preinstalled riscv64 images +if [ -n "${SUBARCH:-}" ]; then + if [ "${SUBARCH:-}" = "generic" ] || [ "$ARCH" = "riscv64" ]; then + IMAGE_SIZE=3758096384 # bump to 3.5G (3584*1024**2), due to linux-generic instead of virtual +fi fi . config/binary @@ -34,10 +37,20 @@ create_partitions() { sgdisk "${disk_image}" --zap-all case $ARCH in arm64|armhf) - sgdisk "${disk_image}" \ - --new=15:0:204800 \ - --typecode=15:ef00 \ - --new=1: + if [ "${SUBARCH:-}" = "generic" ]; then + sgdisk "${disk_image}" \ + --new=15:0:204800 \ + --typecode=15:ef00 \ + --attributes=15:set:2 \ + --new=14::+4M \ + --change-name=14:CIDATA \ + --new=1: + else + sgdisk "${disk_image}" \ + --new=15:0:204800 \ + --typecode=15:ef00 \ + --new=1: + fi ;; riscv64) # same as arm64/armhf, but set bit 2 legacy bios bootable @@ -72,13 +85,25 @@ create_partitions() { fi ;; amd64) - sgdisk "${disk_image}" \ - --new=14::+4M \ - --new=15::+106M \ - --new=1:: - sgdisk "${disk_image}" \ - -t 14:ef02 \ - -t 15:ef00 + if [ "${SUBARCH:-}" = "generic" ]; then + sgdisk "${disk_image}" \ + --new=14::+4M \ + --typecode=14:ef02 \ + --attributes=14:set:2 \ + --new=15::+106M \ + --typecode=15:ef00 \ + --new=13::+4M \ + --change-name=13:CIDATA \ + --new=1:: + else + sgdisk "${disk_image}" \ + --new=14::+4M \ + --new=15::+106M \ + --new=1:: + sgdisk "${disk_image}" \ + -t 14:ef02 \ + -t 15:ef00 + fi ;; esac sgdisk "${disk_image}" \ @@ -119,14 +144,38 @@ install_grub() { arm64) chroot mountpoint apt-get -qqy install --no-install-recommends shim-signed grub-efi-arm64-signed efi_target=arm64-efi + if [ "${SUBARCH:-}" = "generic" ]; then + # Server preinstalled image + # Setup cidata sample data & nocloud fallback + # Allows login on first boot with or without metadata + cidata_dev="/dev/mapper${loop_device///dev/}p14" + setup_cidata "${cidata_dev}" + setup_cinocloud mountpoint + fi ;; armhf) chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm grub-efi-arm-bin efi_target=arm-efi + if [ "${SUBARCH:-}" = "generic" ]; then + # Server preinstalled image + # Setup cidata sample data & nocloud fallback + # Allows login on first boot with or without metadata + cidata_dev="/dev/mapper${loop_device///dev/}p14" + setup_cidata "${cidata_dev}" + setup_cinocloud mountpoint + fi ;; amd64) chroot mountpoint apt-get install -qqy grub-pc shim-signed efi_target=x86_64-efi + if [ "${SUBARCH:-}" = "generic" ]; then + # Server preinstalled image + # Setup cidata sample data & nocloud fallback + # Allows login on first boot with or without metadata + cidata_dev="/dev/mapper${loop_device///dev/}p13" + setup_cidata "${cidata_dev}" + setup_cinocloud mountpoint + fi ;; riscv64) # TODO grub-efi-riscv64 does not exist yet on riscv64 @@ -153,34 +202,7 @@ install_grub() { # Provide stock nocloud datasource # Allow interactive login on baremetal SiFive board, # without a cloud datasource. - mkdir -p mountpoint/var/lib/cloud/seed/nocloud-net - cat <mountpoint/var/lib/cloud/seed/nocloud-net/meta-data -instance-id: iid-$(openssl rand -hex 8) -EOF - cat <mountpoint/var/lib/cloud/seed/nocloud-net/user-data -#cloud-config -chpasswd: - expire: True - list: - - ubuntu:ubuntu -ssh_pwauth: True -EOF - cat <mountpoint/var/lib/cloud/seed/nocloud-net/network-config -# This is the initial network config. -# It can be overwritten by cloud-init. -version: 2 -ethernets: - zz-all-en: - match: - name: "en*" - dhcp4: true - optional: true - zz-all-eth: - match: - name: "eth*" - dhcp4: true - optional: true -EOF + setup_cinocloud mountpoint fi ## TODO remove below once we have grub-efi-riscv64 rm mountpoint/tmp/device.map diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary index fda732da..7c8bc9b7 100755 --- a/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary +++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary @@ -31,6 +31,10 @@ case $ARCH:$SUBARCH in echo "We only create EFI images for $ARCH." exit 0 ;; + amd64:generic) + echo "We only create EFI images for $SUBARCH." + exit 0 + ;; *) ;; esac diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk1-img-xz.binary b/live-build/ubuntu-cpc/hooks.d/base/disk1-img-xz.binary new file mode 100755 index 00000000..b97fe2e8 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks.d/base/disk1-img-xz.binary @@ -0,0 +1,17 @@ +#!/bin/bash -ex + +. config/functions +. config/binary + +if [ "${IMAGE_HAS_HARDCODED_PASSWORD:-}" != "1" ]; then + echo ".disk1.img.xz preinstalled image requested to be built" + echo "but the build is not generated with hardcoded password" + echo "the build is missconfigured" + exit 1 +fi + +if [ -f binary/boot/disk-uefi.ext4 ]; then + xz -T4 -c binary/boot/disk-uefi.ext4 > livecd.ubuntu-cpc.disk1.img.xz +elif [ -f binary/boot/disk.ext4 ]; then + xz -T4 -c binary/boot/disk.ext4 > livecd.ubuntu-cpc.disk1.img.xz +fi diff --git a/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary b/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary index 5b38fe69..8dbbb9ae 100755 --- a/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary +++ b/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary @@ -1,18 +1,5 @@ #!/bin/bash -ex -case $ARCH:$SUBARCH in - # Not sure if any other cloud images use subarch for something that - # should take qcow2 format, so only skipping this on raspi2 for now. - armhf:raspi2) - xz -T4 -c binary/boot/disk.ext4 > livecd.ubuntu-cpc.disk1.img.xz - exit 0 - ;; - riscv64:hifive|riscv64:sifive_*) - xz -T4 -c binary/boot/disk-uefi.ext4 > livecd.ubuntu-cpc.disk1.img.xz - exit 0 - ;; -esac - . config/functions if [ -f binary/boot/disk-uefi.ext4 ]; then diff --git a/live-build/ubuntu-cpc/hooks.d/base/series/disk1-img-xz b/live-build/ubuntu-cpc/hooks.d/base/series/disk1-img-xz new file mode 100644 index 00000000..dfbdf1b2 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks.d/base/series/disk1-img-xz @@ -0,0 +1,3 @@ +depends disk-image +base/disk1-img-xz.binary +provides livecd.ubuntu-cpc.disk1.img.xz