Make installer image UEFI bootable
This commit is contained in:
parent
71878992fe
commit
e5496c247e
2 changed files with 60 additions and 14 deletions
|
|
@ -18,14 +18,15 @@ BUILD_CHANNEL="${BUILD_CHANNEL:-dev}" # dev | release
|
|||
# User-facing date format: DD.mmm.YYYY (per AGENTS.md convention)
|
||||
#
|
||||
# USB KEY SIZING GUIDE:
|
||||
# 32GB USB → IMAGE_SIZE="28G" (fits typical 29.5GiB sticks)
|
||||
# 64GB USB → IMAGE_SIZE="50G" (leaves ~14GB spare for user data/cache)
|
||||
# 128GB USB → IMAGE_SIZE="100G" (leaves ~28GB spare)
|
||||
# 256GB USB → IMAGE_SIZE="200G" (leaves ~56GB spare)
|
||||
#
|
||||
# Minimum: 64GB USB (with IMAGE_SIZE=50G)
|
||||
# Recommended: 128GB USB (with IMAGE_SIZE=100G) for comfortable offline setup
|
||||
# Minimum: 32GB USB (with IMAGE_SIZE=28G)
|
||||
# Recommended: 64GB+ USB for comfortable offline setup
|
||||
#
|
||||
IMAGE_SIZE="50G"
|
||||
IMAGE_SIZE="28G"
|
||||
# build.sh overrides IMAGE_NAME with the "unified" prefix; do not edit here.
|
||||
|
||||
# Clawdie-AI ref to bundle from Codeberg.
|
||||
|
|
|
|||
67
build.sh
67
build.sh
|
|
@ -299,6 +299,15 @@ verify_memstick_cache() {
|
|||
install_image_bootcode() {
|
||||
_image_md="$1"
|
||||
_image_root="$2"
|
||||
_freebsd_slice_index="${3:-}"
|
||||
|
||||
if [ -z "${_freebsd_slice_index}" ]; then
|
||||
if [ -e "/dev/${_image_md}s2" ]; then
|
||||
_freebsd_slice_index="2"
|
||||
else
|
||||
_freebsd_slice_index="1"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${_image_root}/boot/mbr" ] || [ ! -f "${_image_root}/boot/boot" ]; then
|
||||
echo "ERROR: missing bootcode files in ${_image_root}/boot"
|
||||
|
|
@ -306,7 +315,28 @@ install_image_bootcode() {
|
|||
fi
|
||||
|
||||
gpart bootcode -b "${_image_root}/boot/mbr" "/dev/${_image_md}"
|
||||
gpart bootcode -b "${_image_root}/boot/boot" "/dev/${_image_md}s1"
|
||||
gpart bootcode -b "${_image_root}/boot/boot" "/dev/${_image_md}s${_freebsd_slice_index}"
|
||||
}
|
||||
|
||||
install_image_uefi_bootcode() {
|
||||
_image_md="$1"
|
||||
_image_root="$2"
|
||||
_efi_slice_index="${3:-1}"
|
||||
_efi_mount="${CACHE_DIR}/efi-mnt"
|
||||
|
||||
if [ ! -f "${_image_root}/boot/loader.efi" ]; then
|
||||
echo "ERROR: missing UEFI loader at ${_image_root}/boot/loader.efi"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
newfs_msdos -L EFISYS "/dev/${_image_md}s${_efi_slice_index}"
|
||||
mkdir -p "${_efi_mount}"
|
||||
mount_msdosfs "/dev/${_image_md}s${_efi_slice_index}" "${_efi_mount}"
|
||||
mkdir -p "${_efi_mount}/EFI/BOOT"
|
||||
cp "${_image_root}/boot/loader.efi" "${_efi_mount}/EFI/BOOT/BOOTX64.EFI"
|
||||
sync
|
||||
umount "${_efi_mount}"
|
||||
rmdir "${_efi_mount}" 2>/dev/null || true
|
||||
}
|
||||
|
||||
build_live_qml_installer() {
|
||||
|
|
@ -651,22 +681,26 @@ if [ ! -f "$WORK_IMG" ]; then
|
|||
MD=$(mdconfig -a -t vnode -f "$WORK_IMG")
|
||||
echo " Attached as /dev/${MD}"
|
||||
|
||||
# Initialize MBR partition table
|
||||
# Initialize an MBR layout compatible with modern UEFI removable boot:
|
||||
# s1: EFI System Partition (FAT, contains /EFI/BOOT/BOOTX64.EFI)
|
||||
# s2: FreeBSD slice with BSD label + UFS root
|
||||
gpart create -s MBR /dev/${MD}
|
||||
gpart add -t efi -s 64M /dev/${MD}
|
||||
gpart add -t freebsd /dev/${MD}
|
||||
gpart set -a active -i 2 /dev/${MD}
|
||||
|
||||
# Create BSD label (partition a) in the FreeBSD slice
|
||||
gpart create -s BSD /dev/${MD}s1
|
||||
gpart add -t freebsd-ufs /dev/${MD}s1
|
||||
gpart create -s BSD /dev/${MD}s2
|
||||
gpart add -t freebsd-ufs /dev/${MD}s2
|
||||
|
||||
# Create UFS filesystem on partition a
|
||||
newfs -U /dev/${MD}s1a
|
||||
newfs -U /dev/${MD}s2a
|
||||
|
||||
# Mount the new filesystem
|
||||
MOUNT_POINT="${CACHE_DIR}/mnt"
|
||||
mkdir -p "$MOUNT_POINT"
|
||||
mount /dev/${MD}s1a "$MOUNT_POINT"
|
||||
echo " Mounted /dev/${MD}s1a at ${MOUNT_POINT}"
|
||||
mount /dev/${MD}s2a "$MOUNT_POINT"
|
||||
echo " Mounted /dev/${MD}s2a at ${MOUNT_POINT}"
|
||||
|
||||
# Mount memstick read-only to extract base system
|
||||
MEMSTICK_MNT="${CACHE_DIR}/memstick-src"
|
||||
|
|
@ -684,7 +718,8 @@ if [ ! -f "$WORK_IMG" ]; then
|
|||
cleanup_memstick_rootfs "$MEMSTICK_MNT"
|
||||
rm -rf "$MEMSTICK_MNT"
|
||||
|
||||
install_image_bootcode "$MD" "$MOUNT_POINT"
|
||||
install_image_bootcode "$MD" "$MOUNT_POINT" "2"
|
||||
install_image_uefi_bootcode "$MD" "$MOUNT_POINT" "1"
|
||||
|
||||
# Store MD device for later cleanup
|
||||
echo "$MD" > "${CACHE_DIR}/.md_device"
|
||||
|
|
@ -695,8 +730,15 @@ else
|
|||
|
||||
MOUNT_POINT="${CACHE_DIR}/mnt"
|
||||
mkdir -p "$MOUNT_POINT"
|
||||
mount /dev/${MD}s1a "$MOUNT_POINT"
|
||||
echo " Mounted /dev/${MD}s1a at ${MOUNT_POINT}"
|
||||
if [ -e "/dev/${MD}s2a" ]; then
|
||||
ROOT_PART="/dev/${MD}s2a"
|
||||
ROOT_SLICE_INDEX="2"
|
||||
else
|
||||
ROOT_PART="/dev/${MD}s1a"
|
||||
ROOT_SLICE_INDEX="1"
|
||||
fi
|
||||
mount "$ROOT_PART" "$MOUNT_POINT"
|
||||
echo " Mounted ${ROOT_PART} at ${MOUNT_POINT}"
|
||||
|
||||
# Check if base system is missing and extract if needed
|
||||
if [ ! -d "$MOUNT_POINT/etc" ]; then
|
||||
|
|
@ -713,7 +755,10 @@ else
|
|||
cleanup_memstick_rootfs "$MEMSTICK_MNT"
|
||||
rm -rf "$MEMSTICK_MNT"
|
||||
|
||||
install_image_bootcode "$MD" "$MOUNT_POINT"
|
||||
install_image_bootcode "$MD" "$MOUNT_POINT" "$ROOT_SLICE_INDEX"
|
||||
if [ "$ROOT_SLICE_INDEX" = "2" ]; then
|
||||
install_image_uefi_bootcode "$MD" "$MOUNT_POINT" "1"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Store MD device for later cleanup
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue