38 lines
1.8 KiB
Bash
38 lines
1.8 KiB
Bash
set -ex
|
|
|
|
TEMP_IMAGE=${PWD}/decode-parted.img
|
|
# cleanup
|
|
touch $TEMP_IMAGE
|
|
rm $TEMP_IMAGE
|
|
|
|
# Define max sizes and offsets
|
|
IDBLOADER_START=64 # was 64 but report it is not aligned, 2048, which is 1MB alignment.
|
|
IDBLOADER_OFFSET=$((4*1024*1024/512)) # 8192 4MiB 8192
|
|
UBOOT_OFFSET=$((8*1024*1024/512)) # 16382 8MiB 16384
|
|
TRUST_OFFSET=$((12*1024*1024/512)) # 24575 12MiB 24575
|
|
BOOT_OFFSET=$((16*1024*1024/512)) # 32768 16MiB 32768
|
|
ROOT_OFFSET=$((128*1024*1024/512)) # 524288 128MiB 262144
|
|
|
|
MIN_SIZE=$((500*1000*1000/512)) # 976562 500MiB
|
|
SIZE_STEP=$((100*1000*1000/512)) # 195312 100MiB
|
|
MAX_SIZE=$((8*1000*1000*1000/512)) # 15625000 8GiB
|
|
|
|
# Create
|
|
rm -f "$TEMP_IMAGE"
|
|
truncate --size "$((MAX_SIZE*512))" "$TEMP_IMAGE"
|
|
|
|
bootfs="fat32"
|
|
rootfs="ext2"
|
|
alignment_type="optimal" # none, cylinder, minimal, optimal
|
|
# Create partitions
|
|
echo Updating GPT...
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" mklabel gpt
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" unit s mkpart loader1 $((IDBLOADER_START)) $((IDBLOADER_OFFSET-1)) # ~4MB
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" unit s mkpart loader2 $((IDBLOADER_OFFSET)) $((TRUST_OFFSET-1)) # up-to 16MB => ~12MB
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" unit s mkpart atp $((TRUST_OFFSET)) $((BOOT_OFFSET-1)) # up-to 16MB => ~12MB
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" unit s mkpart kernel $bootfs $((BOOT_OFFSET)) $((ROOT_OFFSET-1)) # up-to 132MB => 116MB
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" unit s mkpart Root $rootfs $((ROOT_OFFSET)) 100% # rest
|
|
parted --align ${alignment_type} -s "${TEMP_IMAGE}" set 4 boot on
|
|
|
|
sgdisk -p ${TEMP_IMAGE}
|