mirror of
https://github.com/home-assistant/operating-system.git
synced 2026-07-08 23:43:46 +01:00
2cd8cf450d
Borrow shrinking used in home-assistant/operating-system-full-images for reducing the data partition size to only fit its contents. Currently the data partition is intentionally overprovisioned to comfortably fit all docker images in the hassio build. This results in unnecessarily large image which takes longer to flash, as all the zeroes at the end of the filesystem need to be written to the SD card. For OVA and aarch64 VM formats, the image is resized before creating the VM images - this also makes all generic-aarch64 images sized to 32GB, unlike 6GB which inherently needed resizing before use. Some juggling extra juggling is needed in the aarch64 post-image step, as we want to preserve the raw image (e.g. for generic aarch64 boards) but it's desirable to keep it minimal as well, as it's meant to be flashed to real hardware storage.
112 lines
3.4 KiB
Bash
Executable File
112 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
BOOTSTATE_SIZE=8M
|
|
SYSTEM_SIZE=256M
|
|
KERNEL_SIZE=24M
|
|
OVERLAY_SIZE=96M
|
|
|
|
function create_disk_image() {
|
|
if [ -f "${BOARD_DIR}/genimage.cfg" ]; then
|
|
echo "Using custom genimage.cfg from ${BOARD_DIR}"
|
|
else
|
|
echo "Using default genimage.cfg"
|
|
fi
|
|
|
|
export GENIMAGE_INPUTPATH="${BINARIES_DIR}"
|
|
export GENIMAGE_OUTPUTPATH="${BINARIES_DIR}"
|
|
export GENIMAGE_TMPPATH="${BUILD_DIR}/genimage.tmp"
|
|
|
|
# variables from meta file
|
|
export DISK_SIZE BOOTLOADER KERNEL_FILE PARTITION_TABLE_TYPE BOOT_SIZE BOOT_SPL BOOT_SPL_SIZE
|
|
# variables used in raucb manifest template
|
|
ota_compatible="$(haos_rauc_compatible)"
|
|
ota_version="$(haos_version)"
|
|
export ota_compatible ota_version
|
|
# variables used in genimage configs
|
|
export BOOTSTATE_SIZE SYSTEM_SIZE KERNEL_SIZE OVERLAY_SIZE
|
|
RAUC_MANIFEST=$(tempio -template "${BR2_EXTERNAL_HAOS_PATH}/ota/manifest.raucm.gtpl")
|
|
IMAGE_NAME="$(haos_image_basename)"
|
|
BOOT_SPL_TYPE=$(test "$BOOT_SPL" == "true" && echo "spl" || echo "nospl")
|
|
export RAUC_MANIFEST IMAGE_NAME BOOT_SPL_TYPE
|
|
SYSTEM_IMAGE=$(path_rootfs_img)
|
|
DATA_IMAGE=$(path_data_img)
|
|
export SYSTEM_IMAGE DATA_IMAGE
|
|
|
|
trap 'rm -rf "${ROOTPATH_TMP}" "${GENIMAGE_TMPPATH}"' EXIT
|
|
ROOTPATH_TMP="$(mktemp -d)"
|
|
|
|
rm -rf "${GENIMAGE_TMPPATH}"
|
|
# Generate boot FS image - run in a separate step with specific rootpath
|
|
genimage \
|
|
--rootpath "$(path_boot_dir)" \
|
|
--configdump - \
|
|
--includepath "${BOARD_DIR}:${BR2_EXTERNAL_HAOS_PATH}/genimage" \
|
|
--config images-boot.cfg
|
|
|
|
rm -rf "${GENIMAGE_TMPPATH}"
|
|
# Generate OS image (no files are copied to temporary rootpath here)
|
|
genimage \
|
|
--rootpath "${ROOTPATH_TMP}" \
|
|
--configdump - \
|
|
--includepath "${BOARD_DIR}:${BR2_EXTERNAL_HAOS_PATH}/genimage"
|
|
}
|
|
|
|
function resize_disk_image_virtual() {
|
|
local size="${1}"
|
|
local hdd_img
|
|
hdd_img="$(haos_image_name img)"
|
|
|
|
qemu-img resize -q -f raw "${hdd_img}" "${size}"
|
|
}
|
|
|
|
function convert_disk_image_virtual() {
|
|
local hdd_ext="${1}"
|
|
local hdd_img
|
|
hdd_img="$(haos_image_name img)"
|
|
local hdd_virt
|
|
hdd_virt="$(haos_image_name "${hdd_ext}")"
|
|
local -a qemu_img_opts=()
|
|
|
|
if [ "${hdd_ext}" == "vmdk" ]; then
|
|
qemu_img_opts=("-o" "adapter_type=lsilogic")
|
|
fi
|
|
|
|
rm -f "${hdd_virt}"
|
|
|
|
qemu-img convert -O "${hdd_ext}" "${qemu_img_opts[@]}" "${hdd_img}" "${hdd_virt}"
|
|
}
|
|
|
|
function convert_disk_image_ova() {
|
|
local hdd_img
|
|
hdd_img="$(haos_image_name img)"
|
|
local hdd_ova
|
|
hdd_ova="$(haos_image_name ova)"
|
|
local ova_data="${BINARIES_DIR}/ova"
|
|
|
|
mkdir -p "${ova_data}"
|
|
rm -f "${hdd_ova}"
|
|
|
|
cp -a "${BOARD_DIR}/home-assistant.ovf" "${ova_data}/home-assistant.ovf"
|
|
qemu-img convert -O vmdk -o subformat=streamOptimized,adapter_type=lsilogic "${hdd_img}" "${ova_data}/home-assistant.vmdk"
|
|
(cd "${ova_data}" || exit 1; "${HOST_DIR}/bin/openssl" sha256 home-assistant.* | sed 's/SHA2-256/SHA256/' > home-assistant.mf)
|
|
tar -C "${ova_data}" --owner=root --group=root -cf "${hdd_ova}" home-assistant.ovf home-assistant.vmdk home-assistant.mf
|
|
}
|
|
|
|
function convert_disk_image_xz() {
|
|
local hdd_ext=${1:-img}
|
|
local hdd_img
|
|
hdd_img="$(haos_image_name "${hdd_ext}")"
|
|
|
|
rm -f "${hdd_img}.xz"
|
|
xz -3 -T0 "${hdd_img}"
|
|
}
|
|
|
|
function convert_disk_image_zip() {
|
|
local hdd_ext=${1:-img}
|
|
local hdd_img
|
|
hdd_img="$(haos_image_name "${hdd_ext}")"
|
|
|
|
rm -f "${hdd_img}.zip"
|
|
pigz -q -K -S ".zip" "${hdd_img}"
|
|
}
|