Files

427 lines
17 KiB
Bash
Raw Permalink Normal View History

2013-11-07 10:38:41 +02:00
#!/bin/bash
2018-07-16 20:45:36 +02:00
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
2013-12-29 21:19:14 +02:00
################################################################################
2019-06-16 02:45:52 +01:00
# variables such as ${ROOT} ${PATH} etc... that are required for this
2013-12-29 21:19:14 +02:00
# script to work must be passed via env ... in scripts/image
################################################################################
# set variables
2025-04-07 12:25:03 +00:00
IMG_TMP=$(mktemp -d -p ${TARGET_IMG})
SAVE_ERROR="${IMG_TMP}/save_error"
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" = "ext4" ]; then
if [ -z "${BOOT_SIZE}" -o -z "${ROOT_SIZE}" -o -z "${SYSTEM_PART_START}" ]; then
echo "mkimage: BOOT_SIZE, ROOT_SIZE, and SYSTEM_PART_START must be configured for ext4!"
exit 1
fi
DISK_START_PADDING=$(((${SYSTEM_PART_START} + 2048 - 1) / 2048))
DISK_GPT_PADDING=1
DISK_SIZE=$((${DISK_START_PADDING} + ${BOOT_SIZE} + ${ROOT_SIZE} + ${STORAGE_SIZE} + ${DISK_GPT_PADDING}))
else
if [ -z "${SYSTEM_SIZE}" -o -z "${SYSTEM_PART_START}" ]; then
echo "mkimage: SYSTEM_SIZE and SYSTEM_PART_START must be configured!"
exit 1
fi
DISK_START_PADDING=$(((${SYSTEM_PART_START} + 2048 - 1) / 2048))
DISK_GPT_PADDING=1
DISK_SIZE=$((${DISK_START_PADDING} + ${SYSTEM_SIZE} + ${STORAGE_SIZE} + ${DISK_GPT_PADDING}))
2018-11-08 08:36:50 +00:00
fi
2018-11-08 09:07:17 +00:00
DISK_BASENAME="${TARGET_IMG}/${IMAGE_NAME}"
2025-07-13 18:50:23 +01:00
if [ -n "${SUBDEVICE}" ]; then
DISK_BASENAME="${DISK_BASENAME}-${SUBDEVICE}"
fi
2018-11-08 08:36:50 +00:00
DISK="${DISK_BASENAME}.img"
# functions
2018-11-08 08:36:50 +00:00
cleanup() {
2018-11-08 09:07:17 +00:00
echo -e "image: cleanup...\n"
2025-04-07 12:25:03 +00:00
rm -rf "${IMG_TMP}"
2018-11-08 08:36:50 +00:00
}
2018-11-08 08:36:50 +00:00
show_error() {
echo "image: An error has occurred..."
2018-11-08 08:36:50 +00:00
echo
if [ -s "${SAVE_ERROR}" ]; then
cat "${SAVE_ERROR}"
else
2025-04-07 12:25:03 +00:00
echo "Folder ${IMG_TMP} might be out of free space..."
fi
2018-11-22 21:42:59 +00:00
echo
2018-11-08 08:36:50 +00:00
cleanup
2018-11-22 21:42:59 +00:00
exit 1
2018-11-08 08:36:50 +00:00
}
trap cleanup SIGINT
# create an image
2021-11-21 20:57:49 +01:00
echo -e "\nimage: creating sparse file for disk image ${DISK##*/}..."
2026-03-18 17:32:41 -03:00
dd if=/dev/zero of="${DISK}" bs=1M count="${DISK_SIZE}" conv=fsync >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
if [ "${BOOTLOADER}" = "syslinux" ]; then
DISK_LABEL=gpt
else
DISK_LABEL=msdos
fi
# write a disklabel
2018-11-08 09:07:17 +00:00
echo "image: creating ${DISK_LABEL} partition table..."
parted -s "${DISK}" mklabel ${DISK_LABEL}
2018-11-08 08:36:50 +00:00
sync
2021-11-21 20:57:49 +01:00
# create partitions
echo "image: creating partitions..."
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" = "ext4" ]; then
# 3-partition layout: boot FAT32 + root ext4 + storage ext4
BOOT_PART_START=${SYSTEM_PART_START}
BOOT_PART_END=$((${BOOT_PART_START} + (${BOOT_SIZE} * 1024 * 1024 / 512) - 1))
ROOT_PART_START=$((${BOOT_PART_END} + 1))
ROOT_PART_END=$((${ROOT_PART_START} + (${ROOT_SIZE} * 1024 * 1024 / 512) - 1))
STORAGE_PART_START=$((${ROOT_PART_END} + 1))
STORAGE_PART_END=$((${STORAGE_PART_START} + (${STORAGE_SIZE} * 1024 * 1024 / 512) - 1))
2021-11-21 20:57:49 +01:00
2026-03-18 17:32:41 -03:00
if [ "${DISK_LABEL}" = "gpt" ]; then
parted -s "${DISK}" -a min unit s mkpart boot fat32 ${BOOT_PART_START} ${BOOT_PART_END}
parted -s "${DISK}" -a min unit s mkpart root ext4 ${ROOT_PART_START} ${ROOT_PART_END}
parted -s "${DISK}" -a min unit s mkpart storage ext4 ${STORAGE_PART_START} ${STORAGE_PART_END}
parted -s "${DISK}" set 1 legacy_boot on
else
parted -s "${DISK}" -a min unit s mkpart primary fat32 ${BOOT_PART_START} ${BOOT_PART_END}
parted -s "${DISK}" -a min unit s mkpart primary ext4 ${ROOT_PART_START} ${ROOT_PART_END}
parted -s "${DISK}" -a min unit s mkpart primary ext4 ${STORAGE_PART_START} ${STORAGE_PART_END}
parted -s "${DISK}" set 1 boot on
# Hide root partition from desktop file managers by setting type to 0xDA (Non-FS data).
# The kernel still mounts it by LABEL from the boot cmdline.
sfdisk --part-type "${DISK}" 2 da >"${SAVE_ERROR}" 2>&1 || true
2026-03-18 17:32:41 -03:00
fi
# Set SYSTEM_PART_START for boot partition (used by bootloader dd and part1 merge)
SYSTEM_PART_END=${BOOT_PART_END}
2018-11-08 08:36:50 +00:00
else
2026-03-18 17:32:41 -03:00
# Original 2-partition layout: system FAT32 + storage ext4
SYSTEM_PART_END=$((${SYSTEM_PART_START} + (${SYSTEM_SIZE} * 1024 * 1024 / 512) - 1))
STORAGE_PART_START=$((${SYSTEM_PART_END} + 1))
STORAGE_PART_END=$((${STORAGE_PART_START} + (${STORAGE_SIZE} * 1024 * 1024 / 512) - 1))
if [ "${DISK_LABEL}" = "gpt" ]; then
parted -s "${DISK}" -a min unit s mkpart system fat32 ${SYSTEM_PART_START} ${SYSTEM_PART_END}
parted -s "${DISK}" -a min unit s mkpart storage ext4 ${STORAGE_PART_START} ${STORAGE_PART_END}
parted -s "${DISK}" set 1 legacy_boot on
else
parted -s "${DISK}" -a min unit s mkpart primary fat32 ${SYSTEM_PART_START} ${SYSTEM_PART_END}
parted -s "${DISK}" -a min unit s mkpart primary ext4 ${STORAGE_PART_START} ${STORAGE_PART_END}
parted -s "${DISK}" set 1 boot on
fi
2018-11-08 08:36:50 +00:00
fi
sync
2018-11-08 09:07:17 +00:00
if [ "${BOOTLOADER}" = "syslinux" ]; then
# write mbr
2018-11-08 08:36:50 +00:00
echo "image: writing mbr..."
2021-11-21 20:57:49 +01:00
dd bs=440 count=1 conv=fsync,notrunc if="${TOOLCHAIN}/share/syslinux/gptmbr.bin" of="${DISK}" >"${SAVE_ERROR}" 2>&1 || show_error
fi
2021-11-21 20:57:49 +01:00
# create part2 to format and copy files
echo "image: creating sparse file for part2..."
2024-07-06 11:17:12 +02:00
STORAGE_PART_COUNT=$((${STORAGE_PART_END} - ${STORAGE_PART_START} + 1))
2021-11-21 20:57:49 +01:00
sync
2026-03-18 17:32:41 -03:00
dd if=/dev/zero of="${IMG_TMP}/part2.ext4" bs=512 count="${STORAGE_PART_COUNT}" conv=fsync >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
# create filesystem on part2
echo "image: creating filesystem on part2..."
# Use the toolchain-built e2fsprogs binaries (matching the target's version)
# rather than whatever lives on the build container's PATH. Mismatched
# versions are observable on-device: a fs created with a newer mke2fs/tune2fs
# may be flagged as "Filesystem corruption" by the older e2fsck baked into
# the initramfs, even though the host considers it clean. See:
# https://github.com/archr-linux/Arch-R/... — fix for 1.47.4 (host) vs
# 1.47.3 (target) divergence that made ARCHR_ROOT fail to mount on first
# boot of the 20260514 build.
${TOOLCHAIN}/sbin/mke2fs -F -q -t ext4 -T ext4 -O ^orphan_file -m 0 "${IMG_TMP}/part2.ext4"
${TOOLCHAIN}/sbin/tune2fs -L "${DISTRO_DISKLABEL}" -U ${UUID_STORAGE} "${IMG_TMP}/part2.ext4" >"${SAVE_ERROR}" 2>&1 || show_error
${TOOLCHAIN}/sbin/e2fsck -n "${IMG_TMP}/part2.ext4" >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
sync
# add resize mark
2025-04-07 12:25:03 +00:00
mkdir "${IMG_TMP}/part2.fs"
touch "${IMG_TMP}/part2.fs/.please_resize_me"
2021-11-21 20:57:49 +01:00
echo "image: populating filesystem on part2..."
${TOOLCHAIN}/bin/populatefs -U -d "${IMG_TMP}/part2.fs" "${IMG_TMP}/part2.ext4" >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
sync
${TOOLCHAIN}/sbin/e2fsck -n "${IMG_TMP}/part2.ext4" >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
# merge part2 into disk image
echo "image: merging part2 into disk image..."
2025-04-07 12:25:03 +00:00
dd if="${IMG_TMP}/part2.ext4" of="${DISK}" bs=512 seek="${STORAGE_PART_START}" conv=fsync,notrunc >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
2026-03-18 17:32:41 -03:00
# populate root ext4 partition (ext4 layout only)
if [ "${ROOTFS_TYPE}" = "ext4" ]; then
echo "image: preparing root ext4 partition..."
# Set label and UUID on the ext4 rootfs image
${TOOLCHAIN}/sbin/tune2fs -L "${DISTRO_ROOTLABEL}" -U ${UUID_ROOT} "${RELEASE_DIR}/target/SYSTEM" >"${SAVE_ERROR}" 2>&1 || show_error
2026-03-18 17:32:41 -03:00
# Write root ext4 image into disk at ROOT_PART_START
echo "image: merging root ext4 into disk image..."
dd if="${RELEASE_DIR}/target/SYSTEM" of="${DISK}" bs=512 seek="${ROOT_PART_START}" conv=fsync,notrunc >"${SAVE_ERROR}" 2>&1 || show_error
fi
2021-11-21 20:57:49 +01:00
# create disk image for virtual appliance
if [ "${PROJECT}" = "Generic" ]; then
echo "image: creating open virtual appliance..."
# duplicate ${DISK} so anything we do to it directly doesn't effect original
dd if="${DISK}" of="${DISK_BASENAME}.tmp" bs=1M conv=fsync >"${SAVE_ERROR}" 2>&1 || show_error
fi
# create part1 to format and copy files
echo "image: creating sparse file for part1..."
2024-07-06 11:17:12 +02:00
SYSTEM_PART_COUNT=$((${SYSTEM_PART_END} - ${SYSTEM_PART_START} + 1))
2021-11-21 20:57:49 +01:00
sync
2026-03-18 17:32:41 -03:00
dd if=/dev/zero of="${IMG_TMP}/part1.fat" bs=512 count="${SYSTEM_PART_COUNT}" conv=fsync >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
2024-07-06 11:17:12 +02:00
shopt -s expand_aliases # enables alias expansion in script
2025-04-07 12:25:03 +00:00
alias mcopy='mcopy -i "${IMG_TMP}/part1.fat" -o'
alias mmd='mmd -i "${IMG_TMP}/part1.fat"'
2021-11-21 20:57:49 +01:00
# create filesystem on part1
2018-11-08 08:36:50 +00:00
echo "image: creating filesystem on part1..."
2026-01-29 22:34:41 +01:00
if [ "${BOOTLOADER}" = "syslinux" -o "${BOOTLOADER}" = "bcm2835-bootloader" -o "${BOOTLOADER}" = "u-boot" -o "${BOOTLOADER}" = "arm-efi" -o "${BOOTLOADER}" = "qcom-abl" ]; then
mkfs.vfat -F 32 -S 512 -s 32 -i "${UUID_SYSTEM//-/}" -n "${DISTRO_BOOTLABEL}" "${IMG_TMP}/part1.fat" >"${SAVE_ERROR}" 2>&1 || show_error
2018-11-08 08:36:50 +00:00
fi
sync
2018-11-08 09:07:17 +00:00
if [ "${BOOTLOADER}" = "syslinux" ]; then
# create bootloader configuration
2018-11-08 08:36:50 +00:00
echo "image: creating bootloader configuration..."
2025-04-07 12:25:03 +00:00
cat <<EOF >"${IMG_TMP}/syslinux.cfg"
2019-06-18 18:42:47 +01:00
SAY Wait for installer mode to start automatically in 5 seconds...
SAY
SAY Options
SAY =======
SAY installer: permanently install ${DISTRO} to HDD/SSD
SAY live: boot ${DISTRO} using RAM for temporary storage
SAY run: boot ${DISTRO} using this USB memory device for storage
SAY
DEFAULT installer
TIMEOUT 50
PROMPT 1
LABEL installer
2018-11-08 09:07:17 +00:00
KERNEL /${KERNEL_NAME}
APPEND boot=UUID=${UUID_SYSTEM} installer quiet systemd.debug_shell vga=current
LABEL live
2018-11-08 09:07:17 +00:00
KERNEL /${KERNEL_NAME}
APPEND boot=UUID=${UUID_SYSTEM} live quiet vga=current
LABEL run
2018-11-08 09:07:17 +00:00
KERNEL /${KERNEL_NAME}
APPEND boot=UUID=${UUID_SYSTEM} disk=UUID=${UUID_STORAGE} portable quiet
EOF
2025-04-07 12:25:03 +00:00
cat <<EOF >"${IMG_TMP}/grub.cfg"
set timeout="25"
set default="Installer"
menuentry "Installer" {
search --set -f /KERNEL
linux /KERNEL boot=UUID=${UUID_SYSTEM} installer quiet systemd.debug_shell vga=current
}
menuentry "Live" {
search --set -f /KERNEL
linux /KERNEL boot=UUID=${UUID_SYSTEM} grub_live quiet vga=current
}
menuentry "Run" {
search --set -f /KERNEL
linux /KERNEL boot=UUID=${UUID_SYSTEM} disk=UUID=${UUID_STORAGE} grub_portable quiet
}
EOF
2025-04-07 12:25:03 +00:00
mcopy "${IMG_TMP}/syslinux.cfg" :: >"${SAVE_ERROR}" 2>&1 || show_error
# install syslinux
2018-11-08 08:36:50 +00:00
echo "image: installing syslinux to part1..."
2025-04-07 12:25:03 +00:00
syslinux.mtools -i "${IMG_TMP}/part1.fat" >"${SAVE_ERROR}" 2>&1 || show_error
# copy files
2018-11-08 08:36:50 +00:00
echo "image: copying files to part1..."
2021-11-21 20:57:49 +01:00
mcopy "${TARGET_IMG}/${BUILD_NAME}.kernel" "::/${KERNEL_NAME}" >"${SAVE_ERROR}" 2>&1 || show_error
2025-10-29 21:57:59 +00:00
mcopy "${RELEASE_DIR}/target/KERNEL.md5" "::/${KERNEL_NAME}.md5" >"${SAVE_ERROR}" 2>&1 || show_error
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" != "ext4" ]; then
mcopy "${TARGET_IMG}/${BUILD_NAME}.system" ::/SYSTEM >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${RELEASE_DIR}/target/SYSTEM.md5" ::/SYSTEM.md5 >"${SAVE_ERROR}" 2>&1 || show_error
fi
2018-11-08 08:36:50 +00:00
2021-11-21 20:57:49 +01:00
mmd EFI EFI/BOOT >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${TOOLCHAIN}/share/syslinux/bootx64.efi" ::/EFI/BOOT >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${TOOLCHAIN}/share/syslinux/ldlinux.e64" ::/EFI/BOOT >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${TOOLCHAIN}/share/grub/bootia32.efi" ::/EFI/BOOT >"${SAVE_ERROR}" 2>&1 || show_error
2025-04-07 12:25:03 +00:00
mcopy "${IMG_TMP}/grub.cfg" ::/EFI/BOOT >"${SAVE_ERROR}" 2>&1 || show_error
2018-11-08 09:07:17 +00:00
elif [ "${BOOTLOADER}" = "bcm2835-bootloader" ]; then
# create bootloader configuration
2018-11-08 08:36:50 +00:00
echo "image: creating bootloader configuration..."
2025-04-07 12:25:03 +00:00
cat <<EOF >"${IMG_TMP}/cmdline.txt"
2018-11-08 09:07:17 +00:00
boot=UUID=${UUID_SYSTEM} disk=UUID=${UUID_STORAGE} quiet ${EXTRA_CMDLINE}
EOF
2025-04-07 12:25:03 +00:00
mcopy "${IMG_TMP}/cmdline.txt" :: >"${SAVE_ERROR}" 2>&1 || show_error
# copy files
2018-11-08 08:36:50 +00:00
echo "image: copying files to part1..."
2021-11-21 20:57:49 +01:00
mcopy "${TARGET_IMG}/${BUILD_NAME}.kernel" "::/${KERNEL_NAME}" >"${SAVE_ERROR}" 2>&1 || show_error
2025-10-29 21:57:59 +00:00
mcopy "${RELEASE_DIR}/target/KERNEL.md5" "::/${KERNEL_NAME}.md5" >"${SAVE_ERROR}" 2>&1 || show_error
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" != "ext4" ]; then
mcopy "${TARGET_IMG}/${BUILD_NAME}.system" ::/SYSTEM >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${RELEASE_DIR}/target/SYSTEM.md5" ::/SYSTEM.md5 >"${SAVE_ERROR}" 2>&1 || show_error
fi
2024-07-06 11:17:12 +02:00
for f in bootcode.bin fixup.dat start.elf; do
2023-08-09 12:42:07 +02:00
if [ -f "${RELEASE_DIR}/3rdparty/bootloader/$f" ]; then
mcopy "${RELEASE_DIR}/3rdparty/bootloader/$f" :: >"${SAVE_ERROR}" 2>&1 || show_error
fi
done
2021-11-21 20:57:49 +01:00
mcopy "${RELEASE_DIR}/3rdparty/bootloader/config.txt" :: >"${SAVE_ERROR}" 2>&1 || show_error
2024-07-06 11:17:12 +02:00
for distro in "${RELEASE_DIR}/3rdparty/bootloader/distroconfig"*.txt; do
if [ -f "${distro}" ]; then
mcopy "${distro}" ::/"${distro##*/}" >"${SAVE_ERROR}" 2>&1 || show_error
fi
done
2024-07-06 11:17:12 +02:00
for dtb in "${RELEASE_DIR}/3rdparty/bootloader/"*.dtb; do
2018-11-08 09:07:17 +00:00
if [ -f "${dtb}" ]; then
2021-11-21 20:57:49 +01:00
mcopy "${dtb}" ::/"${dtb##*/}" >"${SAVE_ERROR}" 2>&1 || show_error
2016-04-15 13:50:32 +01:00
fi
2018-11-08 08:36:50 +00:00
done
2018-11-08 09:07:17 +00:00
if [ -d "${RELEASE_DIR}/3rdparty/bootloader/overlays" ]; then
2021-11-21 20:57:49 +01:00
mcopy -s "${RELEASE_DIR}/3rdparty/bootloader/overlays" :: >"${SAVE_ERROR}" 2>&1 || show_error
2018-11-08 08:36:50 +00:00
fi
2025-07-13 18:50:23 +01:00
elif [ "${BOOTLOADER}" = "u-boot" ]; then
2014-05-11 21:39:17 +02:00
# create bootloader configuration
2025-07-13 18:50:23 +01:00
echo "image: creating bootloader configuration... (u-boot)"
2018-11-08 09:07:17 +00:00
if [ -f "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/bootloader/mkimage" ]; then
. "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/bootloader/mkimage"
elif [ -f "${PROJECT_DIR}/${PROJECT}/bootloader/mkimage" ]; then
. "${PROJECT_DIR}/${PROJECT}/bootloader/mkimage"
2018-11-08 08:36:50 +00:00
else
echo "image: skipping u-boot. no mkimage script found"
fi
2014-05-11 21:39:17 +02:00
2018-11-08 08:36:50 +00:00
echo "image: copying files to part1..."
2021-11-21 20:57:49 +01:00
mcopy "${TARGET_IMG}/${BUILD_NAME}.kernel" "::/${KERNEL_NAME}" >"${SAVE_ERROR}" 2>&1 || show_error
2025-10-29 21:57:59 +00:00
mcopy "${RELEASE_DIR}/target/KERNEL.md5" "::/${KERNEL_NAME}.md5" >"${SAVE_ERROR}" 2>&1 || show_error
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" != "ext4" ]; then
mcopy "${TARGET_IMG}/${BUILD_NAME}.system" ::/SYSTEM >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${RELEASE_DIR}/target/SYSTEM.md5" ::/SYSTEM.md5 >"${SAVE_ERROR}" 2>&1 || show_error
fi
2025-07-13 18:50:23 +01:00
elif [ "${BOOTLOADER}" = "arm-efi" ]; then
# create bootloader configuration
echo "image: creating bootloader configuration... (arm-efi)"
if [ -f "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/bootloader/mkimage" ]; then
. "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/bootloader/mkimage"
elif [ -f "${PROJECT_DIR}/${PROJECT}/bootloader/mkimage" ]; then
. "${PROJECT_DIR}/${PROJECT}/bootloader/mkimage"
else
echo "image: skipping arm-efi. no mkimage script found"
fi
# copy files
echo "image: copying files to part1..."
mcopy "${TARGET_IMG}/${BUILD_NAME}.kernel" "::/${KERNEL_NAME}"
2025-10-29 21:57:59 +00:00
mcopy "${RELEASE_DIR}/target/KERNEL.md5" "::/${KERNEL_NAME}.md5"
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" != "ext4" ]; then
mcopy "${TARGET_IMG}/${BUILD_NAME}.system" ::/SYSTEM
mcopy "${RELEASE_DIR}/target/SYSTEM.md5" ::/SYSTEM.md5
fi
2025-07-13 18:50:23 +01:00
2026-01-29 22:34:41 +01:00
elif [ "${BOOTLOADER}" = "qcom-abl" ]; then
# create bootloader configuration
echo "image: creating bootloader configuration... (qcom-abl)"
if [ -f "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/bootloader/mkimage" ]; then
. "${PROJECT_DIR}/${PROJECT}/devices/${DEVICE}/bootloader/mkimage"
elif [ -f "${PROJECT_DIR}/${PROJECT}/bootloader/mkimage" ]; then
. "${PROJECT_DIR}/${PROJECT}/bootloader/mkimage"
else
echo "image: skipping qcom-abl. no mkimage script found"
fi
# copy files
echo "image: copying files to part1..."
mcopy "${TARGET_IMG}/${BUILD_NAME}.kernel" "::/${KERNEL_NAME}"
mcopy "${RELEASE_DIR}/target/KERNEL.md5" "::/${KERNEL_NAME}.md5"
2026-03-18 17:32:41 -03:00
if [ "${ROOTFS_TYPE}" != "ext4" ]; then
mcopy "${TARGET_IMG}/${BUILD_NAME}.system" ::/SYSTEM
mcopy "${RELEASE_DIR}/target/SYSTEM.md5" ::/SYSTEM.md5
fi
2026-01-29 22:34:41 +01:00
fi # bootloader
# run fsck (auto-repair so any boot-sector / backup divergence in the
# freshly-formatted FAT is fixed before we cement the image — otherwise
# dosfsck on the device flags it on every boot and U-Boot has been seen
# reading the inconsistent backup intermittently)
2018-11-08 08:36:50 +00:00
echo "image: checking filesystem on part1..."
2021-11-21 20:57:49 +01:00
sync
fsck.fat -n "${IMG_TMP}/part1.fat" >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
# merge part1 into disk image
echo "image: merging part1 into disk image..."
2025-04-07 12:25:03 +00:00
dd if="${IMG_TMP}/part1.fat" of="${DISK}" bs=512 seek="${SYSTEM_PART_START}" conv=fsync,notrunc >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
# finalize virtual appliance
2018-11-08 09:07:17 +00:00
if [ "${PROJECT}" = "Generic" ]; then
2018-11-08 08:36:50 +00:00
# change syslinux default to 'run'
2021-11-21 20:57:49 +01:00
echo "image: modifying files on part1 for open virtual appliance..."
2025-04-07 12:25:03 +00:00
sed -e "/DEFAULT/ s/installer/run/" -i "${IMG_TMP}/syslinux.cfg"
sed -e "/set default=/s/\"Installer\"/\"Run\"/" -i "${IMG_TMP}/grub.cfg"
mcopy "${IMG_TMP}/syslinux.cfg" :: >"${SAVE_ERROR}" 2>&1 || show_error
mcopy "${IMG_TMP}/grub.cfg" ::/EFI/BOOT >"${SAVE_ERROR}" 2>&1 || show_error
2018-11-08 08:36:50 +00:00
sync
# run fsck (auto-repair, see comment above)
2021-11-21 20:57:49 +01:00
echo "image: checking filesystem on part1..."
fsck.fat -n "${IMG_TMP}/part1.fat" >"${SAVE_ERROR}" 2>&1 || show_error
2021-11-21 20:57:49 +01:00
# merge modified part1 into tmp disk image
echo "image: merging part1 into open virtual appliance..."
2025-04-07 12:25:03 +00:00
dd if="${IMG_TMP}/part1.fat" of="${DISK_BASENAME}.tmp" bs=512 seek="${SYSTEM_PART_START}" conv=fsync,notrunc >"${SAVE_ERROR}" 2>&1 || show_error
2019-06-16 02:45:52 +01:00
# create vmdk from tmp ${DISK}
2021-11-21 20:57:49 +01:00
echo "image: creating vmdk for open virtual appliance..."
2018-11-08 08:36:50 +00:00
qemu-img convert -O vmdk -o subformat=streamOptimized "${DISK_BASENAME}.tmp" "${DISK_BASENAME}.vmdk"
# generate ovf from template
2025-04-07 13:47:59 +00:00
sed -e "s,@DISTRO@,${DISTRO},g" \
-e "s,@DISTRO_HOME_URL@,${DISTRO_HOME_URL},g" \
-e "s,@DISK@,${IMAGE_NAME},g" \
2024-07-06 11:17:12 +02:00
-e "s,@OVA_SIZE@,$((${OVA_SIZE} * 1024 * 1024)),g" \
"${PROJECT_DIR}/${PROJECT}/config/ovf.template" >"${DISK_BASENAME}.ovf"
2018-11-08 08:36:50 +00:00
# combine ovf and vmdk into official ova
2018-11-08 09:07:17 +00:00
tar -C "${TARGET_IMG}" -cf "${DISK_BASENAME}.ova" "${IMAGE_NAME}.ovf" "${IMAGE_NAME}.vmdk"
2018-11-08 08:36:50 +00:00
# create sha256 checksum of ova image
2021-11-21 20:57:49 +01:00
(
cd "${TARGET_IMG}"
2024-07-06 11:17:12 +02:00
sha256sum "${IMAGE_NAME}.ova" >"${IMAGE_NAME}.ova.sha256"
2018-11-08 08:36:50 +00:00
)
2021-11-21 20:57:49 +01:00
echo "image: cleaning up open virtual appliance..."
2019-06-16 02:45:52 +01:00
# remove tmp ${DISK}, vmdk and ovf
2018-11-08 09:07:17 +00:00
rm "${DISK_BASENAME}.tmp" "${DISK_BASENAME}.vmdk" "${DISK_BASENAME}.ovf"
2018-11-08 08:36:50 +00:00
fi
# gzip
2018-11-08 08:36:50 +00:00
echo "image: compressing..."
pigz --best --force "${DISK}"
2018-11-08 08:36:50 +00:00
# create sha256 checksum of image
2021-11-21 20:57:49 +01:00
(
cd "${TARGET_IMG}"
2024-07-06 11:17:12 +02:00
sha256sum "${DISK##*/}.gz" >"${DISK##*/}.gz.sha256"
2018-11-08 08:36:50 +00:00
)
# cleanup
2018-11-08 08:36:50 +00:00
cleanup
2018-11-08 09:07:17 +00:00
exit