# --- sgdisk ---
# -p prints partition table (on the very left it will print before operations, on the very right it will print the results after the operations)
# operations are from done left to right
# -a is alignment of first partition, leave at 1 so that you can set the start sector easily
# -S is 128 meaning there can be a max of 128 partitions
# -n{PARTNUM}:startsection:lastsector
# use -p to find out sector size (in bytes)
sgdisk -p /dev/sda
# -t is to set Type: FD00 is linux RAID, 0700 is Linux/Windows Data
# -c is to set partition label (its optional)
# delete all partitions GPT and MBR (by zapping them with -Z)
sgdisk -Z /dev/sda
# NOTE: deleting all of the partitions will not delete your data in the partitions, if you were to recreate the partitions then you would have access to your data again
# NOTE: to get detailed partition information, combine the results of -p but also look at -i. For example to get all of the info about the 3rd partition of sdc do this:
sgdisk -p /dev/sdc
sgdisk -i3 /dev/sdc
# a,S,p,c,t are all optional, they have default values. t & c can be set at a future time for any partition. Also you can make 1 or 10 partitions right off the bat it doesnt matter (as long as its fits as a bash command)
# *** example: ****
# we are going to make 3 partitions (with a max of 128 partitions that we can make in the future). -a1 makes it easier to align the first partition at the start sector we want - or else it might go to another spot.
sgdisk -a1 -S128 -p -n1:64:8388671 -t1:FD00 -c1:"Linux RAID" -n2:8388672:9437247 -t2:FD00 -c2:"Linux RAID" -n3:9437248:1953525101 -t3:FD00 -c3:"Linux RAID" -p /dev/sda;
# delete one partition (partition 2)
sgdisk -d2 /dev/sda
# make it smaller (no need to set alignment or S as they are already set)
sgdisk -p /dev/sda # <-- view partition table after deleting part#2
sgdisk -n2:8388672:5000000 -t2:FD00 -c2:"Linux RAID" # <-- create new part#2
sgdisk -p /dev/sda # <-- see new part table part#2
# or you can do all that in 1 command:
sgdisk -p -n2:8388672:5000000 -t2:FD00 -c2:"Linux RAID" -p /dev/sda
# *** example: ****
# creating a windows single GPT partition
sgdisk -a1 -S128 -p -n1:256:732566639 -t1:0700 -c1:"Linux/Windows data" -p /dev/sdc
# you can make the biggest partition possible to make using this method:
# -N{partnum} makes biggest partition
# imagine a 3TB drive with 1 partition in the beginning thats 300 Gig that was made like this
sgdisk -Z /dev/sda
sgdisk -a1 -S128 -p -n1:256:$((256*300*1024)) -t1:0700 -c1:"Linux/Windows data" -p /dev/sda
# $((256*300*1024)) gives us the ending sector that would give us 300 MB, the sector size was 4096 bytes on sdc. so 256 sectors gives us 1 MB. There are 300*1024 MBs in 300 GB. So there are 256*300*1024 of these sectors in 300 GB.
# 256 start sector is a good start sector, it gives alot of room in the beginning for other system stuff/gpt stuff. Note that 64 is also a good start sector number (as seen in the examples up top)
# So now we have 1 300 gig partition in the front. Lets create the biggest possible partition in the biggest hole
sgdisk -p -N2 -p /dev/sdc
# note all of the -p were optional, I just used them to get a before and after picture/information of the partition table. -N2 means it made the biggest partition possible and it named it partition 2. I could of used 3 or 4 or any number and it would of made the same size partition. Its just IDing the new partition
# by default the paritition is made with Type: 0700 which Linux/Window Days, and it has no Label/Name (but thats optional, we can set that with -c later). We can also change the type with -t if we wanted to