SGDISK: (Use this for GPT drives of any size)


SFDISK: Use this for MBR (drives 2TiB or smaller)

You can create a partition file with vi and then redirect that file to sfdisk to make your partitions.



To clone entire partition table (every partition) use this:

Currently there isnt a way im aware of to clone single partitions, however using all of the information from the source partition you can recreate it on the destination device. Get all of the info using “sgdisk -p /dev/sda” and “sgdisk -i4 /dev/sda“, assuming I wanted to recreate the 4th partition of sda on another drive, lets say sdz. Then after getting that information, I would backup the destination drives ,sdz’s , partition tables (in case I mess up I can revert). After backup I would proceed with recreating the 4th partition on sdz, the destination device, using the above sgdisk commands using the -n (to set partition number, start and end sector), -t (to set partition type equal to what it was on the source), and -c arguments (to set a label, this is optional, but if you want it to be like a genuine clone of the partition then I would include it). Also remember to use -a1  when first creating the partition table on the destination device so that your partition tables start and end at the same sector numbers as they did on the source device. Optionally also use -S128 to specify max partition numbers are 128


With -t<part number>:<typecode | hex guid> you specify the partition type of the partition number. So for example -t1:fd00 sets the first partition to Linux Raid (fd00). You can also use the full GUID format for fd00 which is alot more digits (that I dont want to look up right now). Its easier to just use the 2 byte (4 hex character) type codes. Here they all are (ignore the stuff in the comments, just look at the type codes):

The common ones I use: 8300 Linux filesystem, fd00 linux raid, and 8200 linux swap.

The end

3 thoughts on “Writing Partition Tables with SGDISK (GPT) and SFDISK (MBR) – cheatsheet

  1. sgdisk sectors aren’t too hard if you suck at the bits and bytes understanding (like I do) using the 0 as a wildcard, you can easily set e.g. a gpt bios boot partition, a regular boot partition, a root and finally, everything else say home, by substitution of the second and third column values by 0 meaning either “next starting sector” or “fill up remaining sectors to end of space”

    -n 0:0:+2M -t “bios boot”
    -n 1:0:+200M -t “boot”
    -n 2:0:+3G -t “root”
    -n 3:0:0 -t “home”

Leave a Reply

Your email address will not be published. Required fields are marked *