SHA256
101 lines
2.8 KiB
Bash
101 lines
2.8 KiB
Bash
create_config() {
|
|
CONFIG=$(cat <<EOF
|
|
set timeout=60
|
|
set default=0
|
|
|
|
menuentry "SemiOS LiveCD (Copy to RAM)" {
|
|
search --no-floppy --set=root --file /boot/linux.img
|
|
|
|
linux /boot/linux.img early_mount=LABEL=SEMIOS:/livecd root=live:/livecd/rootfs.img copytoram ro
|
|
initrd /boot/initramfs.img
|
|
}
|
|
EOF
|
|
)
|
|
echo "${CONFIG}" > "$1/grub.cfg"
|
|
}
|
|
|
|
copy_kernel() {
|
|
mkdir -p "$1/isoroot/boot"
|
|
local kprefix=$(packie --chroot "$1/root" print "package.prefix.linux")
|
|
cp "$1/root/${kprefix}/vmlinuz" "$1/isoroot/boot/linux.img" 2> /dev/null || \
|
|
cp "$1/root/${kprefix}/vmlinux" "$1/isoroot/boot/linux.img" 2> /dev/null || \
|
|
exit 1
|
|
cp "$1/root/${kprefix}/initramfs.img" "$1/isoroot/boot/initramfs.img"
|
|
}
|
|
|
|
grub_arch() {
|
|
case "${ARCH}" in
|
|
aarch64-semios-linux)
|
|
echo arm64-efi
|
|
;;
|
|
riscv64-semios-linux)
|
|
echo riscv64-efi
|
|
;;
|
|
x86_64-semios-linux)
|
|
echo x86_64-efi
|
|
;;
|
|
*)
|
|
echo "mkliveimage: Unsupported architecture for ISO builds"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
efi_image_name() {
|
|
case "${ARCH}" in
|
|
aarch64-semios-linux)
|
|
echo "BOOTAA64.EFI"
|
|
;;
|
|
riscv64-semios-linux)
|
|
echo "BOOTRISCV64.EFI"
|
|
;;
|
|
x86_64-semios-linux)
|
|
echo "BOOTX64.EFI"
|
|
;;
|
|
*)
|
|
echo "mkliveimage: Unsupported architecture for ISO builds"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
create_efiboot_img() {
|
|
dd if=/dev/zero of="$1/efiboot.img" bs=1M count=16
|
|
mkfs.vfat -n EFIBOOT "$1/efiboot.img"
|
|
if [ "${SUDO}" -eq 1 ]; then
|
|
sudo mount --mkdir -o "uid=$(id -u)" "$1/efiboot.img" "$1/efiboot" || exit 1
|
|
else
|
|
mount --mkdir "$1/efiboot.img" "$1/efiboot" || exit 1
|
|
fi
|
|
mkdir -p "$1/efiboot/EFI/BOOT"
|
|
grub-mkstandalone -o "$1/efiboot/EFI/BOOT/$(efi_image_name)" -O "$(grub_arch)" \
|
|
--fonts "" --themes "" --locales "" \
|
|
--install-modules "part_gpt part_msdos fat linux search boot normal gzio iso9660" \
|
|
"boot/grub/grub.cfg=$1/grub.cfg"
|
|
if [ "${SUDO}" -eq 1 ]; then
|
|
sudo umount "$1/efiboot" || exit 1
|
|
else
|
|
umount "$1/efiboot" || exit 1
|
|
fi
|
|
mv "$1/efiboot.img" "$1/isoroot/efiboot.img"
|
|
}
|
|
|
|
create_iso() {
|
|
if [ "$(uname -s)" -eq "Linux" ]; then
|
|
mkfs.erofs -z lz4 -L "SEMIOSLIVEROOT" --mkfs-time --all-root "$1/rootfs.img" "$1/root"
|
|
create_config "$1"
|
|
create_efiboot_img $1
|
|
mkdir -p "$1/isoroot"
|
|
cp "$1/rootfs.img" "$1/isoroot/rootfs.img"
|
|
copy_kernel "$1"
|
|
xorriso -as mkisofs -r -V "SEMIOS" \
|
|
-J -joliet-long \
|
|
-iso-level 3 \
|
|
-e "efiboot.img" -no-emul-boot \
|
|
-isohybrid-gpt-basdat \
|
|
-o "${OUTPUT}" "$1/isoroot"
|
|
else
|
|
echo "Unsupported kernel."
|
|
fi
|
|
}
|