livecd-rootfs/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary
Steve Langasek 0ae1111c55 Import patches-unapplied version 2.376 to ubuntu/xenial-proposed
Imported using git-ubuntu import.

Changelog parent: 80fddc56a2b4d6ed82dcce3ef56028b37e40705a

New changelog entries:
  [ Michael Terry ]
  * Change real name for phablet user to "Ubuntu" in ubuntu-touch.
  [ Steve Langasek ]
  * Drop BuildLiveCD from the examples; we now use launchpad-buildd to drive
    livefs builds, so BuildLiveCD is obsolete and misleading.
  * Add hooks to ubuntu-cpc to divert /bin/sync in the chroot and undivert it
    at the end.  This is a general-purpose change that should be applied to
    all flavors and archs, but at the moment it's only needed on armhf+raspi2
    to work around the raspberrypi2-firmware postinst calling sync, which is
    actually warranted in the normal case.
  * If a subarch is specified for a cloud image build, don't build rootfs
    artifacts; these should come from the 'generic' build.
  * Fix architecture handling in hooks.  We know we're always being invoked
    from a launchpad-buildd-like setup, which passes ARCH and SUBARCH in the
    environment, because auto/config and auto/build both rely on this.  So
    don't scatter dpkg --print-architecture calls throughout, especially
    when many of these are not cross-build-aware.
  * Refactor ubuntu-cpc hooks to allow us to handle images where the root
    partition should not be partition 1.
  [ Ben Howard ]
  * ubuntu-cpc: fix hooks/032-disk-image.binary call to
    create_empty_partition, which requires five args due to "-u"
  * ubuntu-cpc: in hooks/030-root-tarball.binary create /lib/modules to fix
    (LP: 1543204).
  [ Dimitri John Ledkov ]
  * Do not remove linux-base, when purging all the linux-*, in the tarball
    build. Otherwise ubuntu-minimal is removed, and things get crazy.
  * Correct initrd.img symlink, kernel/hooks should actually produce the
    right thing here, but meh.
  * Chroot to execute zipl, because it's nice.
  * Use the right loop device to install zipl onto.
  [ Steve Langasek ]
  * Refactor ubuntu-cpc hooks to always produce a 'plain' rootfs via
    live-build and reuse this for the tarball, instead of lb_binary_rootfs
    creating some artifact that we ignore / throw away.
  * Initial support for raspi2 subarch.
  * Import live-build/ubuntu-cpc/hooks/raspi2/mkknlimg from
    https://github.com/raspberrypi/linux/blob/rpi-4.1.y/scripts/mkknlimg
    and use it to install a bootable uboot.bin.
2016-02-12 21:43:58 +00:00

145 lines
4.4 KiB
Bash
Executable File

#!/bin/bash -eux
case $ARCH in
amd64|arm64)
;;
*)
echo "We don't create EFI images for $ARCH."
exit 0
;;
esac
. /build/config/functions
apt-get -qqy install dosfstools gdisk
create_partitions() {
disk_image="$1"
sgdisk "${disk_image}" --zap-all
case $ARCH in
arm64)
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}"
case $ARCH in
arm64)
chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm64 grub-efi-arm64-bin
grub_modules="part_gpt fat gzio ext2 normal chain boot configfile linux search_fs_uuid search_label terminal serial video video_fb efi_gop"
efi_target=arm64-efi
;;
amd64)
chroot mountpoint apt-get install -qqy grub-efi-amd64-signed grub-efi-amd64 shim-signed
grub_modules="part_gpt fat ext2 normal chain boot configfile linux multiboot search_fs_uuid search_label terminal serial video video_fb video_bochs usb usb_keyboard efi_gop efi_uga"
chroot mountpoint cp /usr/lib/shim/shim.efi.signed "${efi_boot_dir}/shimx64.efi"
chroot mountpoint cp /usr/lib/shim/MokManager.efi.signed "${efi_boot_dir}/MokManager.efi"
chroot mountpoint cp /usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed "${efi_boot_dir}/grubx64.efi"
efi_target=x86_64-efi
;;
esac
cat << EOF >> mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg
${CLOUD_IMG_STR}
# For Cloud Image compatability
GRUB_PRELOAD_MODULES="${grub_modules}"
EOF
chroot mountpoint grub-install "${loop_device}" \
--boot-directory=/boot \
--efi-directory=/boot/efi \
--target=${efi_target} \
--removable \
--uefi-secure-boot \
--no-nvram \
--modules="${grub_modules}"
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${CLOUD_IMG_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
chroot mountpoint dpkg-divert --local --rename /etc/grub.d/30_os-prober
chroot mountpoint update-grub
sed -i "s,root=.* ,root=LABEL=cloudimg-rootfs ,g" mountpoint/boot/grub/grub.cfg
chroot mountpoint dpkg-divert --remove --local --rename /etc/grub.d/30_os-prober
chroot mountpoint apt-get -y clean
chroot mountpoint apt-get -y update
rm mountpoint/tmp/device.map
sync
umount mountpoint/boot/efi
sleep 5
udevadm settle
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
# 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