From 3ad1e1dabdd1b5e87e4f71e70eab92db8de30f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=A0urda?= Date: Sat, 25 Jun 2022 18:01:41 +0200 Subject: [PATCH] Fix bootloader - also disable EFI --- build.sh | 55 +++++++++++++++++++------------------------ syslinux/mainmenu.cfg | 8 +++---- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/build.sh b/build.sh index 957b27f..c2ab65b 100755 --- a/build.sh +++ b/build.sh @@ -2,24 +2,28 @@ OS_CODENAME=focal OS_VERSION=20.04 -DEV=/dev/nbd0 -NBD=yes +DEV=/dev/sda +# NBD=yes, NBD= +NBD= +# TYPE=maas, TYPE=cloud TYPE=maas +# DOWNLOAD=yes, DOWNLOAD= DOWNLOAD=yes -# MAAS_ID=20220601 +MAAS_ID= # partition block device lastchar=${DEV: -1} -EFIPART="${DEV}1" -BOOTPART="${DEV}2" -ROOTPART="${DEV}3" +BOOTPART="${DEV}1" +ROOTPART="${DEV}2" if [ "$lastchar" -eq "$lastchar" ] 2>/dev/null; then - EFIPART="${DEV}p1" - BOOTPART="${DEV}p2" - ROOTPART="${DEV}p3" + BOOTPART="${DEV}p1" + ROOTPART="${DEV}p2" fi function get_maas_id(){ + if [ -n "$MAAS_ID" ]; then + return + fi streams=$(mktemp) wget -O $streams https://images.maas.io/ephemeral-v3/stable/streams/v1/com.ubuntu.maas:stable:v3:download.json MAAS_ID=$(jq -r '.products[]|select(.version=="'"$OS_VERSION"'" and .arch=="amd64" and .kflavor=="generic" and .subarch=="ga-'"$OS_VERSION"'")|.versions|keys|max' \ @@ -52,12 +56,12 @@ function download(){ ln -f download/boot-initrd maas-initrd.img } -sudo apt -yq install syslinux syslinux-common syslinux-efi extlinux f2fs-tools dosfstools +sudo apt -yq install syslinux syslinux-common syslinux-efi extlinux f2fs-tools dosfstools jq mkdir -p build/${TYPE} download mnt out squashmount -#get_maas_id -#download +get_maas_id +download KERNEL_VERSION="$(file ${TYPE}-vmlinuz |cut -d, -f2|cut -d\ -f3)" echo "Detected kernel ${KERNEL_VERSION}" @@ -74,12 +78,11 @@ echo "partitioning" sudo parted -s "${DEV}" -- \ mklabel gpt \ unit MiB \ - mkpart '"EFI system partition"' fat32 1 32MiB \ - mkpart '"Boot"' btrfs 32MiB 512MiB \ + mkpart '"Boot"' btrfs 1 512MiB \ mkpart '"Ubuntu"' btrfs 512MiB 100% \ set 1 esp on \ set 1 legacy_boot on -until [ -b "$EFIPART" ] && [ -b "$BOOTPART" ] && [ -b "$ROOTPART" ]; do +until [ -b "$BOOTPART" ] && [ -b "$ROOTPART" ]; do sleep 1 done @@ -89,17 +92,15 @@ sudo dd bs=440 count=1 conv=notrunc \ if=/usr/lib/syslinux/mbr/gptmbr.bin of="$DEV" 2> /dev/null sync -echo "mkfs.vfat (EFI)" -sudo mkfs.vfat -n EFI ${EFIPART} echo "mkfs.btrfs (boot)" -sudo mkfs.btrfs -L boot ${BOOTPART} || exit 1 +sudo mkfs.btrfs -f -L boot ${BOOTPART} || exit 1 if [ ${TYPE} == "cloud" ]; then echo "mkfs.btrfs (root)" - sudo mkfs.btrfs -L rootfs ${ROOTPART} || exit 1 + sudo mkfs.btrfs -f -L rootfs ${ROOTPART} || exit 1 else echo "mkfs.f2fs (root)" - sudo mkfs.f2fs -l rootfs -O extra_attr ${ROOTPART} || exit 1 + sudo mkfs.f2fs -f -l rootfs -O extra_attr ${ROOTPART} || exit 1 fi sync @@ -109,18 +110,17 @@ if [ ${TYPE} == "cloud" ]; then else sudo mount -t f2fs ${ROOTPART} mnt || exit 1 fi +echo "mounting boot" sudo mkdir -p mnt/boot sudo mount -t btrfs ${BOOTPART} mnt/boot || exit 1 -sudo mkdir -p mnt/boot/EFI -sudo mount -t vfat ${EFIPART} mnt/boot/EFI || exit 1 echo "unpacking root fs" if [ ${TYPE} == "cloud" ]; then sudo tar xJf rootfs.tar.xz -C mnt || exit 1 else sudo mount -t squashfs download/squashfs squashmount -o ro,loop || exit 1 - cp -ar squashmount/. mnt - umount squashmount + sudo cp -ar squashmount/. mnt + sudo umount squashmount fi echo "installing kernel and inintd" @@ -133,11 +133,6 @@ echo "installing legacy syslinux files" sudo mkdir -p mnt/boot/syslinux sudo cp /usr/lib/syslinux/modules/bios/*.c32 mnt/boot/syslinux/ sudo cp syslinux/{mainmenu,syslinux}.cfg mnt/boot/syslinux -echo "installing EFI syslinux files" -sudo mkdir -p mnt/EFI/BOOT -sudo cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi mnt/EFI/BOOT/BOOTX64.EFI -sudo cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 mnt/EFI/BOOT/ldlinux.e64 -sudo cp /usr/lib/syslinux/modules/efi64/*.c32 mnt/EFI/BOOT/ if [ -n "$1" ]; then echo "Patching UUID $1" sudo sed -i -e "s/?/?uuid=$1\&/g" mnt/boot/syslinux/mainmenu.cfg @@ -151,14 +146,12 @@ else echo "LABEL=rootfs / f2fs defaults 0 1" | sudo tee mnt/etc/fstab fi echo "LABEL=boot /boot btrfs defaults 0 1" | sudo tee -a mnt/etc/fstab -echo "LABEL=EFI /boot/EFI vfat defaults 0 1" | sudo tee -a mnt/etc/fstab echo "installing syslinux bootloader" sudo extlinux -i mnt/boot/syslinux echo "umounting" sync -sudo umount mnt/boot/EFI sudo umount mnt/boot sudo umount mnt diff --git a/syslinux/mainmenu.cfg b/syslinux/mainmenu.cfg index 49ca9eb..049475c 100644 --- a/syslinux/mainmenu.cfg +++ b/syslinux/mainmenu.cfg @@ -2,11 +2,11 @@ TIMEOUT 50 TOTALTIMEOUT 3000 LABEL Current - KERNEL /boot/vmlinuz - INITRD /boot/initrd.img + KERNEL /vmlinuz + INITRD /initrd.img APPEND root=LABEL=rootfs ds=nocloud-net;s=https://cloud-init.sysdeploy.org/apiv2?filetype= LABEL Previous - KERNEL /boot/vmlinuz.old - INITRD /boot/initrd.img.old + KERNEL /vmlinuz.old + INITRD /initrd.img.old APPEND root=LABEL=rootfs ds=nocloud-net;s=https://cloud-init.sysdeploy.org/apiv2?filetype=