From 8821c275103e840312d1860c89f000b1e37b7682 Mon Sep 17 00:00:00 2001 From: cyteen Date: Thu, 10 Mar 2022 16:02:59 +0000 Subject: [PATCH] Initial commit --- test-dd.sh | 23 +++ test-partitioning_cgpt.sh | 211 +++++++++++++++++++++ test-partitioning_parted.sh | 37 ++++ test-partitioning_sgdisk.sh | 67 +++++++ test-partitioning_sgdisk_ayufan.sh | 253 +++++++++++++++++++++++++ test-partitioning_sgdisk_ubuntu-zfs.sh | 62 ++++++ 6 files changed, 653 insertions(+) create mode 100644 test-dd.sh create mode 100755 test-partitioning_cgpt.sh create mode 100644 test-partitioning_parted.sh create mode 100644 test-partitioning_sgdisk.sh create mode 100644 test-partitioning_sgdisk_ayufan.sh create mode 100644 test-partitioning_sgdisk_ubuntu-zfs.sh diff --git a/test-dd.sh b/test-dd.sh new file mode 100644 index 0000000..1cd28d1 --- /dev/null +++ b/test-dd.sh @@ -0,0 +1,23 @@ + +gpt_idbloader=(64 8063) # 4MiB 8192 +gpt_uboot=(16384 24575) # 8MiB 16384 +gpt_trust=(24576 32767) # 12MiB 24575 +gpt_boot=(32768 229376) # 16MiB 32768 +gpt_root=(262144) # 128MiB 262144 expanded to use remaining space. + +ls *.img +loopdevice=${PWD}/decode-1.0.0-arm64.img +cgpt show ${loopdevice} + echo "sudo dd if=idbloader.img bs=512 seek=${gpt_idbloader[0]} of="${loopdevice}" status=none conv=notrunc" + sudo dd if=idbloader.img bs=512 seek=${gpt_idbloader[0]} of="${loopdevice}" status=none conv=notrunc status=progress + + echo sudo dd if=idbloader.img bs=512 seek=${gpt_idbloader[0]} of="${loopdevice}" status=none conv=notrunc status=progress + + echo "sudo dd if=uboot.img bs=512 seek=${gpt_uboot[0]} of="${loopdevice}" status=none conv=notrunc" + sudo dd if=uboot.img bs=512 seek=${gpt_uboot[0]} of="${loopdevice}" status=none conv=notrunc status=progress + + echo "sudo dd if=trust.img bs=512 seek=${gpt_trust[0]} of="${loopdevice}" status=none conv=notrunc" + sudo dd if=trust.img bs=512 seek=${gpt_trust[0]} of="${loopdevice}" status=none conv=notrunc status=progress + +cgpt show ${loopdevice} + diff --git a/test-partitioning_cgpt.sh b/test-partitioning_cgpt.sh new file mode 100755 index 0000000..1403b60 --- /dev/null +++ b/test-partitioning_cgpt.sh @@ -0,0 +1,211 @@ +#!/usr/bin/env zsh +set -x + +# Partition table for root and boot +parted_type="gpt" +gpt_idbloader=(64 8063) +gpt_uboot=(16384 24575) +gpt_trust=(24576 32767) +gpt_boot=(32768 229376) # start and end values for partitioning the `boot` partition. +gpt_root=(262144) # currently libdevuansdk chooses this as a startpoint, and maxes out remaining +bootfs="vfat" +rootfs="ext4" + +# Define max sizes and offsets +IDBLOADER_OFFSET=$((4*1024*1024/512)) # 4MiB 8192 +UBOOT_OFFSET=$((8*1024*1024/512)) # 8MiB 16384 +TRUST_OFFSET=$((12*1024*1024/512)) # 12MiB 24575 +BOOT_OFFSET=$((16*1024*1024/512)) # 16MiB 32768 +ROOT_OFFSET=$((128*1024*1024/512)) # 128MiB 262144 + +gpt_idbloader=(64 $((IDBLOADER_OFFSET-1))) +gpt_uboot=($((IDBLOADER_OFFSET)) $((TRUST_OFFSET-1))) +gpt_trust=($((TRUST_OFFSET)) $((BOOT_OFFSET-1))) +gpt_boot=($((BOOT_OFFSET)) $((ROOT_OFFSET-1))) +gpt_root=($((ROOT_OFFSET))) + +size=4098 +image_name=decode-cgpt +workdir=${PWD} + +dd if=/dev/zero \ + of=$workdir/${image_name}.img \ + bs=1M \ + count=$size + +parted $workdir/${image_name}.img --script -- mklabel gpt +cgpt create -z $workdir/${image_name}.img +cgpt create $workdir/${image_name}.img +cgpt repair $workdir/${image_name}.img +cgpt show $workdir/${image_name}.img + +# Create partition using start and end values for partitioning the `idbloader` partition. +# -i 3 -l idbloader -b 64 -s 8063 -t basicdata +# +# -i Specify partition number +# -l says label in the instructions but actually changes the name +# -b First block (a.k.a. start of partition) +# -s Size (in blocks) +# -t Partition Type GUID - see below after code +cgpt add \ + -i 3 \ + -l idbloader \ + -b ${gpt_idbloader[1]} \ + -s ${gpt_idbloader[2]} \ + -t data \ + $workdir/${image_name}.img + +# Create partition using start and end values for partitioning the `uboot` partition. +# -i 4 -l uboot -b 16384 -s 24575 -t basicdata +cgpt add \ + -i 4 \ + -l uboot \ + -b ${gpt_uboot[1]} \ + -s ${gpt_uboot[2]} \ + -t data \ + $workdir/${image_name}.img + +## Create partition using start and end values for partitioning the `trust` partition. +# -i 5 -l trust -b 24576 -s 32767 -t basicdata +cgpt add \ + -i 5 \ + -l trust \ + -b ${gpt_trust[1]} \ + -s ${gpt_trust[2]} \ + -t data \ + $workdir/${image_name}.img + +# Create partition using start and end values for partitioning the `boot` partition. +# -i 1 -l kernel -b 32768 -s 229376 -t kernel -S 1 -T 5 -P 10 +cgpt add \ + -i 1 \ + -l boot \ + -b ${gpt_boot[1]} \ + -s ${gpt_boot[2]} \ + -t kernel \ + -S 1 -T 5 -P 10 \ + $workdir/${image_name}.img + +# Create partion using just the start value, and maxes out remaining, +# -i 2 -l root -b 262144 -s 8130527 -t data +cgpt add \ + -i 2 \ + -l root \ + -b ${gpt_root[1]} \ + -s $(expr $(cgpt show $workdir/${image_name}.img | \ + awk '/Sec GPT table/ {print $1}') - ${gpt_root[1]}) \ + -t data \ + $workdir/${image_name}.img + +sgdisk -p $workdir/${image_name}.img + +# cgpt add -h +# The partition type may also be given as one of these aliases: +# firmware ChromeOS firmware FFFF +# kernel ChromeOS kernel 7F00 ChromeOS kernel +# rootfs ChromeOS rootfs 7F01 ChromeOS root +# data Linux data 8300 Linux filesystem +# basicdata Basic data 0700 Microsoft basic data +# reserved ChromeOS reserved 7F02 ChrOS reserved +# efi EFI System Partition EF00 EFI system partition +# unused Unused (nonexistent) partition NOT AVAILABLE + + +# sgdisk -L +# +# 0700 Microsoft basic data 0c01 Microsoft reserved +# 2700 Windows RE 3000 ONIE boot +# 3001 ONIE config 3900 Plan 9 +# 4100 PowerPC PReP boot 4200 Windows LDM data +# 4201 Windows LDM metadata 4202 Windows Storage Spaces +# 7501 IBM GPFS 7f00 ChromeOS kernel +# 7f01 ChromeOS root 7f02 ChromeOS reserved +# 8200 Linux swap 8300 Linux filesystem +# 8301 Linux reserved 8302 Linux /home +# 8303 Linux x86 root (/) 8304 Linux x86-64 root (/) +# 8305 Linux ARM64 root (/) 8306 Linux /srv +# 8307 Linux ARM32 root (/) 8308 Linux dm-crypt +# 8309 Linux LUKS 830a Linux IA-64 root (/) +# 830b Linux x86 root verity 830c Linux x86-64 root verity +# 830d Linux ARM32 root verity 830e Linux ARM64 root verity +# 830f Linux IA-64 root verity 8310 Linux /var +# 8311 Linux /var/tmp 8400 Intel Rapid Start +# 8500 Container Linux /usr 8501 Container Linux resizable rootfs +# 8502 Container Linux /OEM customization 8503 Container Linux root on RAID +# 8e00 Linux LVM a000 Android bootloader +# a001 Android bootloader 2 a002 Android boot 1 +# a003 Android recovery 1 a004 Android misc +# a005 Android metadata a006 Android system 1 +# a007 Android cache a008 Android data +# a009 Android persistent a00a Android factory +# a00b Android fastboot/tertiary a00c Android OEM +# a00d Android vendor a00e Android config +# a00f Android factory (alt) a010 Android meta +# a011 Android EXT a012 Android SBL1 +# a013 Android SBL2 a014 Android SBL3 +# a015 Android APPSBL a016 Android QSEE/tz +# a017 Android QHEE/hyp a018 Android RPM +# a019 Android WDOG debug/sdi a01a Android DDR +# a01b Android CDT a01c Android RAM dump +# a01d Android SEC a01e Android PMIC +# a01f Android misc 1 a020 Android misc 2 +# a021 Android device info a022 Android APDP +# a023 Android MSADP a024 Android DPO +# a025 Android recovery 2 a026 Android persist +# a027 Android modem ST1 a028 Android modem ST2 +# a029 Android FSC a02a Android FSG 1 +# a02b Android FSG 2 a02c Android SSD +# a02d Android keystore a02e Android encrypt +# a02f Android EKSST a030 Android RCT +# a031 Android spare1 a032 Android spare2 +# a033 Android spare3 a034 Android spare4 +# a035 Android raw resources a036 Android boot 2 +# a037 Android FOTA a038 Android system 2 +# a039 Android cache a03a Android user data +# a03b LG (Android) advanced flasher a03c Android PG1FS +# a03d Android PG2FS a03e Android board info +# a03f Android MFG a040 Android limits +# a200 Atari TOS basic data a500 FreeBSD disklabel +# a501 FreeBSD boot a502 FreeBSD swap +# a503 FreeBSD UFS a504 FreeBSD ZFS +# a505 FreeBSD Vinum/RAID a580 Midnight BSD data +# a581 Midnight BSD boot a582 Midnight BSD swap +# a583 Midnight BSD UFS a584 Midnight BSD ZFS +# a585 Midnight BSD Vinum a600 OpenBSD disklabel +# a800 Apple UFS a901 NetBSD swap +# a902 NetBSD FFS a903 NetBSD LFS +# a904 NetBSD concatenated a905 NetBSD encrypted +# a906 NetBSD RAID ab00 Recovery HD +# af00 Apple HFS/HFS+ af01 Apple RAID +# af02 Apple RAID offline af03 Apple label +# af04 AppleTV recovery af05 Apple Core Storage +# af06 Apple SoftRAID Status af07 Apple SoftRAID Scratch +# af08 Apple SoftRAID Volume af09 Apple SoftRAID Cache +# af0a Apple APFS b300 QNX6 Power-Safe +# bc00 Acronis Secure Zone be00 Solaris boot +# bf00 Solaris root bf01 Solaris /usr & Mac ZFS +# bf02 Solaris swap bf03 Solaris backup +# bf04 Solaris /var bf05 Solaris /home +# bf06 Solaris alternate sector bf07 Solaris Reserved 1 +# bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 +# bf0a Solaris Reserved 4 bf0b Solaris Reserved 5 +# c001 HP-UX data c002 HP-UX service +# e100 ONIE boot e101 ONIE config +# e900 Veracrypt data ea00 Freedesktop $BOOT +# eb00 Haiku BFS ed00 Sony system partition +# ed01 Lenovo system partition ef00 EFI system partition +# ef01 MBR partition scheme ef02 BIOS boot partition +# f800 Ceph OSD f801 Ceph dm-crypt OSD +# f802 Ceph journal f803 Ceph dm-crypt journal +# f804 Ceph disk in creation f805 Ceph dm-crypt disk in creation +# f806 Ceph block f807 Ceph block DB +# f808 Ceph block write-ahead log f809 Ceph lockbox for dm-crypt keys +# f80a Ceph multipath OSD f80b Ceph multipath journal +# f80c Ceph multipath block 1 f80d Ceph multipath block 2 +# f80e Ceph multipath block DB f80f Ceph multipath block write-ahead l +# f810 Ceph dm-crypt block f811 Ceph dm-crypt block DB +# f812 Ceph dm-crypt block write-ahead lo f813 Ceph dm-crypt LUKS journal +# f814 Ceph dm-crypt LUKS block f815 Ceph dm-crypt LUKS block DB +# f816 Ceph dm-crypt LUKS block write-ahe f817 Ceph dm-crypt LUKS OSD +# fb00 VMWare VMFS fb01 VMWare reserved +# fc00 VMWare kcore crash protection fd00 Linux RAID diff --git a/test-partitioning_parted.sh b/test-partitioning_parted.sh new file mode 100644 index 0000000..cf95d49 --- /dev/null +++ b/test-partitioning_parted.sh @@ -0,0 +1,37 @@ +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} diff --git a/test-partitioning_sgdisk.sh b/test-partitioning_sgdisk.sh new file mode 100644 index 0000000..fc42f79 --- /dev/null +++ b/test-partitioning_sgdisk.sh @@ -0,0 +1,67 @@ +set -ex + +DISK_NAME=${PWD}/decode-sgdisk.img +DISK_NAME=/dev/sdb +# cleanup +touch $DISK_NAME +rm $DISK_NAME + +# Partition sizes in MiB +IDBLOADER_SIZE=4 +UBOOT_SIZE=8 +TRUST_SIZE=12 +BOOT_SIZE=16 +ROOT_SIZE=128 + +# Define max sizes and offsets +IDBLOADER_START=64 # was 64 but report it is not aligned, 2048, which is 1MB alignment. +IDBLOADER_OFFSET=$((${IDBLOADER_SIZE}*1024*1024/512)) # 8192 4MiB 8192 +UBOOT_OFFSET=$((${UBOOT_SIZE}*1024*1024/512)) # 16382 8MiB 16384 +TRUST_OFFSET=$((${TRUST_SIZE}*1024*1024/512)) # 24575 12MiB 24575 +BOOT_OFFSET=$((${BOOT_SIZE}*1024*1024/512)) # 32768 16MiB 32768 +ROOT_OFFSET=$((${ROOT_SIZE}*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 "$DISK_NAME" +truncate --size "$((MAX_SIZE*512))" "$DISK_NAME" + +bootfs="fat32" +rootfs="ext2" +alignment_type="optimal" # none, cylinder, minimal, optimal +# Create partitions +echo Updating GPT... + +TARGET=${DISK_NAME} + +/sbin/sgdisk --zap-all ${TARGET} + +## Partition 3 - Create partition using start and end values for partitioning the `idbloader` partition. +#STARTSECTOR=`/sbin/sgdisk --first-aligned-in-largest ${TARGET}|sed -sn 2p` +STARTSECTOR=${IDBLOADER_START} +/sbin/sgdisk --print --set-alignment=64 --mbrtogpt --new=3:${STARTSECTOR}:+${IDBLOADER_SIZE}MB ${TARGET} +/sbin/sgdisk --print --change-name=3:"idbloader" --typecode=3:8300 ${TARGET} + +## Partition 4 - Create partition using start and end values for partitioning the `uboot` partition. +ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` +/sbin/sgdisk --print --new=4:-${UBOOT_SIZE}MB:${ENDSECTOR} ${TARGET} +/sbin/sgdisk --print --change-name=4:"uboot" --typecode=4:8300 ${TARGET} + +## Partition 5 - the 12MB partition for trust partition +ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` +/sbin/sgdisk --print --new=5:-${TRUST_SIZE}MB:${ENDSECTOR} ${TARGET} +/sbin/sgdisk --print --change-name=5:"atp" --typecode=5:8300 ${TARGET} + +## Partition 1 - the 16MB partition for boot +ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` +/sbin/sgdisk --print --new=1:-${BOOT_SIZE}MB:${ENDSECTOR} ${TARGET} +/sbin/sgdisk --print --change-name=1:"boot" --typecode=1:EF00 ${TARGET} + +## Partition 2 - the main partition for root +/sbin/sgdisk --print --largest-new=2 ${TARGET} +/sbin/sgdisk --print --change-name=2:root --typecode=2:8305 ${TARGET} + +/sbin/sgdisk -print ${TARGET} diff --git a/test-partitioning_sgdisk_ayufan.sh b/test-partitioning_sgdisk_ayufan.sh new file mode 100644 index 0000000..7a651b9 --- /dev/null +++ b/test-partitioning_sgdisk_ayufan.sh @@ -0,0 +1,253 @@ +set -ex + +DISK_NAME=${PWD}/decode-sgdisk.img +# cleanup +touch $DISK_NAME +rm $DISK_NAME + +# Partition sizes in MiB +IDBLOADER_SIZE=4 +UBOOT_SIZE=8 +TRUST_SIZE=12 +BOOT_SIZE=16 +ROOT_SIZE=128 + +# Define max sizes and offsets +IDBLOADER_START=64 # was 64 but report it is not aligned, 2048, which is 1MB alignment. +IDBLOADER_OFFSET=$((${IDBLOADER_SIZE}*1024*1024/512)) # 8192 4MiB 8192 +UBOOT_OFFSET=$((${UBOOT_SIZE}*1024*1024/512)) # 16382 8MiB 16384 +TRUST_OFFSET=$((${TRUST_SIZE}*1024*1024/512)) # 24575 12MiB 24575 +BOOT_OFFSET=$((${BOOT_SIZE}*1024*1024/512)) # 32768 16MiB 32768 +ROOT_OFFSET=$((${ROOT_SIZE}*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 "$DISK_NAME" +truncate --size "$((MAX_SIZE*512))" "$DISK_NAME" + +bootfs="fat32" +rootfs="ext2" +alignment_type="optimal" # none, cylinder, minimal, optimal + + +gpt_loader1=(64 8063) # name:loader1 type=Linux data 8300 label="" +gpt_reserved1=(8064 8191) # name:reserved1 type=Linux data 8300 label="" +gpt_reserved2=(8192 16383) # name:reserved2 type=Linux data 8300 label="" +gpt_loader2=(16384 24575) # name:reserved2 type=Linux data 8300 label="" +gpt_atf=(24576 32767) # name:atf type=Linux data 8300 label="" +gpt_boot=(32768 262143) # name:boot type=Basic data 0700 label="boot" Attr=msftdata +gpt_root=(262144) # name:root type=Linux data 8300 label="linux-root" Attr=legacy-boot=1 # NB change to type=Linux ARM64 root 8305 + +gpt_loader1_size=4 +gpt_reserved1_size=64 # in k +gpt_reserved2_size=4 +gpt_loader2_size=4 +gpt_atf_size=4 +gpt_boot_size=112 + +# Create partitions +echo Updating GPT... + +TARGET=${DISK_NAME} + +/sbin/sgdisk --zap-all ${TARGET} + +partition_loader1() { + ## Partition 1 - Create partition using start and end values for partitioning the `loader1` partition. + #STARTSECTOR=`/sbin/sgdisk --first-aligned-in-largest ${TARGET}|sed -sn 2p` + STARTSECTOR=${gpt_loader[1]} + /sbin/sgdisk --print --set-alignment=64 --mbrtogpt --new=1:${STARTSECTOR}:+${gpt_loader1_size}MB ${TARGET} + /sbin/sgdisk --print --change-name=1:"loader1" --typecode=1:8300 ${TARGET} +} + +partition_reserved1() { + ## Partition 2 - Create partition using start and end values for partitioning the `reserved1` partition. + #ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` + #/sbin/sgdisk --print --new=2:-${gpt_reserved1_size}KB:${ENDSECTOR} ${TARGET} + STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` + /sbin/sgdisk --print --new=2:${STARTSECTOR}:+${gpt_reserved1_size}KB ${TARGET} + /sbin/sgdisk --print --change-name=2:"reserved1" --typecode=2:8300 ${TARGET} +} + +partition_reserved2() { + ## Partition 3 - Create partition using start and end values for partitioning the `reserved2` partition. + #ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` + #/sbin/sgdisk --print --new=3:-${gpt_reserved1_size}MB:${ENDSECTOR} ${TARGET} + STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` + /sbin/sgdisk --print --new=3:${STARTSECTOR}:+${gpt_reserved2_size}MB ${TARGET} + /sbin/sgdisk --print --change-name=3:"reserved2" --typecode=3:8300 ${TARGET} +} + +partition_loader2() { + ## Partition 4 - Create partition using start and end values for partitioning the `loader2` partition. + #ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` + #/sbin/sgdisk --print --new=4:-${gpt_loader2_size}MB:${ENDSECTOR} ${TARGET} + STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` + /sbin/sgdisk --print --new=4:${STARTSECTOR}:+${gpt_loader2_size}MB ${TARGET} + /sbin/sgdisk --print --change-name=4:"loader2" --typecode=4:8300 ${TARGET} +} + +partition_atf() { + ## Partition 5 - Create partition using start and end values for partitioning the `atf` partition. + #ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` + #/sbin/sgdisk --print --new=4:-${gpt_atf_size}MB:${ENDSECTOR} ${TARGET} + STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` + /sbin/sgdisk --print --new=5:${STARTSECTOR}:+${gpt_atf_size}MB ${TARGET} + /sbin/sgdisk --print --change-name=5:"atf" --typecode=5:8300 ${TARGET} +} + +partition_boot() { + ## Partition 6 - the 112MB partition for boot + #ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` + #/sbin/sgdisk --print --new=6:-${gpt_boot_size}MB:${ENDSECTOR} ${TARGET} + STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` + /sbin/sgdisk --print --new=6:${STARTSECTOR}:+${gpt_boot_size}MB ${TARGET} + /sbin/sgdisk --print --change-name=6:"boot" --typecode=6:EF00 ${TARGET} +} + +partition_root() { + ## Partition 7 - the main partition for root + /sbin/sgdisk --print --largest-new=7 ${TARGET} + /sbin/sgdisk --print --change-name=7:root --typecode=7:8305 ${TARGET} +} + +image_format_partitions() { + mkfs.ext4 -L "linux-boot" "${loopdevice}p6" + mkfs.ext4 -L "linux-root" "${loopdevice}p7" + tune2fs -o journal_data_writeback "${loopdevice}p7" +} + + +loop_it() { + loopdevice=$(sudo losetup -f --show $DISK_NAME) + echo "Loop device is: " $loopdevice + sudo partx -av $loopdevice || zerr + + + loader1="${loopdevice}p1" + reserved1="${loopdevice}p2" + reserved2="${loopdevice}p3" + loader2="${loopdevice}p4" + atf="${loopdevice}p5" + boot="${loopdevice}p6" + root="${loopdevice}p7" + + mkfs.ext2 -L "linux-boot" "$boot" + mkfs.ext4 -L "linux-root" "$root" + tune2fs -o journal_data_writeback "$root" +} + +partition_loader1 +partition_reserved1 +partition_reserved2 +partition_loader2 +partition_atf +partition_boot +partition_root +loop_it + + +#/sbin/sgdisk -print ${TARGET} +cgpt show ${TARGET} + +# sgdisk -L +# +# 0700 Microsoft basic data 0c01 Microsoft reserved +# 2700 Windows RE 3000 ONIE boot +# 3001 ONIE config 3900 Plan 9 +# 4100 PowerPC PReP boot 4200 Windows LDM data +# 4201 Windows LDM metadata 4202 Windows Storage Spaces +# 7501 IBM GPFS 7f00 ChromeOS kernel +# 7f01 ChromeOS root 7f02 ChromeOS reserved +# 8200 Linux swap 8300 Linux filesystem +# 8301 Linux reserved 8302 Linux /home +# 8303 Linux x86 root (/) 8304 Linux x86-64 root (/) +# 8305 Linux ARM64 root (/) 8306 Linux /srv +# 8307 Linux ARM32 root (/) 8308 Linux dm-crypt +# 8309 Linux LUKS 830a Linux IA-64 root (/) +# 830b Linux x86 root verity 830c Linux x86-64 root verity +# 830d Linux ARM32 root verity 830e Linux ARM64 root verity +# 830f Linux IA-64 root verity 8310 Linux /var +# 8311 Linux /var/tmp 8400 Intel Rapid Start +# 8500 Container Linux /usr 8501 Container Linux resizable rootfs +# 8502 Container Linux /OEM customization 8503 Container Linux root on RAID +# 8e00 Linux LVM a000 Android bootloader +# a001 Android bootloader 2 a002 Android boot 1 +# a003 Android recovery 1 a004 Android misc +# a005 Android metadata a006 Android system 1 +# a007 Android cache a008 Android data +# a009 Android persistent a00a Android factory +# a00b Android fastboot/tertiary a00c Android OEM +# a00d Android vendor a00e Android config +# a00f Android factory (alt) a010 Android meta +# a011 Android EXT a012 Android SBL1 +# a013 Android SBL2 a014 Android SBL3 +# a015 Android APPSBL a016 Android QSEE/tz +# a017 Android QHEE/hyp a018 Android RPM +# a019 Android WDOG debug/sdi a01a Android DDR +# a01b Android CDT a01c Android RAM dump +# a01d Android SEC a01e Android PMIC +# a01f Android misc 1 a020 Android misc 2 +# a021 Android device info a022 Android APDP +# a023 Android MSADP a024 Android DPO +# a025 Android recovery 2 a026 Android persist +# a027 Android modem ST1 a028 Android modem ST2 +# a029 Android FSC a02a Android FSG 1 +# a02b Android FSG 2 a02c Android SSD +# a02d Android keystore a02e Android encrypt +# a02f Android EKSST a030 Android RCT +# a031 Android spare1 a032 Android spare2 +# a033 Android spare3 a034 Android spare4 +# a035 Android raw resources a036 Android boot 2 +# a037 Android FOTA a038 Android system 2 +# a039 Android cache a03a Android user data +# a03b LG (Android) advanced flasher a03c Android PG1FS +# a03d Android PG2FS a03e Android board info +# a03f Android MFG a040 Android limits +# a200 Atari TOS basic data a500 FreeBSD disklabel +# a501 FreeBSD boot a502 FreeBSD swap +# a503 FreeBSD UFS a504 FreeBSD ZFS +# a505 FreeBSD Vinum/RAID a580 Midnight BSD data +# a581 Midnight BSD boot a582 Midnight BSD swap +# a583 Midnight BSD UFS a584 Midnight BSD ZFS +# a585 Midnight BSD Vinum a600 OpenBSD disklabel +# a800 Apple UFS a901 NetBSD swap +# a902 NetBSD FFS a903 NetBSD LFS +# a904 NetBSD concatenated a905 NetBSD encrypted +# a906 NetBSD RAID ab00 Recovery HD +# af00 Apple HFS/HFS+ af01 Apple RAID +# af02 Apple RAID offline af03 Apple label +# af04 AppleTV recovery af05 Apple Core Storage +# af06 Apple SoftRAID Status af07 Apple SoftRAID Scratch +# af08 Apple SoftRAID Volume af09 Apple SoftRAID Cache +# af0a Apple APFS b300 QNX6 Power-Safe +# bc00 Acronis Secure Zone be00 Solaris boot +# bf00 Solaris root bf01 Solaris /usr & Mac ZFS +# bf02 Solaris swap bf03 Solaris backup +# bf04 Solaris /var bf05 Solaris /home +# bf06 Solaris alternate sector bf07 Solaris Reserved 1 +# bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 +# bf0a Solaris Reserved 4 bf0b Solaris Reserved 5 +# c001 HP-UX data c002 HP-UX service +# e100 ONIE boot e101 ONIE config +# e900 Veracrypt data ea00 Freedesktop $BOOT +# eb00 Haiku BFS ed00 Sony system partition +# ed01 Lenovo system partition ef00 EFI system partition +# ef01 MBR partition scheme ef02 BIOS boot partition +# f800 Ceph OSD f801 Ceph dm-crypt OSD +# f802 Ceph journal f803 Ceph dm-crypt journal +# f804 Ceph disk in creation f805 Ceph dm-crypt disk in creation +# f806 Ceph block f807 Ceph block DB +# f808 Ceph block write-ahead log f809 Ceph lockbox for dm-crypt keys +# f80a Ceph multipath OSD f80b Ceph multipath journal +# f80c Ceph multipath block 1 f80d Ceph multipath block 2 +# f80e Ceph multipath block DB f80f Ceph multipath block write-ahead l +# f810 Ceph dm-crypt block f811 Ceph dm-crypt block DB +# f812 Ceph dm-crypt block write-ahead lo f813 Ceph dm-crypt LUKS journal +# f814 Ceph dm-crypt LUKS block f815 Ceph dm-crypt LUKS block DB +# f816 Ceph dm-crypt LUKS block write-ahe f817 Ceph dm-crypt LUKS OSD +# fb00 VMWare VMFS fb01 VMWare reserved +# fc00 VMWare kcore crash protection fd00 Linux RAID diff --git a/test-partitioning_sgdisk_ubuntu-zfs.sh b/test-partitioning_sgdisk_ubuntu-zfs.sh new file mode 100644 index 0000000..fb01e7d --- /dev/null +++ b/test-partitioning_sgdisk_ubuntu-zfs.sh @@ -0,0 +1,62 @@ +set -ex + +DISK_NAME=${PWD}/ubuntu-sgdisk.img +#DISK_NAME=/dev/sdb +# cleanup +touch $DISK_NAME +rm $DISK_NAME + +# Partition sizes in MiB +EFI_SIZE=4 +SWAP_SIZE=8 +BOOT_SIZE=16 +ROOT_SIZE=128 + +# Define max sizes and offsets +EFI_START=2048 # was 64 but report it is not aligned, 2048, which is 1MB alignment. +EFI_OFFSET=$((${EFI_SIZE}*1024*1024/512)) # 8192 4 MiB 8192 +SWAP_OFFSET=$((${SWAP_SIZE}*1024*1024/512)) # 16382 8 MiB 16384 +BOOT_OFFSET=$((${BOOT_SIZE}*1024*1024/512)) # 32768 16 MiB 32768 +ROOT_OFFSET=$((${ROOT_SIZE}*1024*1024/512)) # 524288 128 MiB 262144 + +MIN_SIZE=$((500*1000*1000/512)) # 976562 500 MiB +SIZE_STEP=$((100*1000*1000/512)) # 195312 100 MiB +MAX_SIZE=$((8*1000*1000*1000/512)) # 15625000 8 GiB + +# Create +rm -f "$DISK_NAME" +truncate --size "$((MAX_SIZE*512))" "$DISK_NAME" + +bootfs="fat32" +rootfs="ext2" +alignment_type="optimal" # none, cylinder, minimal, optimal +# Create partitions +echo Updating GPT... + +TARGET=${DISK_NAME} + +/sbin/sgdisk --zap-all ${TARGET} + +## Partition 1 - Create partition using start and end values for partitioning the `EFI` partition. +#STARTSECTOR=`/sbin/sgdisk --first-aligned-in-largest ${TARGET}|sed -sn 2p` +STARTSECTOR=${EFI_START} +/sbin/sgdisk --print --set-alignment=${STARTSECTOR} --mbrtogpt --new=1:${STARTSECTOR}:+${EFI_SIZE}MB ${TARGET} +/sbin/sgdisk --print --change-name=1:"EFI System Partition" --typecode=1:EF00 ${TARGET} + +## Partition 2 - Create partition using start and end values for partitioning the `swap` partition. +#ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` +STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` +/sbin/sgdisk --print --new=2:${STARTSECTOR}:+${SWAP_SIZE}MB ${TARGET} +/sbin/sgdisk --print --change-name=2:"Linux swap" --typecode=2:8200 ${TARGET} + +## Partition 3 - upto 2GB partition for boot +#ENDSECTOR=`/sbin/sgdisk --end-of-largest ${TARGET}|sed -sn 2p` +STARTSECTOR=`/sbin/sgdisk --first-in-largest ${TARGET}|sed -sn 2p` +/sbin/sgdisk --print --new=3:${STARTSECTOR}:+${BOOT_SIZE}MB ${TARGET} +/sbin/sgdisk --print --change-name=3:boot --typecode=3:BE00 ${TARGET} + +## Partition 4 - the main partition for root +/sbin/sgdisk --print --largest-new=4 ${TARGET} +/sbin/sgdisk --print --change-name=4:root --typecode=4:BF00 ${TARGET} + +/sbin/gdisk -print ${TARGET}