fix incorrect partition layout because of size mismatch of /boot/efi

This commit is contained in:
Pratham Patel 2023-10-17 09:16:01 +05:30
parent 1ac3f3ab0a
commit 15a158431a
No known key found for this signature in database

View File

@ -17,32 +17,28 @@ done
function create_new_image {
UBOOT_MAX_SIZE='32'
EFI_END=$(( 512 + UBOOT_MAX_SIZE ))
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 ))"MiB "${NEW_IMAGE_NAME}"
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}")
parted -s "${LOOPBACK_02}" mklabel gpt
parted -s "${LOOPBACK_02}" mkpart efi fat32 "${UBOOT_MAX_SIZE}"MiB "${EFI_END}"MiB
parted -s "${LOOPBACK_02}" mkpart boot ext4 "${BOOT_START}"MiB "${BOOT_END}"MiB
parted -s "${LOOPBACK_02}" mkpart root ext4 "${ROOT_START}"MiB 100%
parted -s "${LOOPBACK_02}" set 1 boot on
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%
sync; sync; sync; sync;
sleep 10
hdparm -z "${LOOPBACK_02}"
dd bs=4M conv=sync status=progress if="${LOOPBACK_01}p1" if="${LOOPBACK_02}p1"
dd bs=4M conv=sync status=progress if="${LOOPBACK_01}p2" if="${LOOPBACK_02}p2"
dd bs=4M conv=sync status=progress if="${LOOPBACK_01}p3" if="${LOOPBACK_02}p3"
cat << EOF | fdisk "${LOOPBACK_02}"
w
EOF
dd bs=4M conv=sync status=progress if="${LOOPBACK_01}p3" of="${LOOPBACK_02}p3"
dd bs=4M conv=sync status=progress if="${LOOPBACK_01}p2" of="${LOOPBACK_02}p2"
dd bs=4M conv=sync status=progress if="${LOOPBACK_01}p1" of="${LOOPBACK_02}p1"
sync; sync; sync; sync;
sleep 10