mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-10-30 08:24:06 +00:00
Since release 25.10 we require support for the rva23s64 profile. Remove all code relating for boards that do not match this requirement. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
268 lines
8.9 KiB
Bash
Executable File
268 lines
8.9 KiB
Bash
Executable File
#!/bin/bash -eux
|
|
|
|
case $ARCH in
|
|
amd64|arm64|armhf|riscv64)
|
|
;;
|
|
*)
|
|
echo "We don't create EFI images for $ARCH."
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
|
|
if [ "$ARCH" = "amd64" ]; then
|
|
IMAGE_SIZE=3758096384 # bump to 3.5G (3584*1024**2); Since Kinetic amd64 need more then the default 2.2G
|
|
fi
|
|
|
|
if [ "$ARCH" = "armhf" ]; then
|
|
IMAGE_SIZE=3758096384 # bump to 3.5G (3584*1024**2); Since Jammy armhf need more then the default 2.2G
|
|
fi
|
|
|
|
# Change image size for preinstalled generic images
|
|
if [ -n "${SUBARCH:-}" ]; then
|
|
if [ "${SUBARCH:-}" = "generic" ]; then
|
|
IMAGE_SIZE=3758096384 # bump to 3.5G (3584*1024**2), due to linux-generic instead of virtual
|
|
fi
|
|
fi
|
|
|
|
if [ "$ARCH" = "riscv64" ]; then
|
|
IMAGE_SIZE=4831838208 # bump to 4.5G (4608*1024**2); initrd creation fails with "No space left" with 3.5G
|
|
fi
|
|
|
|
case ${PROJECT:-}:${SUBPROJECT:-} in
|
|
ubuntu:|ubuntu:dangerous)
|
|
echo "We don't create EFI images for Ubuntu Desktop."
|
|
exit 0
|
|
;;
|
|
ubuntu:desktop-preinstalled)
|
|
IMAGE_STR="# DESKTOP_IMG: This file was created/modified by the Desktop Image build process"
|
|
FS_LABEL="desktop-rootfs"
|
|
IMAGE_SIZE=12884901888 # 12G
|
|
;;
|
|
*)
|
|
IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
|
FS_LABEL="cloudimg-rootfs"
|
|
;;
|
|
esac
|
|
|
|
. config/binary
|
|
|
|
. config/functions
|
|
|
|
create_partitions() {
|
|
disk_image="$1"
|
|
sgdisk "${disk_image}" --zap-all
|
|
case $ARCH in
|
|
arm64|armhf)
|
|
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)
|
|
sgdisk "${disk_image}" \
|
|
--new=15::+106M \
|
|
--typecode=15:ef00 \
|
|
--new=12::+4M \
|
|
--change-name=12:CIDATA \
|
|
--new=1:: \
|
|
fi
|
|
;;
|
|
amd64)
|
|
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}" \
|
|
--print
|
|
}
|
|
|
|
create_and_mount_uefi_partition() {
|
|
uefi_dev="${loop_device}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 umask=0077 0 1
|
|
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}"
|
|
|
|
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 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="${loop_device}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="${loop_device}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="${loop_device}p13"
|
|
setup_cidata "${cidata_dev}"
|
|
setup_cinocloud mountpoint
|
|
fi
|
|
;;
|
|
riscv64)
|
|
# Per-device images
|
|
local my_d=$(dirname $(readlink -f ${0}))
|
|
echo "Adjusting GRUB defaults for ${ARCH}/${SUBARCH}"
|
|
mkdir -p mountpoint/etc/default/grub.d/
|
|
cp ${my_d}/riscv64/grub/10_cmdline.cfg mountpoint/etc/default/grub.d/
|
|
echo "Copying device trees"
|
|
kver=$(ls mountpoint/lib/modules | sort -V | tail -n 1)
|
|
dtb_src_dirs=(
|
|
"mountpoint/usr/lib/linux-image-$kver"
|
|
"mountpoint/lib/firmware/$kver/device-tree"
|
|
)
|
|
dtb_tgt_dir="mountpoint/boot/efi/dtb/"
|
|
mkdir -p "$dtb_tgt_dir"
|
|
for src_dir in "${dtb_src_dirs[@]}"; do
|
|
[ -d "$src_dir" ] && cp -r -v "$src_dir"/* "$dtb_tgt_dir" || echo "Skipping missing: $src_dir"
|
|
done
|
|
chroot mountpoint bash -c 'FK_FORCE=yes apt-get install -qqy grub-efi-riscv64 flash-kernel'
|
|
efi_target=riscv64-efi
|
|
# Provide end-user modifyable CIDATA
|
|
cidata_dev="${loop_device}p12"
|
|
setup_cidata "${cidata_dev}"
|
|
# Provide stock nocloud datasource
|
|
# Allow interactive login without a cloud datasource.
|
|
setup_cinocloud mountpoint
|
|
;;
|
|
esac
|
|
|
|
chroot mountpoint apt-get autoremove --purge --assume-yes
|
|
|
|
chroot mountpoint grub-install "${loop_device}" \
|
|
--boot-directory=/boot \
|
|
--efi-directory=/boot/efi \
|
|
--target=${efi_target} \
|
|
--uefi-secure-boot \
|
|
--no-nvram
|
|
|
|
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
|
|
|
|
# Use initrdless boot for minimal images
|
|
if [ "${SUBPROJECT:-}" = "minimized" ]; then
|
|
force_boot_without_initramfs mountpoint
|
|
fi
|
|
|
|
# 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
|
|
|
|
divert_grub mountpoint
|
|
track_initramfs_boot_fallback 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
|
|
|
|
# create sorted filelist as the very last step before unmounting
|
|
(cd mountpoint && find -xdev) | sort > binary/boot/filesystem.filelist
|
|
|
|
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
|