Merge buildd-bootable/bionic into ubuntu/bionic

Backports to enable building of bootable buildd images LP: #1863024

MP: https://code.launchpad.net/~davidkrauser/livecd-rootfs/+git/livecd-rootfs/+merge/380908
sil2100/appliance-images
Robert C Jennings 5 years ago
commit a00ac033d9
No known key found for this signature in database
GPG Key ID: 740C3D9EEDF2ED73

7
debian/changelog vendored

@ -1,3 +1,10 @@
livecd-rootfs (2.525.42) UNRELEASED; urgency=medium
[ Cody Shepherd / David Krauser ]
* Add bootable buildd image (LP: #1863024)
-- Robert C Jennings <robert.jennings@canonical.com> Fri, 27 Mar 2020 14:27:03 -0500
livecd-rootfs (2.525.41) bionic; urgency=medium livecd-rootfs (2.525.41) bionic; urgency=medium
* Use snap cli rather than custom snap-tool (LP: #1864252) * Use snap cli rather than custom snap-tool (LP: #1864252)

@ -763,7 +763,6 @@ case $SUBPROJECT in
OPTS="${OPTS:+$OPTS }--security false --volatile false" OPTS="${OPTS:+$OPTS }--security false --volatile false"
add_package install adduser add_package install adduser
add_package install policyrcd-script-zg2
add_package install pkgbinarymangler add_package install pkgbinarymangler
add_package install ca-certificates add_package install ca-certificates
add_package install gpg add_package install gpg

@ -9,4 +9,4 @@ set -e
# /var/lib/apt/lists/ has suitable cached Packages files; this speeds up # /var/lib/apt/lists/ has suitable cached Packages files; this speeds up
# builds on buildds. # builds on buildds.
sed -i "s,${LB_PARENT_MIRROR_BINARY},${LB_MIRROR_BINARY},g" \ sed -i "s,${LB_PARENT_MIRROR_BINARY},${LB_MIRROR_BINARY},g" \
binary/etc/apt/sources.list chroot/etc/apt/sources.list

@ -1,13 +0,0 @@
#! /bin/sh
set -e
# Put the /usr/sbin/policy-rc.d alternatives symlink in place. Ordinarily
# update-alternatives ought to create this when policyrcd-script-zg2 is
# installed, but that doesn't work because live-build has already installed
# a dummy one at that point. The simplest approach is to repair the
# situation by putting it in place here.
if [ -L binary/etc/alternatives/policy-rc.d ] && \
[ ! -e binary/usr/sbin/policy-rc.d ] && \
[ ! -L binary/usr/sbin/policy-rc.d ]; then
ln -s /etc/alternatives/policy-rc.d binary/usr/sbin/policy-rc.d
fi

@ -0,0 +1,158 @@
#!/bin/bash -eux
case $ARCH in
amd64)
;;
*)
echo "We don't create EFI images for $ARCH."
exit 0
;;
esac
IMAGE_STR="# BUILDD_IMG: This file was created/modified by the Buildd Image build process"
FS_LABEL="buildd-rootfs"
. config/binary
. config/functions
create_partitions() {
disk_image="$1"
sgdisk "${disk_image}" --zap-all
case $ARCH in
arm64|armhf)
sgdisk "${disk_image}" \
--new=15:0:204800 \
--typecode=15:ef00 \
--new=1:
;;
amd64)
sgdisk "${disk_image}" \
--new=14::+4M \
--new=15::+106M \
--new=1::
sgdisk "${disk_image}" \
-t 14:ef02 \
-t 15:ef00
;;
esac
sgdisk "${disk_image}" \
--print
}
create_and_mount_uefi_partition() {
uefi_dev="/dev/mapper${loop_device///dev/}p15"
mountpoint="$1"
mkfs.vfat -F 32 -n UEFI "${uefi_dev}"
mkdir -p "${mountpoint}"/boot/efi
mount "${uefi_dev}" "$mountpoint"/boot/efi
cat << EOF >> "mountpoint/etc/fstab"
LABEL=UEFI /boot/efi vfat defaults 0 0
EOF
}
install_grub() {
mkdir mountpoint
mount_partition "${rootfs_dev_mapper}" mountpoint
create_and_mount_uefi_partition mountpoint
echo "(hd0) ${loop_device}" > mountpoint/tmp/device.map
mkdir -p mountpoint/etc/default/grub.d
efi_boot_dir="/boot/efi/EFI/BOOT"
chroot mountpoint mkdir -p "${efi_boot_dir}"
if [ -n "$partuuid" ]; then
echo "GRUB_FORCE_PARTUUID=$partuuid" >> mountpoint/etc/default/grub.d/40-force-partuuid.cfg
fi
chroot mountpoint apt-get -y update
# UEFI GRUB modules are meant to be used equally by Secure Boot and
# non-Secure Boot systems. If you need an extra module not already
# provided or run into "Secure Boot policy forbids loading X" problems,
# please file a bug against grub2 to include the affected module.
case $ARCH in
arm64)
chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm64 grub-efi-arm64-bin
efi_target=arm64-efi
;;
armhf)
chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm grub-efi-arm-bin
efi_target=arm-efi
;;
amd64)
chroot mountpoint apt-get install -qqy grub-pc
chroot mountpoint apt-get install -qqy grub-efi-amd64-signed shim-signed
efi_target=x86_64-efi
;;
esac
# This call to rewrite the debian package manifest is added here to capture
# grub-efi packages that otherwise would not make it into the base
# manifest. filesystem.packages is moved into place via symlinking to
# livecd.ubuntu-cpc.manifest by live-build/auto/build after lb_binary runs
# and at that time snaps are added to the manifest (create-manifest is
# not called here as it calls snap-seed-parse, resulting in duplicate
# snap listings)
chroot mountpoint dpkg-query -W > binary/boot/filesystem.packages
chroot mountpoint grub-install "${loop_device}" \
--boot-directory=/boot \
--efi-directory=/boot/efi \
--target=${efi_target} \
--removable \
--uefi-secure-boot \
--no-nvram
if [ -f mountpoint/boot/efi/EFI/BOOT/grub.cfg ]; then
sed -i "s| root| root hd0,gpt1|" mountpoint/boot/efi/EFI/BOOT/grub.cfg
sed -i "1i${IMAGE_STR}" mountpoint/boot/efi/EFI/BOOT/grub.cfg
# For some reason the grub disk is looking for /boot/grub/grub.cfg on
# part 15....
chroot mountpoint mkdir -p /boot/efi/boot/grub
chroot mountpoint cp /boot/efi/EFI/BOOT/grub.cfg /boot/efi/boot/grub
fi
if [ "$ARCH" = "amd64" ]; then
# Install the BIOS/GPT bits. Since GPT boots from the ESP partition,
# it means that we just run this simple command and we're done
chroot mountpoint grub-install --target=i386-pc "${loop_device}"
fi
divert_grub mountpoint
chroot mountpoint update-grub
replace_grub_root_with_label mountpoint
undivert_grub mountpoint
chroot mountpoint apt-get -y clean
rm mountpoint/tmp/device.map
umount mountpoint/boot/efi
mount
umount_partition mountpoint
rmdir mountpoint
}
disk_image=binary/boot/disk-uefi.ext4
create_empty_disk_image "${disk_image}"
create_partitions "${disk_image}"
mount_image "${disk_image}" 1
partuuid=$(blkid -s PARTUUID -o value "$rootfs_dev_mapper")
# Copy the chroot in to the disk
make_ext4_partition "${rootfs_dev_mapper}"
mkdir mountpoint
mount "${rootfs_dev_mapper}" mountpoint
cp -a chroot/* mountpoint/
umount mountpoint
rmdir mountpoint
install_grub
clean_loops
trap - EXIT

@ -0,0 +1,18 @@
#!/bin/sh
set -e
# This is run after 02-disk-image-uefi.binary because
# we don't want policyrcd-script-zg2 installed in
# bootable images.
. config/functions
cleanup() {
teardown_mountpoint chroot
}
trap cleanup EXIT
setup_mountpoint chroot
chroot chroot apt-get install -y policyrcd-script-zg2

@ -0,0 +1,4 @@
#!/bin/sh
set -e
chroot chroot truncate -s 0 /etc/resolv.conf

@ -0,0 +1,70 @@
#!/bin/bash -eux
# vi: ts=4 expandtab
#
# Generate linux-virtual image
#
case $ARCH in
amd64)
;;
*)
echo "We don't build bootable Buildd images for $ARCH."
exit 0
;;
esac
echo "Building bootable Buildd image"
IMAGE_STR="# BUILDD_IMG: This file was created/modified by the Buildd Image build process"
. config/functions
mount_d=$(mktemp -d)
create_derivative uefi linux-virtual #sets $derivative_img
mount_disk_image $derivative_img $mount_d
# unmount disk image and remove created folders on exit
# even though we unmount manually before we convert to
# qcow2, we have this here just in case we error out before
# that step
cleanup_linux_virtual() {
if [ -d "$mount_d" ]; then
umount_disk_image "$mount_d"
fi
rm -rf $mount_d $derivative_img
}
trap cleanup_linux_virtual EXIT
# Install dependencies
env DEBIAN_FRONTEND=noninteractive chroot "$mount_d" apt-get \
update --assume-yes
env DEBIAN_FRONTEND=noninteractive chroot "$mount_d" apt-get \
install -y lsb-release locales initramfs-tools busybox-initramfs \
udev dbus netplan.io cloud-init openssh-server sudo snapd
# Install a kernel
divert_grub "$mount_d"
env DEBIAN_FRONTEND=noninteractive chroot "$mount_d" apt-get \
install --assume-yes linux-image-virtual
env DEBIAN_FRONTEND=noninteractive chroot "$mount_d" apt-get \
autoremove --purge --assume-yes
chroot "$mount_d" update-grub
undivert_grub "$mount_d"
# Update initramfs image
chroot "$mount_d" \
sh -c 'update-initramfs -c -v -k $(ls /boot/vmlinuz*generic | sed 1q | cut -d- -f2-3)'
# Cleanup
env DEBIAN_FRONTEND=noninteractive chroot "$mount_d" apt-get \
clean
create_manifest $mount_d "livecd.$PROJECT.disk-linux-virtual.manifest"
# unmount disk image to prevent corruption
# and remove it so the trap doesn't try to unmount it again
umount_disk_image $mount_d
rm -rf $mount_d
convert_to_qcow2 $derivative_img "livecd.$PROJECT.disk-linux-virtual.img"

@ -1,7 +1,7 @@
127.0.0.1 localhost.localdomain localhost 127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts # The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback ::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes ff02::1 ip6-allnodes

Loading…
Cancel
Save