A Guide to Linux Disk Partitioning with `fdisk` and `parted`
Aug 02, 2025 am 07:14 AMfdisk is suitable for use when the MBR partition table and the disk is less than 2TB, suitable for simple interactive operations; 1. When using fdisk, first use p to view the current partition table, n to create a new partition, t set the type, w to save changes; 2. parted is suitable for disks larger than 2TB or when GPT support is required, scripting operations can be performed; 3. When using parted, first mklabel gpt creates GPT tags, unit sets units, mkpart creates partitions, prints to view results, and quit exit; 4. Both must be carefully checked for device names to avoid data loss due to error operations; 5. Format the partition using the mkfs command, and can be used after mount; always back up important data before operation and confirm that the device name is correct.
Linux disk partitioning is a fundamental skill for system administrators and power users. Whether you're setting up a new drive, resizing partitions, or preparing for a fresh OS install, knowing how to use tools like fdisk
and parted
give you full control over your storage layout. While both tools serve the same basic purpose—creating and managing disk partitions—they different in capabilities and use cases.

Here's a practical guide to using fdisk
and parted
, when to use each, and what you need to know to avoid common pitfalls.
When to Use fdisk
vs. parted
Use fdisk
when:

- You're working with MBR (Master Boot Record) partition tables.
- The disk is under 2TB in size.
- You prefer a simple, text-based interactive interface.
- You don't need advanced features like resizing or non-destructive operations.
fdisk
is reliable, widely available, and great for basic partitioning tasks on older-style disks.
Use parted
when:

- The disk is larger than 2TB .
- You need GPT (GUID Partition Table) support.
- You want to resize, move, or copy partitions (with caution).
- You're scripting partitioning tasks (supports non-interactive mode).
parted
is more modern and flexible, especially for large drives and advanced settings.
Using fdisk
to Partition a Disk
Let's walk through creating a new partition on /dev/sdb
using fdisk
.
-
Start
fdisk
:sudo fdisk /dev/sdb
Check current partition table: At the prompt, type
p
to print the current partition layout.Create a new partition:
- Type
n
to create a new partition. - Choose
p
for primary (ore
for extended). - Accept default values or specify sector ranges.
- Confirm the partition size (eg,
20G
for 20GB).
- Type
Set the partition type (optional):
- Type
t
to change the partition type. - Enter the partition number.
- Choose a type code (eg,
8e
for Linux LVM,82
for swap).
- Type
Write changes:
- Type
w
to write the new partition table to disk and exit. - Or
q
to quit without saving.
- Type
?? Warning:
w
apply changes immediately. There's no undo.
Notify the kernel of changes:
sudo partprobe /dev/sdb
Or reboot if needed.
Format and use:
sudo mkfs.ext4 /dev/sdb1 sudo mkdir /mnt/mydisk sudo mount /dev/sdb1 /mnt/mydisk
Using parted
for GPT and Large Disks
For disks over 2TB or when using UEFI systems, GPT is required. fdisk
can technically handle GPT (via gdisk
), but parted
is better suited.
Check disk and use
parted
:sudo parted /dev/sdc
Create a GPT partition table: Inside
parted
, run:(parted) mklabel gpt
Set unit (optional, for clarity):
(parted) unit GB
Create a partition:
(parted) mkpart primary 0GB 50GB
This creates a 50GB partition. You can also specify
ext4
,xfs
, etc., thoughparted
doesn't format—it only defines layout.List and verify:
(parted) print
Exit:
(parted) quit
Format and mount:
sudo mkfs.ext4 /dev/sdc1 sudo mount /dev/sdc1 /mnt/bigdisk
? Tip: You can run
parted
non-interactively:sudo parted /dev/sdc mkpart primary 0% 100%
Key Differences and Best Practices
Partition table support:
fdisk
: Best for MBR (limited to 2TB, max 4 primary partitions).parted
: Supports both MBR and GPT; essential for large drives.Interactive vs. scriptable:
fdisk
is mostly interactive.parted
supports batch mode—great for automation.Resizing:
parted
can resize partitions (withresizepart
), but always back up data first.fdisk
does not support resizing.Safety:
- Always double-check the device name (
/dev/sda
,/dev/sdb
, etc.). Wiping the wrong disk is irreversible.- Use
lsblk
orfdisk -l
to list disks before starting.UEFI systems:
- Use GPT and create an EFI System Partition (ESP) (type
ef00
ingdisk
or set appropriately inparted
).
Final Notes
Both
fdisk
andparted
are powerful, but they serve different needs. For traditional setups with smaller disks,fdisk
is perfectly adequate. For modern systems with large drives, UEFI, or GPT requirements,parted
is the better choice.You don't need to pick one forever—knowing both give you flexibility. Just remember: always back up critical data before repartitioning , and verify device names carefully .
Basically, start with
fdisk
for simple tasks, switch toparted
when you hit its limits.The above is the detailed content of A Guide to Linux Disk Partitioning with `fdisk` and `parted`. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

The key steps for creating a self-signed SSL certificate are as follows: 1. Generate the private key, use the command opensslgenrsa-outselfsigned.key2048 to generate a 2048-bit RSA private key file, optional parameter -aes256 to achieve password protection; 2. Create a certificate request (CSR), run opensslreq-new-keyselfsigned.key-outselfsigned.csr and fill in the relevant information, especially the "CommonName" field; 3. Generate the certificate by self-signed, and use opensslx509-req-days365-inselfsigned.csr-signk

Firefox browser is the default browser for most modern Linux distributions such as Ubuntu, Mint, and Fedora. Initially, its performance might be impressive, however, with the passage of time, you might notice that your browser is not as fast and resp

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

If you find that the server is running slowly or the memory usage is too high, you should check the cause before operating. First, you need to check the system resource usage, use top, htop, free-h, iostat, ss-antp and other commands to check CPU, memory, disk I/O and network connections; secondly, analyze specific process problems, and track the behavior of high-occupancy processes through tools such as ps, jstack, strace; then check logs and monitoring data, view OOM records, exception requests, slow queries and other clues; finally, targeted processing is carried out based on common reasons such as memory leaks, connection pool exhaustion, cache failure storms, and timing task conflicts, optimize code logic, set up a timeout retry mechanism, add current limit fuses, and regularly pressure measurement and evaluation resources.

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

Frankly speaking, I cannot recall the last time I used a PC with a CD/DVD drive. This is thanks to the ever-evolving tech industry which has seen optical disks replaced by USB drives and other smaller and compact storage media that offer more storage
![Installation and Review of Q4OS Linux [Lightweight Distro]](https://img.php.cn/upload/article/001/242/473/175150507396452.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
Q4OS is a new Linux distribution that’s based on Debian; a common base that’s shared with other distributions like Ubuntu and Linux Mint. It’s aimed at users who just want a simple, stable, easy to use Linux operating system that they can convenientl
