Skip to content

How to Create Disk Partitions in Linux With parted and fdisk

Updated 2 min read

Updated: 30 September 2026 · Applies to: util-linux fdisk and GNU parted on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13

Before you can store data on a new disk, you create one or more partitions on it, put a file system on each partition, and mount it. This guide uses parted, which handles large disks and GPT partition tables well. Partitioning changes the disk layout: double-check the device name, because choosing the wrong disk destroys its data.

1. Find the new disk

lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS,MODEL

A new, empty disk has no partitions and no mount point, for example sdb or vdb. The examples use /dev/sdb.

2. Create a partition table and a partition

parted /dev/sdb --script mklabel gpt
parted /dev/sdb --script mkpart data xfs 0% 100%
parted /dev/sdb --script print

mklabel gpt creates a GPT partition table, which supports disks larger than 2 TB and many partitions. 0% 100% lets parted align the partition correctly and use the whole disk. For several partitions, give sizes instead, for example mkpart data xfs 0% 50% and mkpart backup ext4 50% 100%.

3. Create a file system

mkfs.xfs /dev/sdb1          # XFS, the default on AlmaLinux, Rocky Linux and RHEL
mkfs.ext4 /dev/sdb1         # or ext4, the default on Ubuntu and Debian

4. Mount it permanently

mkdir -p /data
blkid /dev/sdb1

Add a line to /etc/fstab with the UUID from blkid:

UUID=0b3f5c2e-...  /data  xfs  defaults,nofail  0 0
systemctl daemon-reload
mount -a
df -h /data

nofail lets the server boot even if this disk is missing. mount -a reports mistakes in /etc/fstab now instead of at the next boot.

Using fdisk instead

fdisk /dev/sdb works interactively: press g for a new GPT table, n for a new partition (accept the defaults to use the whole disk), p to check, and w to write. Nothing is changed until you press w.

For more on parted, including resizing, see 8 Linux parted commands to create, resize and rescue disk partitions and how to partition and mount a new disk with parted.

Official documentation: GNU parted manual and fdisk manual.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket