How to Use parted and fdisk for Disk Partitioning
Disk partitioning defines how Linux stores operating systems, applications, logs and user data on a drive. The fdisk and parted utilities are standard command-line tools for creating, deleting and resizing partitions on RHEL, CentOS, Fedora and related distributions.
Use these commands carefully: a single incorrect device name can erase an entire disk. The examples below use /dev/sdb, but you must replace it with the correct drive on your system and confirm every destructive operation before accepting it.
| Feature | fdisk |
parted |
|---|---|---|
| Best suited to | Interactive partition management | Interactive and scripted administration |
| Partition tables | MBR and GPT | MBR, GPT and other formats |
| Large disks | Supported with modern versions | Strong support for large disks |
| Resize operations | Limited | Supports partition resizing |
| Alignment guidance | Manual or automatic prompts | Reports alignment and sector details |
| Typical use | Quick, familiar partition edits | Advanced layouts and automation |
Check The Disk Layout First
Start by identifying disks, existing partitions and mount points. The lsblk command provides a readable overview, while blkid shows filesystem UUIDs and types.
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,UUID
sudo blkid
Never assume that the second disk is /dev/sdb. Hardware order can change after a reboot, and a removable drive may receive a different device name. On systems in Sydney or Melbourne data centres, confirm the storage device through the hosting console as well as the operating system.
Check whether a disk is already mounted before changing its partition table:
findmnt /dev/sdb1
sudo umount /dev/sdb1
Unmounting is essential before deleting or recreating a partition. If the disk contains an active swap partition, disable it with sudo swapoff /dev/sdb1 only after confirming that it is not needed by the running system.
Prepare A Safe Partitioning Session
Back up important files before making changes. For business systems, consider a tested restore process rather than relying on a copy that has never been opened. This is especially relevant when Australian organisations store customer information under obligations associated with the Privacy Act 1988 and the Notifiable Data Breaches scheme.
Record the current layout so that you can compare it later:
sudo sfdisk -d /dev/sdb > sdb-layout-backup.txt
sudo parted /dev/sdb print free
If you are working with a new disk, a GUID Partition Table (GPT) is generally preferable. GPT handles large drives and many partitions more cleanly than the older DOS/MBR format. Check the existing label before proceeding, because creating a new one removes its partition definitions.
Create Partitions With Fdisk
Launch fdisk against the complete disk, not an existing partition:
sudo fdisk /dev/sdb
Inside the utility, use p to print the current layout, g to create a new GPT label, and n to create a partition. Press Enter to accept suitable defaults, or enter explicit first and last sectors when you need precise sizing. The t command changes a partition type, while w writes changes to disk.
A simple new partition sequence may look like this:
g
n
1
<Enter>
+100G
w
The g command is destructive when a disk already contains a partition table. For an existing GPT disk, omit it and create only the required partition. After fdisk exits, ask the kernel to reread the layout if necessary:
sudo partprobe /dev/sdb
lsblk /dev/sdb
Build A Layout With Parted
parted is useful when you need alignment checks, exact units or repeatable commands. First inspect the disk:
sudo parted /dev/sdb
(parted) print
(parted) print free
For a new GPT disk, use:
sudo parted -s /dev/sdb mklabel gpt
sudo parted -s -a optimal /dev/sdb mkpart primary 1MiB 100GiB
The -a optimal option aligns partitions for modern SSDs and hard drives. Alignment can improve performance and avoid unnecessary read-modify-write operations. Australian administrators managing compact NVMe systems from local hardware retailers should still verify the drive’s actual capacity rather than copying specifications from a product listing.
parted accepts human-readable units, but exact values may be rounded. Use unit MiB or unit s when sector-level control matters. Its rm command removes a partition definition, while resizepart changes the partition boundary; resizing the filesystem itself is a separate operation.
Format And Mount The New Space
Partition creation does not create a usable filesystem. After checking the new device name, format it with an appropriate filesystem:
sudo mkfs.xfs /dev/sdb1
For a Fedora or RHEL server, XFS is common for general data storage. Ext4 remains a practical choice for many installations:
sudo mkfs.ext4 /dev/sdb1
Create a mount point and mount the filesystem temporarily:
sudo mkdir -p /data
sudo mount /dev/sdb1 /data
df -hT /data
For permanent mounting, use the UUID instead of /dev/sdb1, because device names may change:
sudo blkid /dev/sdb1
Add a carefully tested entry to /etc/fstab. A temporary mount followed by df -hT is safer than rebooting immediately with an unverified configuration.
Verify Alignment And Persistence
Review the resulting layout with both tools:
sudo fdisk -l /dev/sdb
sudo parted /dev/sdb align-check optimal 1
lsblk -f
The alignment check should report that the partition is optimally aligned. If it does not, investigate before placing a database or high-write workload on the disk. parted print free also helps reveal unused gaps that might otherwise be overlooked.
Confirm that the filesystem mounts correctly after a controlled test:
sudo umount /data
sudo mount -a
findmnt /data
A server in Brisbane, Perth or regional Australia may have limited hands-on access, so remote operators should keep an out-of-band console available before changing storage. Network access through an NBN connection or a cloud control panel does not protect against an invalid /etc/fstab entry.
Connect Storage Work With Server Administration
Partitioning is often one step in a broader deployment. Once a data volume is mounted, services such as Nginx may use it for static files, uploads or logs. A related Nginx static content guide explains how to expose content safely on RHEL.
Keep application files, logs and backups on deliberately chosen filesystems. Avoid placing rapidly growing logs on the root filesystem, and use tools such as du, journalctl --disk-usage and log rotation to monitor consumption. For hosted infrastructure, review the provider’s storage and recovery terms; broader telecom resources can also provide useful context when comparing connectivity and infrastructure arrangements.
Practical Partitioning Recommendations
Use these habits whenever you modify a Linux disk:
- Verify the target with
lsblk,findmntand the hosting console before writing changes. - Prefer GPT for new disks, especially drives larger than 2 TB or systems requiring several partitions.
- Choose
fdiskfor straightforward interactive work andpartedfor alignment checks or repeatable scripts. - Back up data and export the existing partition layout before deleting or recreating anything.
- Test
/etc/fstabwithmount -abefore rebooting a remote server.
Keep command output and change notes with your system documentation. If a storage change affects a production service, record the maintenance window and rollback plan; the Linuxtpoint contact page is available for publication-related enquiries. Before changing a real disk, run lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS and write down the exact device you intend to modify.