From cd15b730f748e791af795fcc0632cd548dc8b91c Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Thu, 28 Sep 2017 09:38:21 -0400 Subject: [PATCH] In a cloud environment, we can rely on the kernel being able to boot the root filesystem directly, without an initramfs; enable this when building minimized. --- live-build/ubuntu-cpc/functions | 4 ++++ .../ubuntu-cpc/hooks/032-disk-image.binary | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/live-build/ubuntu-cpc/functions b/live-build/ubuntu-cpc/functions index 1cde487a..9e340149 100644 --- a/live-build/ubuntu-cpc/functions +++ b/live-build/ubuntu-cpc/functions @@ -273,6 +273,10 @@ replace_grub_root_with_label() { # Instead, we want grub to use the cloudimg-rootfs labelled disk CHROOT_ROOT="$1" + # If boot by partuuid has been requested, don't override. + if grep -q ^GRUB_FORCE_PARTUUID= $CHROOT_ROOT/etc/default/grub; then + return 0 + fi sed -i -e "s,root=[^ ]\+,root=LABEL=cloudimg-rootfs," \ "$CHROOT_ROOT/boot/grub/grub.cfg" } diff --git a/live-build/ubuntu-cpc/hooks/032-disk-image.binary b/live-build/ubuntu-cpc/hooks/032-disk-image.binary index 9c7d42ea..4e00649e 100755 --- a/live-build/ubuntu-cpc/hooks/032-disk-image.binary +++ b/live-build/ubuntu-cpc/hooks/032-disk-image.binary @@ -2,6 +2,8 @@ . config/functions +. /build/config/binary + BOOTPART_START= BOOTPART_END= BOOT_MOUNTPOINT= @@ -64,6 +66,8 @@ create_empty_partition "${disk_image}" "$ROOTPART" "$ROOTPART_START" -1 ext2 "$R mount_image "${disk_image}" "$ROOTPART" +partuuid=$(blkid -s PARTUUID -o value "$rootfs_dev_mapper") + # Copy the chroot in to the disk make_ext4_partition "${rootfs_dev_mapper}" mkdir mountpoint @@ -111,6 +115,25 @@ if [ "${should_install_grub}" -eq 1 ]; then ${loop_device} rm mountpoint/tmp/device.map + + if [ "$SUBPROJECT" = minimize ] && [ -n "$partuuid" ]; then + echo "partuuid found for root device; omitting initrd" + chroot mountpoint dpkg-divert --add \ + --divert /usr/sbin/update-initramfs.divert-minimize \ + --rename /usr/sbin/update-initramfs + cat > mountpoint/usr/sbin/update-initramfs <<'EOF' +#! /bin/sh +echo "initramfs disabled on this system. To reenable, run:" >&2 +echo " sudo rm -f /usr/sbin/update-initramfs" >&2 +echo " sudo dpkg-divert --remove --rename /usr/sbin/update-initramfs" >&2 +exit 0 +EOF + chmod +x mountpoint/usr/sbin/update-initramfs + rm -f mountpoint/boot/initrd.img-* + + echo "GRUB_FORCE_PARTUUID=$partuuid" >> mountpoint/etc/default/grub + chroot mountpoint update-grub + fi fi if [ "$ARCH" = "s390x" ]; then