# How to Create Partitions on DigitalOcean Volumes Block Storage Volumes are network-attached block storage. You can use them with Droplets or Kubernetes clusters, move or resize them, and create snapshots at any time. Partitioning divides a single storage device into smaller, independently managed sections. Each partition can contain its own filesystem, which lets you organize storage for different purposes. To use partitions on a volume, first [create the partition(s)](#create), and then [format each partition](#format). ## Create Partitions The two most common partitioning schemes are the legacy [master boot record (MBR)](https://en.wikipedia.org/wiki/Master_boot_record) and the modern [GUID Partition Table (GPT)](https://en.wikipedia.org/wiki/GUID_Partition_Table). MBR has significant limitations, including restrictions on partition size and the number of partitions. GPT removes these limitations and is the standard on modern systems, so we recommend using GPT. To manage GPT partitions: - Use `parted` for non-interactive partitioning. - Use `gdisk` for interactive, menu-driven partitioning. Most Linux distributions install both tools by default. If they’re not installed, install them using your distribution’s package manager: - **Ubuntu or Debian:** ``` ``` sudo apt update sudo apt install parted gdisk \`\`\` - **CentOS, RHEL, or Rocky Linux:** ``` ``` sudo dnf install parted gdisk \`\`\` ## Non-interactive partitioning with parted First, run the `parted` command to specify the block device: ```shell sudo parted /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 ``` This opens a `(parted)` prompt where you can run commands without repeating the device path. Then, create a new GPT partition table using `mklabel`: ```shell mklabel gpt ``` Then, create partitions using the `mkpart` command. The `partlabel` flag specifies the partition name. Provide a name, or use `""` to create the partition without a label. The `start` and `end` values define the partition boundaries. ```shell mkpart ``` `parted` also supports multiple units. We recommend using percentages so `parted` aligns partitions properly. For example, to create one partition that spans the entire volume, run `mkpart` like this: ```shell mkpart "" 0% 100% ``` Then, create two equally sized partitions: ```shell mkpart example1 0% 50% mkpart example2 50% 100% ``` Then, exit `parted` with the `quit` command: ```shell quit ``` ## Interactive partitioning with gdisk First, run the `gdisk` command using the volume identifier. `gdisk` scans the device and opens an interactive prompt. ```shell sudo gdisk /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 ``` Then, create a new GPT partition table with the `o` command: ```text o This option deletes all partitions and creates a new protective MBR. Proceed? (Y/N): ``` Confirm the operation by typing `Y`. Then, create a new partition with the `n` command: ```text n ``` `gdisk` prompts you for the partition number, first sector, last sector or size, and partition type. Press `ENTER` to accept the default values. ```text Partition number (1-128, default 1): First sector (34-209715166, default = 2048) or {+-}size{KMGTP}: Last sector (2048-209715166, default = 209715166) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' ``` When prompted for the last sector, you can alternatively specify a relative size using `+`. For example, entering `+10G` creates a partition that is 10 GiB in size instead of requiring you to calculate the ending sector manually: ```text Last sector (2048-209715166, default = 209715166) or {+-}size{KMGTP}: +10G ``` After you enter the size, `gdisk` confirms the partition type: ```text Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' ``` This creates a 10 GiB partition. To review the partition table, run the `p` command: ```text p ``` `gdisk` displays the disk details and the current partition table, showing the new 10 GiB partition along with its start and end sectors, partition type, and other disk metadata like this: ```text Disk /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01: ... ... Number Start (sector) End (sector) Size Code Name 1 2048 20973567 10.0 GiB 8300 Linux filesystem ``` To write the changes and exit, enter the `w` command: ```text w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): ``` `gdisk` displays a final warning that writing the GPT data overwrites existing partitions and prompts you to confirm. Enter `Y` to confirm. `gdisk` writes the new partition table to disk and exits. ## Format the Partitions After creating partitions, format each one with a filesystem. The filesystem manages how data is stored and retrieved. Common Linux filesystems include: - Ext4 - [XFS](https://en.wikipedia.org/wiki/XFS) - [Btrfs](https://en.wikipedia.org/wiki/Btrfs) - [ZFS](https://en.wikipedia.org/wiki/ZFS) Most distributions default to Ext4 or XFS, so we recommend using one of these options. The required tools are usually installed by default, but if they’re not installed, you can install them using your distribution’s package manager: - **Ubuntu or Debian:** ``` ``` sudo apt update sudo apt install e2fsprogs xfsprogs \`\`\` - **CentOS, RHEL, or Rocky Linux:** ``` ``` sudo dnf install e2fsprogs xfsprogs \`\`\` After installation, you can format partitions using tools that follow the `mkfs.` format, such as `mkfs.ext4` or `mkfs.xfs`. By default, these tools create a filesystem that fills the entire device you specify. **Note**: Always format the partition, not the entire volume. Formatting the full volume overwrites the partition table. When using `/dev/disk/by-id` identifiers, partitions end with `-part#`. You can use the `-L` option with `mkfs` to assign a filesystem label. Labels provide a persistent identifier as an alternative to `/dev/disk/by-id`. ## Format with Ext4 Format a partition with Ext4: ```shell sudo mkfs.ext4 /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01-part1 ``` The output confirms that a new Ext4 filesystem was successfully created on the partition and shows the total block count, block size, UUID, and journal creation details: ```text mke2fs 1.47.0 (5-Feb-2023) Creating filesystem with 25165824 4k blocks and 6291456 inodes Filesystem UUID: 12345678-1234-1234-1234-123456789abc Superblock backups stored on blocks: 32768, 98304, 163840, ... Allocating group tables: done Writing inode tables: done Creating journal (32768blocks): done Writing superblocks and filesystem accounting information: done ``` ## Format with XFS Format a partition with XFS: ```shell sudo mkfs.xfs /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01-part1 ``` The output confirms that a new XFS filesystem was created on the partition and shows the device path plus key filesystem layout details like block size, total blocks, and journal configuration: ```text meta-data=/dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01-part1 isize=512 agcount=4, agsize=5898175 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=0 data = bsize=4096 blocks=23592699, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=11519, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 ``` After formatting each partition, you can [mount the volume](https://docs.digitalocean.com/products/nfs/how-to/mount/index.html.md), and then begin using it.