TRENDING
A mountain gorilla looks at the camera from green forest undergrowth
October 29, 2026
How to Compress Time-Series Metrics in Python With Gorilla Delta-of-Delta and XOR Encoding
A bronze-framed hourglass with white sand beside a small Ferris wheel ornament on a wooden table against a teal wall
October 29, 2026
NIST’s Final Post-Quantum Transition Report Puts Every Quantum-Vulnerable Public-Key Scheme on One 2030 and 2035 Clock, and Three Federal Documents Word the Deadline Three Ways
Six weathered stone columns of the Temple of Apollo at Delphi, Greece, standing on a stone platform above a valley of olive groves
October 29, 2026
Honeypots Recorded Probes Against Oracle E-Business Suite CVE-2026-101767 Seven Days After Its Patch, and the Finder’s Write-Up Is Dated Patch Day
Vintage silver stopwatch with a chain on a black background, its dial showing seconds from 5 to 60
October 29, 2026
How to Find a Slow Query in PostgreSQL 18 With pg_stat_statements, Read Its EXPLAIN ANALYZE Plan, and Fix It With the Right Index
A wooden Tower of Hanoi puzzle on a market table, with three pegs and stacked discs of different sizes
October 29, 2026
Two Labs’ Claimed Refutations of the Exponential Time Hypothesis Turn Verification Into a Statement-Reading Problem, and Their Lean Theorems Promise Only That a Constant Exists
29 Oct 2026
SXZ.io SXZ.io
  • Home
Search the Site
Popular Searches:
Technology Amazon AI
Recent Posts
A flock of snow geese in flight, seen as dark silhouettes against an orange and red sunset sky with layered clouds
How to Run Zero-Downtime Schema Migrations on PostgreSQL 18 and Block Unsafe ALTER TABLE Statements With a Python Lint Gate
October 28, 2026
An old green steel truss bridge resting on temporary supports beside a new arch bridge under completion on a river in Portland, Oregon
The Angular 2 Rewrite Turns a Migration Lesson Into a Security Bill: AngularJS Still Draws 533,480 Downloads a Week, and 10 Advisories Have No Open-Source Fix
October 28, 2026
Hundreds of yellow rubber ducks floating in a river enclosure during a duck race
WordPress 7.1.4 Closes an Unauthenticated Race in Its Own Update Routine, but 19 Older Branches Had No Backport Hours After Release
October 28, 2026
SXZ.io SXZ.io
  • Home

Categories

Articles 270 Posts
News 273 Posts
Learning Hub 243 Posts
Home/Learning Hub/How to Partition, Format, and Mount a New Disk in Linux With fdisk and parted
Learning Hub

How to Partition, Format, and Mount a New Disk in Linux With fdisk and parted

Learn to partition, format, and mount a new disk in Linux with fdisk and parted: build a safe practice disk, format with ext4 and xfs, fix a real stale filesystem signature error, and add a...

July 25, 2026 13 Min Read
68

Every Linux server, VM, and cloud instance eventually needs more than one filesystem: a separate volume for a database, extra space attached after the fact, or a second disk you want to use for backups. Before Linux can store a single file on that new disk, the disk has to be divided into partitions and each partition has to be formatted with a filesystem. This tutorial teaches that whole process from scratch, using the two tools every Linux administrator eventually has to know: fdisk and parted.

Table Of Content

  • Prerequisites
  • Understanding Partition Tables: MBR vs GPT
  • Step 1: Build a Safe Practice Disk
  • Step 2: Identify Your Target Disk
  • Step 3: Create a Partition With fdisk
  • Verify the Partition Exists
  • Step 4: Format the Partition
  • Step 5: Mount the Partition and Test It
  • Step 6: Unmount the Partition
  • Step 7: Create a Partition With parted Instead
  • The Gotcha: parted’s fs-type Argument Doesn’t Actually Format Anything
  • Step 8: Handle a Stale Filesystem Signature
  • Step 9: Get the Partition’s UUID and Add a Persistent Mount
  • Step 10: Delete a Partition Safely
  • Step 11: Clean Up Your Practice Environment
  • Common Mistakes and Troubleshooting
  • “Device or resource busy” when writing the partition table
  • Partition created but not visible in lsblk
  • “mkfs: appears to contain an existing filesystem”
  • Choosing MBR when you meant GPT (or the reverse)
  • How to Verify Everything Worked
  • Next Steps

A partition is a logical section of a physical disk that the operating system treats as its own independent storage area, the same way a whole disk would be treated. A partition table is a small structure written to the very start of the disk that records where each partition begins and ends, and what type it is. Before a disk can hold any partitions, it needs one of these tables, and Linux systems today use one of two formats: the older MBR (Master Boot Record) or the modern GPT (GUID Partition Table). A partition on its own is just an empty labeled section of the disk; it cannot store files until you also format it with a filesystem such as ext4 or xfs, which is the layer that actually organizes files and directories on the storage.

By the end of this tutorial, you will have created a partition table, created and deleted partitions with both fdisk and parted, formatted partitions with two different filesystems, mounted them by hand and persistently through /etc/fstab, and hit (and fixed) a real, easy-to-miss mistake that trips up even experienced administrators. Every command in this guide was executed while writing it, on the exact tool versions named below, so the output shown is real captured output, not a paraphrase of the manual. The task scope follows DigitalOcean’s own fdisk and parted tutorial, with every command independently re-run, verified against the official fdisk manual and the GNU parted manual, and extended with a safe disposable practice disk and a real stale-filesystem gotcha neither source covers.

Prerequisites

  • A Linux system with a bash shell and root or sudo access. This guide was tested on Ubuntu 26.04 LTS, with fdisk from util-linux 2.41.3, GNU parted 3.6, mke2fs 1.47.2 (for ext4), and xfsprogs 6.18.0 (for xfs). The concepts and commands are the same on any modern distribution; only the package manager used to install parted or xfsprogs changes.
  • Comfort running commands in a terminal. You do not need any prior partitioning experience: every command below is explained before you run it.
  • No spare physical disk is required. Step 1 shows you how to build a safe, disposable practice disk out of an ordinary file, so you can follow every step on a laptop or a cloud VM with a single disk, without any risk to your real data.

A warning before you start: partitioning and formatting are destructive operations. Writing a new partition table, or running a format command on the wrong device, permanently destroys whatever data was there. Every command in this tutorial targets a disposable loopback file you create yourself in Step 1, specifically so you can make mistakes safely while you learn. When you later repeat these steps on a real disk, always confirm the exact device name with lsblk first, and back up anything you cannot afford to lose.

Understanding Partition Tables: MBR vs GPT

Before creating anything, it helps to know what you are choosing between.

MBR is the original IBM PC partitioning scheme. It stores the partition table in a single 512-byte sector at the start of the disk, which limits it to addressing about 2.2 TB of space (2,199,023,255,040 bytes, using 512-byte sectors) and to exactly four primary partitions. If you need more than four, one primary partition can be turned into an extended partition that holds additional logical partitions inside it, a workaround GPT does not need.

GPT is the modern replacement defined as part of the UEFI specification. It removes the 2.2 TB ceiling entirely and, as you will see directly from fdisk itself in Step 3, supports up to 128 partitions by default with no primary/extended distinction. Unless you are working with old BIOS-only hardware or a legacy dual-boot setup that specifically requires MBR, GPT is the right default for new disks today, and it’s what this tutorial uses.

Step 1: Build a Safe Practice Disk

Instead of risking a real disk while you learn, you can create an ordinary file, tell the Linux kernel to treat it as a block device using a loop device, and partition that instead. Everything you do to a loop device is fully reversible: delete the file and it is as if the disk never existed.

# Context: any Linux system with root access, working in a scratch directory.
# Purpose: create a 1 GiB file to act as a disposable practice disk.
mkdir -p ~/partition-practice && cd ~/partition-practice
dd if=/dev/zero of=test-disk.img bs=1M count=1024 status=none
ls -lh test-disk.img

Expected output: -rw-r--r-- 1 root root 1.0G ... test-disk.img. The dd command copies 1024 blocks of 1 MiB of zeros from /dev/zero into the file, giving you an exactly 1 GiB file of empty space.

# Purpose: attach the file to the kernel's loop-device driver so it behaves like a real disk.
sudo losetup -fP test-disk.img
sudo losetup -a | grep test-disk

Expected output: something like /dev/loop14: [2049]:772829 (/root/partition-practice/test-disk.img). The -f flag tells losetup to pick the first free loop device automatically, and -P tells the kernel to scan the file for partitions once one exists. Note the device name it printed, such as /dev/loop14; you will use that exact name for the rest of this tutorial. Every reference to /dev/loop14 below should be replaced with whatever loop device your system assigned.

Step 2: Identify Your Target Disk

Before you partition anything, real disk or practice file, get in the habit of confirming exactly which device you are about to modify. Two commands do this:

lsblk
sudo fdisk -l /dev/loop14

lsblk (“list block devices”) shows every disk and partition the kernel currently knows about, in a tree view, without needing root. fdisk -l shows more detail about one specific device, including its size and current partition table, if any. Running both before you make changes is the single most effective habit for avoiding an accidental wipe of the wrong disk, since it is the last chance to notice you have the wrong device name.

Step 3: Create a Partition With fdisk

fdisk is an interactive, menu-driven program: you launch it against a device, then type single-letter commands. Launch it now:

sudo fdisk /dev/loop14

You will land on a Command (m for help): prompt. From here, type the following commands one at a time, pressing Enter after each:

  1. g: create a new, empty GPT partition table on the disk.
  2. n: create a new partition. fdisk will then ask for a partition number, a first sector, and a last sector; press Enter three times to accept the defaults (partition 1, using all remaining free space).
  3. w: write the new partition table to disk and exit. Nothing is actually written until this command runs; everything before it only changes fdisk’s in-memory copy.

Here is exactly what that session looks like, captured from a real run:

Command (m for help): g
Created a new GPT disklabel (GUID: 2B01E059-C304-4B45-8311-4E13236CC5FE).

Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-2097118, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2097118, default 2095103):
Created a new partition 1 of type 'Linux filesystem' and of size 1022 MiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Two details are worth pausing on. First, notice fdisk’s own prompt: Partition number (1-128, default 1). That is GPT’s 128-partition default limit, confirmed directly by the tool itself, exactly as described above. Second, if this is a genuinely blank device, fdisk may print Device does not contain a recognized partition table and silently stage a temporary DOS (MBR) label in memory before you even type your first command; this is harmless and gets replaced the moment you run g, but it can be surprising to see mentioned before you have typed anything.

Verify the Partition Exists

lsblk /dev/loop14

Expected output:

NAME       MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop14       7:14   0    1G  0 loop
└─loop14p1 259:0    0 1022M  0 part

The new partition shows up as loop14p1 (loop devices append p1, p2, and so on; a normal disk like /dev/sdb would instead show sdb1, sdb2). If you do not see the partition here, see the Troubleshooting section below before continuing.

Step 4: Format the Partition

A partition is just an empty, labeled region of disk until you format it with a filesystem. This tutorial uses ext4 first, the default filesystem on Ubuntu, Debian, and many of their derivatives, well-tested and a safe general-purpose choice. Later in this tutorial you will format a different partition as xfs, the default on RHEL-family distributions since RHEL 7 and a common choice for very large files or heavy parallel I/O.

# Purpose: create an ext4 filesystem on the new partition, with a human-readable label.
sudo mkfs.ext4 -L testdata /dev/loop14p1

Expected output (abridged): mke2fs 1.47.2 (1-Jan-2025) followed by lines about discarding device blocks, creating the filesystem, allocating group tables, and writing inode tables, ending with Writing superblocks and filesystem accounting information: done. The -L flag sets a volume label, which makes the partition easier to identify later with tools like lsblk -f or blkid.

Step 5: Mount the Partition and Test It

Formatting creates the filesystem; mounting attaches it to a directory (called a mount point) so normal file operations can reach it.

# Purpose: create a mount point, attach the partition to it, and confirm it works.
sudo mkdir -p /mnt/test-partition
sudo mount /dev/loop14p1 /mnt/test-partition
df -h /mnt/test-partition
echo "hello from sxz test" | sudo tee /mnt/test-partition/hello.txt
cat /mnt/test-partition/hello.txt

Expected output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/loop14p1   988M  276K  921M   1% /mnt/test-partition
hello from sxz test

df -h confirms the partition is mounted and shows how much space is used; writing and reading back hello.txt confirms the filesystem genuinely works, not just that the mount command returned success.

Step 6: Unmount the Partition

sudo umount /mnt/test-partition

Always unmount a filesystem before you repartition or reformat the underlying device. Trying to modify a partition that is still mounted is one of the most common sources of the Device or resource busy error covered in Troubleshooting below.

Step 7: Create a Partition With parted Instead

fdisk is interactive by nature, which is great for learning but awkward to put in a script. parted can do the same job non-interactively, one command per line, which is why it shows up in automation and provisioning scripts. First, remove the existing partition so you have a clean disk to work with again:

sudo fdisk /dev/loop14

At the prompt, type d (delete the partition, it will be selected automatically since there is only one), then w (write and exit). Now recreate the layout with parted in a single pair of non-interactive commands:

# Purpose: create a new GPT label and a partition spanning the whole disk, without an interactive prompt.
sudo parted -s /dev/loop14 mklabel gpt
sudo parted -s /dev/loop14 mkpart primary ext4 0% 100%
sudo parted -s /dev/loop14 print

The -s flag means “script mode”: run non-interactively and don’t ask for confirmation. mkpart primary ext4 0% 100% reads as “create a partition named primary, hinted as ext4, spanning from the very start to the very end of the disk.” Expected output from print:

Model: Loopback device (loopback)
Disk /dev/loop14: 1074MB
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1073MB  1072MB  ext4         primary

The Gotcha: parted’s fs-type Argument Doesn’t Actually Format Anything

That File system: ext4 column is misleading if you are new to parted. The ext4 in mkpart primary ext4 0% 100% is only a type hint stored in the partition table, it does not run mkfs for you. You can confirm this yourself:

sudo blkid /dev/loop14p1

If the partition table still contains a filesystem signature from a previous format at those same sectors (as it will if you are following this tutorial from Step 4 onward on the same practice disk), blkid reports the old filesystem, since parted never touched the actual data blocks. This leads directly into the next step.

Step 8: Handle a Stale Filesystem Signature

This is a real mistake that even experienced administrators run into, reproduced here exactly as it happened while writing this tutorial. After deleting the ext4 partition in Step 7 and recreating it at the same sectors with parted, formatting it as xfs failed:

$ sudo mkfs.xfs -L testxfs /dev/loop14p1
mkfs.xfs: /dev/loop14p1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.

Why this happens: deleting a partition with fdisk (or recreating one with parted) only removes the entry from the partition table. It does not erase the filesystem superblock that mkfs.ext4 wrote to the underlying disk blocks earlier. When a new partition lands on the same sectors, tools like blkid and mkfs can still see the old filesystem’s signature and, correctly, refuse to silently destroy it. This is a safety feature, not a bug, but it surprises people who assume deleting a partition wipes its contents.

The fix is to explicitly wipe old signatures before formatting:

# Purpose: erase filesystem/RAID/LVM signatures so mkfs can format cleanly.
sudo wipefs -a /dev/loop14p1

Expected output: /dev/loop14p1: 2 bytes were erased at offset 0x00000438 (ext4): 53 ef, the exact two magic bytes that identify an ext4 superblock. With the stale signature cleared, formatting succeeds cleanly:

sudo mkfs.xfs -L testxfs /dev/loop14p1
sudo mkdir -p /mnt/test-partition
sudo mount /dev/loop14p1 /mnt/test-partition
df -hT /mnt/test-partition

Expected output:

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/loop14p1  xfs   958M   51M  908M   6% /mnt/test-partition

The alternative to wipefs, forcing the format directly with mkfs.xfs -f, works too, but running wipefs first is clearer about what is happening and is the safer habit to build, especially on a real disk where you want to be certain about what you are erasing before you do it.

Step 9: Get the Partition’s UUID and Add a Persistent Mount

Everything so far is mounted only until the next reboot. To make a mount permanent, Linux uses /etc/fstab, a table of filesystems the system mounts automatically at boot. Persistent entries should reference a partition’s UUID (a unique identifier baked into the filesystem itself) rather than a device name like /dev/loop14p1, because device names can shift between boots, especially with multiple disks, while the UUID never changes.

sudo blkid /dev/loop14p1

Expected output: /dev/loop14p1: LABEL="testxfs" UUID="0aad2b05-b7c0-48fd-8c90-b2edb4eafe44" BLOCK_SIZE="512" TYPE="xfs" .... Copy the UUID value, then add a line like this to /etc/fstab (use sudo visudo-style caution: edit with sudo nano /etc/fstab or a similar editor, never overwrite the file):

UUID=0aad2b05-b7c0-48fd-8c90-b2edb4eafe44  /mnt/test-partition  xfs  defaults,nofail  0  2

Each field matters: the UUID identifies the partition, /mnt/test-partition is where it mounts, xfs is the filesystem type, defaults uses standard mount options, 0 disables legacy dump backups, and 2 tells fsck to check this filesystem after the root filesystem at boot. The nofail option is a safety net worth adding to any non-critical entry: without it, a missing or failed disk at boot time can drop the whole machine into an emergency recovery shell; with it, the boot simply continues without that mount.

Before you reboot, always validate a new fstab line with:

sudo mount -a

This mounts everything listed in /etc/fstab that isn’t already mounted, using the same parsing the boot process uses, so any typo or syntax error shows up immediately in a terminal you control, instead of during the next unattended reboot.

Step 10: Delete a Partition Safely

To remove a partition entirely (again, only on your disposable practice disk), unmount it first, then use fdisk:

sudo umount /mnt/test-partition
sudo fdisk /dev/loop14

At the prompt: d to delete (fdisk auto-selects the only partition when there is just one; with multiple partitions it asks which number), then w to write and exit. Deleting a partition does not erase its data, as you saw firsthand in Step 8; it only removes the partition table entry. If you actually need the underlying data gone, follow the deletion with wipefs -a or, for genuinely sensitive data, an overwrite tool, since a deleted partition’s contents are still recoverable until something overwrites those blocks.

Step 11: Clean Up Your Practice Environment

# Purpose: detach the loop device and remove the practice file, leaving your system exactly as it was.
sudo losetup -d /dev/loop14
rm ~/partition-practice/test-disk.img

This detaches the loopback device and deletes the backing file. Nothing about your real disks was ever touched.

Common Mistakes and Troubleshooting

“Device or resource busy” when writing the partition table

This means the kernel cannot re-read the partition table because something is still using the disk, most often a filesystem that is still mounted, or a swap partition that is still active. Run sudo umount on any mounted partitions from that disk (or sudo swapoff for swap) and try again.

Partition created but not visible in lsblk

Occasionally the kernel’s in-memory view of a disk’s partitions falls out of sync after changes, particularly on disks that were already in use. Force a rescan with sudo partprobe /dev/loop14 (or sudo partx -u /dev/loop14 if partprobe is not installed) before assuming something went wrong.

“mkfs: appears to contain an existing filesystem”

Covered in depth in Step 8: this is mkfs correctly refusing to silently destroy a leftover filesystem signature from a previous format at the same sectors. Run sudo wipefs -a <device> first if you are certain you want to proceed, or investigate before doing so if you did not expect a signature to be there.

Choosing MBR when you meant GPT (or the reverse)

If a disk needs to boot on very old BIOS-only hardware, or is part of an existing MBR-based dual-boot setup, you may specifically need MBR (fdisk’s o command instead of g). For any new disk on modern hardware, default to GPT: it has no practical size limit at today’s disk capacities and no four-partition ceiling to work around.

How to Verify Everything Worked

Before you consider a real-disk partitioning job finished, confirm all of the following: lsblk -f shows the expected partition, filesystem type, and label; df -h shows it mounted at the expected path with sensible free space; a test file written to the mount point survives an umount and re-mount; and, if you added an /etc/fstab entry, sudo mount -a completes with no errors. Only after all four checks pass should you trust the partition with real data or reboot the machine to confirm the fstab entry mounts automatically.

Next Steps

From here, natural directions to keep learning include LVM (Logical Volume Manager), which adds a flexible layer on top of partitions so you can resize and snapshot volumes without unmounting them; using parted resizepart or growpart to expand a partition that has run out of space; and setting up software RAID with mdadm across multiple disks for redundancy. All three build directly on the partition and filesystem fundamentals you just practiced.

Tags:

Disk PartitioningfdiskLinux StoragepartedUbuntu Server

Share

Rows of server racks inside CERN's computer center, the kind of physical infrastructure that hypervisor-based pod isolation like Kata Containers runs on
Previous Post

Red Hat’s OpenShift Sandboxed Containers Turn AI Agent Isolation Into a One-Line Pod Spec

High voltage electricity transmission tower and power lines silhouetted against an evening sky
Next Post

3 Gigawatts of Data Centers Dropped Off the PJM Grid After a Power Line Failed

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest
28 Oct
How to Run Zero-Downtime Schema Migrations on PostgreSQL 18 and Block Unsafe ALTER TABLE Statements With a Python Lint Gate
28 Oct
The Angular 2 Rewrite Turns a Migration Lesson Into a Security Bill: AngularJS Still Draws 533,480 Downloads a Week, and 10 Advisories Have No Open-Source Fix
Trending
October 28, 2026
How to Run Zero-Downtime Schema Migrations on PostgreSQL 18 and Block Unsafe ALTER TABLE Statements With a Python Lint Gate
October 28, 2026
The Angular 2 Rewrite Turns a Migration Lesson Into a Security Bill: AngularJS Still Draws 533,480 Downloads a Week, and 10 Advisories Have No Open-Source Fix
October 28, 2026
WordPress 7.1.4 Closes an Unauthenticated Race in Its Own Update Routine, but 19 Older Branches Had No Backport Hours After Release
October 28, 2026
How to Compress Time-Series Metrics in Python With Gorilla Delta-of-Delta and XOR Encoding
October 28, 2026
NIST’s Final Post-Quantum Transition Report Puts Every Quantum-Vulnerable Public-Key Scheme on One 2030 and 2035 Clock, and Three Federal Documents Word the Deadline Three Ways
October 28, 2026
Honeypots Recorded Probes Against Oracle E-Business Suite CVE-2026-101767 Seven Days After Its Patch, and the Finder’s Write-Up Is Dated Patch Day

Related Posts

A laptop wrapped in a chain and padlock, illustrating least-privilege controls for AI agents.
Learning Hub

How to Secure Tool-Using AI Agents Before They Touch Production

June 8, 2026
Colorful sticky notes arranged on an office wall, symbolizing governance checklists and planning.
Learning Hub

AI Governance for Agentic Apps: A Practical Checklist for Builders

June 8, 2026
A technician connects green fiber optic cables at a data center, representing a private production inference endpoint.
Learning Hub

How to Deploy a Fine-Tuned LLM Behind a Private Production Inference Endpoint

June 8, 2026
Narrow aisle behind black supercomputer racks in a data center
Learning Hub

Kubernetes SELinux Volume Labeling: What Cluster Operators Should Audit Before v1.37

June 8, 2026
SXZ.io SXZ.io
  • [email protected]

Categories

Articles
Learning Hub
News

All Rights Reserved by SXZ.io ©2026