From 330f86648b6ef5709c7ff2839255b89c0c771a2a Mon Sep 17 00:00:00 2001 From: Dongjin Kim Date: Mon, 8 Jan 2024 17:43:32 +0900 Subject: [PATCH] functions: add to build with extra space Extra space in partitions can be defined in '/custom/*/partitions' by adding symbols 'EXTRA__SIZE' with size in MBytes EXTRA_BOOT_SIZE=128 EXTRA_ROOT_SIZE=256 Signed-off-by: Dongjin Kim Change-Id: I08f0daae5abc12857986d29bb58a18afb40c1ee7 --- fdiskcmd.sh | 1 + functions | 39 ++++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/fdiskcmd.sh b/fdiskcmd.sh index b64cce3..7764c97 100755 --- a/fdiskcmd.sh +++ b/fdiskcmd.sh @@ -4,6 +4,7 @@ . ${1} do_fdisk_commands() { + [ ! -z ${TOTAL_SECTORS} ] || return TOTAL=0 for (( p = 0 ; p < ${#PART[@]} ; p++ )); do diff --git a/functions b/functions index eca9cda..81de7fd 100644 --- a/functions +++ b/functions @@ -297,15 +297,35 @@ do_create_partition() { local boot_blk=$((${2} * 1024 * 1024 / 512 - 1)) local root_blk=$(($(du -s --block-size=512 ${rootfs_mnt} | cut -f1) * 12 / 10)) local boot_pstart=$(get_reserved_sectors) + local fdiskcmd="" [ "x${boot_pstart}" = "x" ] && boot_pstart=2048 + if [ -f ${TOPDIR}/custom/${CUSTOMOS}/partitions ]; then + echo ${TOPDIR}/custom/${CUSTOMOS}/partitions + . ${TOPDIR}/custom/${CUSTOMOS}/partitions + + if [ ! -z ${TOTAL_SECTORS} ]; then + fdiskcmd=$(${TOPDIR}/fdiskcmd.sh ${TOPDIR}/custom/${CUSTOMOS}/partitions) + fi + fi + + if [ ! -z ${EXTRA_BOOT_SIZE} ]; then + blks=$((${EXTRA_BOOT_SIZE} * 1024 * 1024 / 512 - 1)) + boot_blk=$((${boot_blk} + ${blks})) + fi + if [ ! -z ${EXTRA_ROOT_SIZE} ]; then + blks=$((${EXTRA_ROOT_SIZE} * 1024 * 1024 / 512 - 1)) + root_blk=$((${root_blk} + ${blks})) + fi + local boot_size=$((${boot_pstart} + ${boot_blk})) local blocks=$((${boot_pstart} + ${boot_blk} + ${root_blk})) - if [ -f ${TOPDIR}/custom/${CUSTOMOS}/partitions ]; then - . ${TOPDIR}/custom/${CUSTOMOS}/partitions - blocks=${TOTAL_SECTORS} + blocks=${TOTAL_SECTORS:-${blocks}} + + if [ "x${fdiskcmd}" = "x" ]; then + fdiskcmd="n\np\n\n${boot_pstart}\n${boot_size}\nn\np\n\n$((${boot_size} + 1))\n\nw\n" fi if [ ! -b ${disk} ]; then @@ -325,16 +345,9 @@ do_create_partition() { [ "${BASH_VERSION}" = "" ] || BACKSLASH_ESCAPE="-e" echo "I: creating a partition table to '${disk}'" - if [ -f ${TOPDIR}/custom/${CUSTOMOS}/partitions ]; then - echo ${BACKSLASH_ESCAPE} \ - $(${TOPDIR}/fdiskcmd.sh ${TOPDIR}/custom/${CUSTOMOS}/partitions) \ - | fdisk ${disk} >/dev/null - fi - - echo ${BACKSLASH_ESCAPE} \ - "n\np\n\n${boot_pstart}\n${boot_size}\n" \ - "n\np\n\n$((${boot_size} + 1))\n\n" \ - "w\n" | fdisk ${disk} >/dev/null + echo fdiskcmd=${fdiskcmd} + echo ${BACKSLASH_ESCAPE} ${fdiskcmd} | fdisk ${disk} \ + || panic "failed to create partition table" >/dev/null partprobe if [ ! -b ${disk} ]; then