Update for physical disks and EFI
This commit is contained in:
parent
8a3fe39a22
commit
8ad514203e
155
build.sh
155
build.sh
|
@ -3,79 +3,103 @@
|
|||
OS_CODENAME=focal
|
||||
OS_VERSION=20.04
|
||||
DEV=/dev/nbd0
|
||||
TYPE=cloud
|
||||
NBD=yes
|
||||
TYPE=maas
|
||||
DOWNLOAD=yes
|
||||
MAAS_ID=20220524
|
||||
# MAAS_ID=20220601
|
||||
|
||||
if [ ${TYPE} == cloud ]; then
|
||||
ROOTPART="${DEV}p1"
|
||||
else
|
||||
BOOTPART="${DEV}p1"
|
||||
ROOTPART="${DEV}p2"
|
||||
# partition block device
|
||||
lastchar=${DEV: -1}
|
||||
EFIPART="${DEV}1"
|
||||
BOOTPART="${DEV}2"
|
||||
ROOTPART="${DEV}3"
|
||||
if [ "$lastchar" -eq "$lastchar" ] 2>/dev/null; then
|
||||
EFIPART="${DEV}p1"
|
||||
BOOTPART="${DEV}p2"
|
||||
ROOTPART="${DEV}p3"
|
||||
fi
|
||||
|
||||
function get_maas_id(){
|
||||
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' \
|
||||
"$streams")
|
||||
rm -f $streams
|
||||
echo "MAAS_ID=$MAAS_ID"
|
||||
}
|
||||
|
||||
function download(){
|
||||
if [ -z "$DOWNLOAD" ]; then
|
||||
return
|
||||
fi
|
||||
echo "Downloading"
|
||||
if [ ${TYPE} == "cloud" ]; then
|
||||
wget -O build/${TYPE}/initrd.img \
|
||||
https://cloud-images.ubuntu.com/$OS_CODENAME/current/unpacked/${OS_CODENAME}-server-cloudimg-amd64-initrd-generic
|
||||
wget -O build/${TYPE}/vmlinuz \
|
||||
https://cloud-images.ubuntu.com/${OS_CODENAME}/current/unpacked/${OS_CODENAME}-server-cloudimg-amd64-vmlinuz-generic
|
||||
wget -O build/${TYPE}/rootfs.tar.xz \
|
||||
https://cloud-images.ubuntu.com/${OS_CODENAME}/current/${OS_CODENAME}-server-cloudimg-amd64-root.tar.xz
|
||||
else
|
||||
wget -O build/${TYPE}/initrd.img \
|
||||
https://images.maas.io/ephemeral-v3/stable/${OS_CODENAME}/amd64/${MAAS_ID}/ga-${OS_VERSION}/boot-initrd
|
||||
wget -O build/${TYPE}/vmlinuz \
|
||||
https://images.maas.io/ephemeral-v3/stable/${OS_CODENAME}/amd64/${MAAS_ID}/ga-${OS_VERSION}/boot-kernel
|
||||
wget -O build/${TYPE}/rootfs.squashfs \
|
||||
https://cloud-images.ubuntu.com/${OS_CODENAME}/amd64/${MAAS_ID}/squashfs
|
||||
fi
|
||||
wget -N -P download \
|
||||
https://cloud-images.ubuntu.com/$OS_CODENAME/current/unpacked/${OS_CODENAME}-server-cloudimg-amd64-initrd-generic \
|
||||
https://cloud-images.ubuntu.com/${OS_CODENAME}/current/unpacked/${OS_CODENAME}-server-cloudimg-amd64-vmlinuz-generic \
|
||||
https://cloud-images.ubuntu.com/${OS_CODENAME}/current/${OS_CODENAME}-server-cloudimg-amd64-root.tar.xz \
|
||||
https://images.maas.io/ephemeral-v3/stable/${OS_CODENAME}/amd64/${MAAS_ID}/ga-${OS_VERSION}/generic/boot-initrd \
|
||||
https://images.maas.io/ephemeral-v3/stable/${OS_CODENAME}/amd64/${MAAS_ID}/ga-${OS_VERSION}/generic/boot-kernel \
|
||||
https://images.maas.io/ephemeral-v3/stable/${OS_CODENAME}/amd64/${MAAS_ID}/squashfs
|
||||
|
||||
|
||||
# CLOUD
|
||||
ln -f download/${OS_CODENAME}-server-cloudimg-amd64-vmlinuz-generic cloud-vmlinuz
|
||||
ln -f download/${OS_CODENAME}-server-cloudimg-amd64-initrd-generic cloud-initrd.img
|
||||
ln -f download/${OS_CODENAME}-server-cloudimg-amd64-root.tar.xz rootfs.tar.xz
|
||||
|
||||
# MAAS
|
||||
ln -f download/boot-kernel maas-vmlinuz
|
||||
ln -f download/boot-initrd maas-initrd.img
|
||||
}
|
||||
|
||||
sudo apt -yq install syslinux syslinux-common syslinux-efi extlinux f2fs-tools
|
||||
sudo apt -yq install syslinux syslinux-common syslinux-efi extlinux f2fs-tools dosfstools
|
||||
|
||||
mkdir -p build/${TYPE} mnt out squashmount
|
||||
mkdir -p build/${TYPE} download mnt out squashmount
|
||||
|
||||
download
|
||||
#get_maas_id
|
||||
#download
|
||||
|
||||
KERNEL_VERSION="$(file build/${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 "Creating empty image"
|
||||
qemu-img create -f qcow2 build/${TYPE}/ubuntu-${OS_CODENAME}.qcow2 2G || exit 1
|
||||
|
||||
echo "attaching image"
|
||||
sudo modprobe nbd
|
||||
sudo qemu-nbd -c "${DEV}" build/${TYPE}/ubuntu-${OS_CODENAME}.qcow2 || exit 1
|
||||
if [ "$NBD" ]; then
|
||||
echo "Creating empty image"
|
||||
qemu-img create -f qcow2 build/${TYPE}/ubuntu-${OS_CODENAME}.qcow2 5G || exit 1
|
||||
echo "attaching image"
|
||||
sudo modprobe nbd
|
||||
sudo qemu-nbd -c "${DEV}" build/${TYPE}/ubuntu-${OS_CODENAME}.qcow2 || exit 1
|
||||
fi
|
||||
|
||||
echo "partitioning"
|
||||
sudo parted -s "${DEV}" -- \
|
||||
mklabel gpt \
|
||||
unit MiB \
|
||||
mkpart '"Ubuntu"' btrfs 1 100% \
|
||||
set 1 legacy_boot on
|
||||
until [ -b "${DEV}1" ] || [ -b "${DEV}p1" ]; do
|
||||
sleep 1
|
||||
mklabel gpt \
|
||||
unit MiB \
|
||||
mkpart '"EFI system partition"' fat32 1 32MiB \
|
||||
mkpart '"Boot"' btrfs 32MiB 512MiB \
|
||||
mkpart '"Ubuntu"' btrfs 512MiB 100% \
|
||||
set 1 esp on \
|
||||
set 1 legacy_boot on
|
||||
until [ -b "$EFIPART" ] && [ -b "$BOOTPART" ] && [ -b "$ROOTPART" ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
|
||||
echo "installing hybrid bootloader"
|
||||
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
|
||||
|
||||
echo "mkfs.vfat (EFI)"
|
||||
sudo mkfs.vfat -n EFI ${EFIPART}
|
||||
echo "mkfs.btrfs (boot)"
|
||||
sudo mkfs.btrfs -L boot ${BOOTPART} || exit 1
|
||||
|
||||
if [ ${TYPE} == "cloud" ]; then
|
||||
echo "mkfs.btrfs"
|
||||
sudo mkfs.btrfs -L rootfs ${ROOTPART}" || exit 1
|
||||
echo "mkfs.btrfs (root)"
|
||||
sudo mkfs.btrfs -L rootfs ${ROOTPART} || exit 1
|
||||
else
|
||||
echo "mkfs.btrfs"
|
||||
sudo mkfs.btrfs -L boot ${BOOTPART}" || exit 1
|
||||
echo "mkfs.f2fs"
|
||||
sudo mkfs.f2fs -l rootfs -O extra_attr,inode_checksum,sb_checksum,compression ${ROOTPART} || exit 1
|
||||
echo "mkfs.f2fs (root)"
|
||||
sudo mkfs.f2fs -l rootfs -O extra_attr ${ROOTPART} || exit 1
|
||||
fi
|
||||
sync
|
||||
|
||||
|
@ -84,22 +108,24 @@ if [ ${TYPE} == "cloud" ]; then
|
|||
sudo mount -t btrfs ${ROOTPART} mnt || exit 1
|
||||
else
|
||||
sudo mount -t f2fs ${ROOTPART} mnt || exit 1
|
||||
sudo mkdir -p mnt/boot
|
||||
sudo mount -t btrfs ${BOOTPART} mnt/boot || exit 1
|
||||
fi
|
||||
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 build/${TYPE}/rootfs.tar.xz -C mnt || exit 1
|
||||
sudo tar xJf rootfs.tar.xz -C mnt || exit 1
|
||||
else
|
||||
sudo mount -t squashfs build/${TYPE}/rootfs.squashfs squashmount -o ro,loop || exit 1
|
||||
sudo mount -t squashfs download/squashfs squashmount -o ro,loop || exit 1
|
||||
cp -ar squashmount/. mnt
|
||||
umount squashmount
|
||||
fi
|
||||
|
||||
echo "installing kernel and inintd"
|
||||
sudo mkdir -p mnt/boot
|
||||
sudo cp -ar build/${TYPE}/initrd.img "mnt/boot/initrd.img-${KERNEL_VERSION}"
|
||||
sudo cp -ar build/${TYPE}/vmlinuz "mnt/boot/vmlinuz-${KERNEL_VERSION}"
|
||||
sudo cp -ar ${TYPE}-initrd.img "mnt/boot/initrd.img-${KERNEL_VERSION}"
|
||||
sudo cp -ar ${TYPE}-vmlinuz "mnt/boot/vmlinuz-${KERNEL_VERSION}"
|
||||
sudo ln -s "vmlinuz-${KERNEL_VERSION}" mnt/boot/vmlinuz
|
||||
sudo ln -s "initrd.img-${KERNEL_VERSION}" mnt/boot/initrd.img
|
||||
|
||||
|
@ -107,6 +133,11 @@ 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
|
||||
|
@ -118,24 +149,26 @@ if [ ${TYPE} == "cloud" ]; then
|
|||
echo "LABEL=rootfs / btrfs defaults 0 1" | sudo tee mnt/etc/fstab
|
||||
else
|
||||
echo "LABEL=rootfs / f2fs defaults 0 1" | sudo tee mnt/etc/fstab
|
||||
echo "LABEL=boot /boot btrfs defaults 0 1" | sudo tee -a 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
|
||||
if [ ${TYPE} != "cloud" ]; then
|
||||
umount /mnt/boot
|
||||
fi
|
||||
sudo umount mnt/boot/EFI
|
||||
sudo umount mnt/boot
|
||||
sudo umount mnt
|
||||
|
||||
echo "detaching"
|
||||
sudo qemu-nbd -d "${DEV}"
|
||||
if [ "$NBD" ]; then
|
||||
echo "detaching"
|
||||
sudo qemu-nbd -d "${DEV}"
|
||||
echo "compressing"
|
||||
qemu-img convert -cpO qcow2 build/${TYPE}/ubuntu-${OS_CODENAME}.qcow2 out/ubuntu-${OS_CODENAME}-${TYPE}.qcow2
|
||||
# rm -f out/ubuntu-${OS_CODENAME}.qcow2
|
||||
fi
|
||||
|
||||
echo "compressing"
|
||||
qemu-img convert -cpO qcow2 build/${TYPE}/ubuntu-${OS_CODENAME}.qcow2 out/ubuntu-${OS_CODENAME}-${TYPE}.qcow2
|
||||
# rm -f out/ubuntu-${OS_CODENAME}.qcow2
|
||||
|
||||
echo "done"
|
||||
|
|
|
@ -4,9 +4,9 @@ TOTALTIMEOUT 3000
|
|||
LABEL Current
|
||||
KERNEL /boot/vmlinuz
|
||||
INITRD /boot/initrd.img
|
||||
APPEND root=LABEL=cloudimg-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
|
||||
KERNEL /boot/vmlinuz.old
|
||||
INITRD /boot/initrd.img.old
|
||||
APPEND root=LABEL=cloudimg-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=
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
MENU TITLE Legacy boot
|
||||
UI vesamenu.c32
|
||||
|
||||
INCLUDE /boot/syslinux/mainmenu.cfg
|
||||
INCLUDE /syslinux/mainmenu.cfg
|
||||
|
|
Loading…
Reference in New Issue
Block a user