First, write a bare GPT partition table to your volume by passing the device to the parted
command with the mklabel gpt
subcommand:
sudo parted /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 mklabel gpt
Next, you can begin writing your partitions with parted
. The command has several parts:
mkpart
creates a new partition table of the specified type, like GPT.
-a opt
aligns the partitions with the disk’s underlying sectors.
primary
is an odd parameter. parted
works with GPT, but its argument structure still reflects its MBR origins, so you still need to specify that you’re writing “primary” partitions, even though GPT doesn’t use these designations.
- The starting and ending position of the partition take a variety of units, like
GB
, sectors, or percentages. parted
can only handle absolute positioning by providing a definite start and end point.
Using percentages and passing in the -a opt
option lets parted
to automatically align the partitions to the underlying sectors, which is important for proper performance.
As an example, this command creates a single partition that spans the entire volume:
sudo parted -a opt /dev/disk/by-id/scsi-example mkpart primary 0% 100%
And this command creates two equally-sized partitions:
sudo parted -a opt /dev/disk/by-id/scsi-example mkpart primary 0% 50%
sudo parted -a opt /dev/disk/by-id/scsi-example mkpart primary 50% 100%
To start, use the volume identifier as an argument to gdisk
to scan the device and locate existing structures.
sudo gdisk /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01
This enters you into an interactive prompt:
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help):
To write a new partition table to the disk, use the o option:
Confirm the operation by entering y at the confirmation prompt:
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N):
Next, create partitions by using the n option:
gdisk
takes you through a series of prompts for the partition number, the first sector, the last sector or size, and the GUID for the partition type:
Partition number (1-128, default 1):
First sector (34-209715166, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-209715166, default = 209715166) or {+-}size{KMGTP}: +10G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
You can press ENTER
to accept the suggested default values, which is typically the right choice. For the last sector or size prompt, you can use +
to indicate relative sizing. This means that you can pass the partition size directly (instead of calculating the end position, as with parted
).
You can display the partitions by using the p option:
Disk /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 19252774-25E2-4899-96CD-DCFE3B846DCC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 188743613 sectors (90.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 20973567 10.0 GiB 8300 Linux filesystem
To write the table to the volume and exit the utility, use the w option, which prompts you to confirm the changes.
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N):
When you are certain of your changes, type Y to write the partitions to the volume.