Fix bootloader
Some checks failed
buildbot/multibuild_parent Build done.
buildbot/travis_bionic Build done.

- also disable EFI
This commit is contained in:
Peter Šurda 2022-06-25 18:01:41 +02:00
parent 8ad514203e
commit 3ad1e1dabd
Signed by: PeterSurda
GPG Key ID: 3E47497CF67ABB95
2 changed files with 28 additions and 35 deletions

View File

@ -2,24 +2,28 @@
OS_CODENAME=focal OS_CODENAME=focal
OS_VERSION=20.04 OS_VERSION=20.04
DEV=/dev/nbd0 DEV=/dev/sda
NBD=yes # NBD=yes, NBD=
NBD=
# TYPE=maas, TYPE=cloud
TYPE=maas TYPE=maas
# DOWNLOAD=yes, DOWNLOAD=
DOWNLOAD=yes DOWNLOAD=yes
# MAAS_ID=20220601 MAAS_ID=
# partition block device # partition block device
lastchar=${DEV: -1} lastchar=${DEV: -1}
EFIPART="${DEV}1" BOOTPART="${DEV}1"
BOOTPART="${DEV}2" ROOTPART="${DEV}2"
ROOTPART="${DEV}3"
if [ "$lastchar" -eq "$lastchar" ] 2>/dev/null; then if [ "$lastchar" -eq "$lastchar" ] 2>/dev/null; then
EFIPART="${DEV}p1" BOOTPART="${DEV}p1"
BOOTPART="${DEV}p2" ROOTPART="${DEV}p2"
ROOTPART="${DEV}p3"
fi fi
function get_maas_id(){ function get_maas_id(){
if [ -n "$MAAS_ID" ]; then
return
fi
streams=$(mktemp) streams=$(mktemp)
wget -O $streams https://images.maas.io/ephemeral-v3/stable/streams/v1/com.ubuntu.maas:stable:v3:download.json 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' \ 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 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 mkdir -p build/${TYPE} download mnt out squashmount
#get_maas_id get_maas_id
#download download
KERNEL_VERSION="$(file ${TYPE}-vmlinuz |cut -d, -f2|cut -d\ -f3)" KERNEL_VERSION="$(file ${TYPE}-vmlinuz |cut -d, -f2|cut -d\ -f3)"
echo "Detected kernel ${KERNEL_VERSION}" echo "Detected kernel ${KERNEL_VERSION}"
@ -74,12 +78,11 @@ echo "partitioning"
sudo parted -s "${DEV}" -- \ sudo parted -s "${DEV}" -- \
mklabel gpt \ mklabel gpt \
unit MiB \ unit MiB \
mkpart '"EFI system partition"' fat32 1 32MiB \ mkpart '"Boot"' btrfs 1 512MiB \
mkpart '"Boot"' btrfs 32MiB 512MiB \
mkpart '"Ubuntu"' btrfs 512MiB 100% \ mkpart '"Ubuntu"' btrfs 512MiB 100% \
set 1 esp on \ set 1 esp on \
set 1 legacy_boot on set 1 legacy_boot on
until [ -b "$EFIPART" ] && [ -b "$BOOTPART" ] && [ -b "$ROOTPART" ]; do until [ -b "$BOOTPART" ] && [ -b "$ROOTPART" ]; do
sleep 1 sleep 1
done 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 if=/usr/lib/syslinux/mbr/gptmbr.bin of="$DEV" 2> /dev/null
sync sync
echo "mkfs.vfat (EFI)"
sudo mkfs.vfat -n EFI ${EFIPART}
echo "mkfs.btrfs (boot)" 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 if [ ${TYPE} == "cloud" ]; then
echo "mkfs.btrfs (root)" echo "mkfs.btrfs (root)"
sudo mkfs.btrfs -L rootfs ${ROOTPART} || exit 1 sudo mkfs.btrfs -f -L rootfs ${ROOTPART} || exit 1
else else
echo "mkfs.f2fs (root)" 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 fi
sync sync
@ -109,18 +110,17 @@ if [ ${TYPE} == "cloud" ]; then
else else
sudo mount -t f2fs ${ROOTPART} mnt || exit 1 sudo mount -t f2fs ${ROOTPART} mnt || exit 1
fi fi
echo "mounting boot"
sudo mkdir -p mnt/boot sudo mkdir -p mnt/boot
sudo mount -t btrfs ${BOOTPART} mnt/boot || exit 1 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" echo "unpacking root fs"
if [ ${TYPE} == "cloud" ]; then if [ ${TYPE} == "cloud" ]; then
sudo tar xJf rootfs.tar.xz -C mnt || exit 1 sudo tar xJf rootfs.tar.xz -C mnt || exit 1
else else
sudo mount -t squashfs download/squashfs squashmount -o ro,loop || exit 1 sudo mount -t squashfs download/squashfs squashmount -o ro,loop || exit 1
cp -ar squashmount/. mnt sudo cp -ar squashmount/. mnt
umount squashmount sudo umount squashmount
fi fi
echo "installing kernel and inintd" echo "installing kernel and inintd"
@ -133,11 +133,6 @@ echo "installing legacy syslinux files"
sudo mkdir -p mnt/boot/syslinux sudo mkdir -p mnt/boot/syslinux
sudo cp /usr/lib/syslinux/modules/bios/*.c32 mnt/boot/syslinux/ sudo cp /usr/lib/syslinux/modules/bios/*.c32 mnt/boot/syslinux/
sudo cp syslinux/{mainmenu,syslinux}.cfg 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 if [ -n "$1" ]; then
echo "Patching UUID $1" echo "Patching UUID $1"
sudo sed -i -e "s/?/?uuid=$1\&/g" mnt/boot/syslinux/mainmenu.cfg 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 echo "LABEL=rootfs / f2fs defaults 0 1" | sudo tee mnt/etc/fstab
fi fi
echo "LABEL=boot /boot btrfs defaults 0 1" | sudo tee -a mnt/etc/fstab 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" echo "installing syslinux bootloader"
sudo extlinux -i mnt/boot/syslinux sudo extlinux -i mnt/boot/syslinux
echo "umounting" echo "umounting"
sync sync
sudo umount mnt/boot/EFI
sudo umount mnt/boot sudo umount mnt/boot
sudo umount mnt sudo umount mnt

View File

@ -2,11 +2,11 @@ TIMEOUT 50
TOTALTIMEOUT 3000 TOTALTIMEOUT 3000
LABEL Current LABEL Current
KERNEL /boot/vmlinuz KERNEL /vmlinuz
INITRD /boot/initrd.img INITRD /initrd.img
APPEND root=LABEL=rootfs ds=nocloud-net;s=https://cloud-init.sysdeploy.org/apiv2?filetype= APPEND root=LABEL=rootfs ds=nocloud-net;s=https://cloud-init.sysdeploy.org/apiv2?filetype=
LABEL Previous LABEL Previous
KERNEL /boot/vmlinuz.old KERNEL /vmlinuz.old
INITRD /boot/initrd.img.old INITRD /initrd.img.old
APPEND root=LABEL=rootfs ds=nocloud-net;s=https://cloud-init.sysdeploy.org/apiv2?filetype= APPEND root=LABEL=rootfs ds=nocloud-net;s=https://cloud-init.sysdeploy.org/apiv2?filetype=