From 3ef2b90cadd8035375625a5f3eaa086741b876d8 Mon Sep 17 00:00:00 2001 From: Pratham Patel Date: Tue, 17 Oct 2023 09:31:43 +0530 Subject: [PATCH] improve partitioning moar --- create-image.sh | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/create-image.sh b/create-image.sh index c95b655..a86c9ec 100755 --- a/create-image.sh +++ b/create-image.sh @@ -17,21 +17,31 @@ done function create_new_image { UBOOT_MAX_SIZE='32' - EFI_END=$(( 256 + UBOOT_MAX_SIZE )) - BOOT_START=$(( EFI_END + 1 )) - BOOT_END=$(( BOOT_START + 1024 )) - ROOT_START=$(( BOOT_END + 1 )) IMAGE_SIZE=$(( $(stat -c '%s' "${IMAGE_NAME}") / 1024 / 1024 )) NEW_IMAGE_NAME="${IMAGE_NAME}.new" truncate -s "$(( IMAGE_SIZE + (UBOOT_MAX_SIZE * 2) ))"MiB "${NEW_IMAGE_NAME}" LOOPBACK_01=$(losetup -f -P --show "${IMAGE_NAME}") LOOPBACK_02=$(losetup -f -P --show "${NEW_IMAGE_NAME}") + UEFI_SECTORS="$(fdisk -l "${LOOPBACK_02}" | grep "${LOOPBACK_02}p1" | awk '{print $4}')" + BOOT_SECTORS="$(fdisk -l "${LOOPBACK_02}" | grep "${LOOPBACK_02}p2" | awk '{print $4}')" - parted -s "${LOOPBACK_02}" -- mklabel gpt - parted -s "${LOOPBACK_02}" -- mkpart rockyefi fat32 "${UBOOT_MAX_SIZE}"MiB "${EFI_END}"MiB - parted -s "${LOOPBACK_02}" -- mkpart rockyboot ext4 "${BOOT_START}"MiB "${BOOT_END}"MiB - parted -s "${LOOPBACK_02}" -- mkpart rockyroot ext4 "${ROOT_START}"MiB 100% + cat << EOF | fdisk "${LOOPBACK_02}" + g + n + 1 + 65536 + +${UEFI_SECTORS} + n + 2 + + +${BOOT_SECTORS} + n + 3 + + + w +EOF sync; sync; sync; sync; sleep 10 hdparm -z "${LOOPBACK_02}" @@ -44,6 +54,8 @@ function create_new_image { losetup -d "${LOOPBACK_02}" losetup -d "${LOOPBACK_01}" + fdisk -l "${NEW_IMAGE_NAME}" + fdisk -l "${IMAGE_NAME}" mv "${NEW_IMAGE_NAME}" "${IMAGE_NAME}" sync; sync; sync; sync; sleep 10