If any of this is wrong, let me know so I can fix it. No actual hard drives were harmed in the production of this blog post.
The examples are easier to read if you turn your smart phone sideways.
## **Command Line Is Faster**
Sure you can partition your discs using a GUI disk management application or an interactive,
menu-driven terminal interface. But the command line is faster.
## **gdisk vs sgdisk**
`sgdisk` is the scriptable version of `gdisk` (gptfdisk).
## **[what the manpage says](https://manpages.debian.org/stretch/gdisk/sgdisk.8.en.html){target=_blank}**
If you’re familiar with `gdisk`, you probably know how to interactively set the partition size and type.
If you look at the man page for `sgdisk` you see that the relevant flags are `-n` and `-t`. The beginning and ending numbers
are absolute, unless you prepend them with a `+` or `-` sign, in which case they become relative.
```console
# For New Partition:
-n, --new=partnum:start:end
```
```console
# Change partition type:
-t, --typecode=partnum:{hexcode|GUID}
```
## **Example with Separate EFI and / Partitions**
BTW, `gdisk` is a partitioning tool intended to be used with a gpt partition table, so the assumption is that you would want an efi partition,
(although the efi partition does not have to be on the disk you are partitioning or even on the same disk where your other system partitions are).
1. Wipe any leftover filesystem metadata with wipefs.
```console
wipefs --all /dev/sdx
```
1. Create a new GPT partition table.
```console
sgdisk /dev/sdx -o
```
1. Create an efi partition of 512MB by specifying the end of the partition (relative) and the partition type, `ef00`.
```console
sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00
```
1. Create an `/` partition using the remainder of the disk, by not specifying the end or the beginning or partition type, which defaults to 8300.
```console
sgdisk /dev/sdx -n 2
```
1. Format the efi partition fat 32.
```console
mkfs.vfat -F32 /dev/sdx1
```
1. Format the `/` partition ext4.
```console
mkfs.ext4 /dev/sdx2
```
## **Practice With A Sparse Image**
If you don’t want to partition a real hard drive, you can practice using an sparse image file, instead.
```console
# create a sparse image file
truncate -S 100G practiceImage.img
# partition the image file with sgdisk
sgdisk practiceImage.img -o
# etc
```
## **Example with Separate /boot, EFI, and luks-encrypted / Partitions**
1. Wipe any leftover filesystem metadata with `wipefs`.
```console
wipefs --all /dev/sdx
```
1. Create a new GPT partition table.
```console
sgdisk /dev/sdx -o
```
1. Create an efi partition of 512MB by specifying the end of the partition (relative) and the partition type, `ef00`.
```console
sgdisk /dev/sdx -n 1::+512MiB -t 1:ef00
```
1. Create a `/boot` partition of 1GB, by specifying the end of the partition (relative), but not specifying the partition type which defaults to `8300`.
```console
sgdisk /dev/sdx -n 2::+1GiB
```
1. Create an `/` partition using the remainder of the disk, by not specifying the end or the beginning or partition type, which defaults to `8300`.