Sample Header Ad - 728x90

How to determine sizes using sgdisk partitioning in bash script

1 vote
1 answer
1787 views
I'm using sgdisk in a bash script similar to this: sgdisk --clear /dev/vda --set-alignment=1 --new 1:34:2047 --typecode 1:EF02 -c 1:"grub" -g /dev/vda sgdisk --new 2:2048:16779263 --typecode 2:8300 -g /dev/vda sgdisk --new 3:16779264:20971486 --typecode 3:8200 -g /dev/vda That works only when the devices are well known in advance and the sectors are hard-coded. I want to drop the hardcode the sector values. Instead, I want the script to work when the disk size is not known until the script runs. After making partition 1, I will set aside a known fixed amount to partition 3 for swap, and give the rest to partition 2. The easy way would be to make the swap partition #2. I know how to do that. However, I want to see if I can instead **do this while keeping swap on partition 3**. It means sgdisk will have to calculate a size or end sector value for partition 2 taking into account the size that will be allocated for partition 3 in the next step. Reading through the sgdisk man page hasn't given me the clues about how to do this (or even if it can be done).
Asked by BugBuddy (668 rep)
Nov 11, 2019, 06:27 AM
Last activity: Nov 11, 2019, 06:56 AM