Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets, create disk images of them, and resize them at any time.
Partitioning lets you divide a single storage device into smaller units that you can manage independently. You can write multiple filesystems to one device to segment space along functional lines.
To use partitions with a volume, first you must create the partition(s) and then format each partition
The two most common partitioning systems are the traditional master boot record (MBR) format and the more modern GUID Partition Table (GPT). The MBR format has some inherent limitations, especially regarding the number and sizes of partitions that you can create.
If you have no specialized needs, we recommend using GPT partitions. To work with GPT partitions, we recommend parted
for non-interactive partitioning and gdisk
’s more robust menu-driven interface for interactive partitioning, both of which are often installed by default.
First, write a bare GPT partition table to your volume by passing the device to the parted
command with the mklabel gpt
subcommand:
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.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:
And this command creates two equally-sized partitions:
To start, use the volume identifier as an argument to gdisk
to scan the device and locate existing structures.
This enters you into an interactive prompt:
To write a new partition table to the disk, use the o option:
Confirm the operation by entering y at the confirmation prompt:
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:
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:
To write the table to the volume and exit the utility, use the w option, which prompts you to confirm the changes.
When you are certain of your changes, type Y to write the partitions to the volume.
After partitioning, you must format the partitions by writing a filesystem to each one. The filesystem is responsible for managing file-level interactions and providing reliable methods of writing and retrieving information on the disk.
There are many different types of Linux-compatible filesystems, like ext4, XFS, Btrfs, and ZFS. Distributions usually promote ext4 or XFS as the default choice for general purpose computing. The tooling for these two filesystems is usually installed by default, which means that formatting and managing these filesystems is straightforward.
Most Linux filesystems are formatted using tools that begin with mkfs.
followed by the name of the filesystem in lowercase, like mkfs.ext4
or mkfs.xfs
. By default, this creates a filesystem that fills the entire block device passed to it.
When formatting with mkfs
, use the identifier for the partition, not the identifier for the whole volume. Formatting the volume overwrites the partitions you created.
When using the /dev/disk/by-id
identifiers, partitions end in -part#
. You can use mkfs
’s -L
option to label the partition, which gives it a persistent name to use as an alternative to the /dev/disk/by-id
identifiers.
To format a partition with an ext4 filesystem, use mkfs.ext4
:
To format a partition with an XFS partition, use mkfs.xfs
:
Once you’ve formatted each partition, you’re ready to mount and use the volume.