DiyMediaServer
Featured image of post Master the Basics - How to Use Fdisk to Create Partitions Format Them and Add a Mount Point

Master the Basics - How to Use Fdisk to Create Partitions Format Them and Add a Mount Point

A Step-by-Step Guide to Partitioning, Formatting, and Mounting Drives in Linux Using fdisk and fstab

So you bought that multi-terabyte hard drive and want to bolt it onto your server. You’re staring at a fresh disk and you’re not sure where to start. I’ve got you covered.

Setting up storage on Linux looks intimidating the first time, especially when fdisk and fstab enter the picture. It’s not as bad as it looks. By the end of this guide you’ll know how to carve up a disk with fdisk, slap a filesystem on it, and wire it into fstab so it mounts automatically at boot.

The Power of Partitions (and Why They Matter)

Think of your hard drive as a giant empty filing cabinet. Without partitions, your system has no idea how to organize or access any of that space. Partitions break the drive into smaller sections, each with a specific purpose. Data here, programs there, backups over in the corner. That separation is what keeps things sane when something goes sideways.

fdisk is the tool that creates and manages those partitions. It ships with almost every Linux distribution, so you don’t have to install anything. I’ll walk you through every step, whether you’re setting up a brand-new drive or reorganizing an existing one.

Step-by-Step Guide to Using fdisk, Formatting Partitions, and Configuring fstab

Step 1: Identify the Target Disk

Before you touch anything, figure out which drive you’re actually working with. Use lsblk to list every disk and partition the kernel can see:

lsblk

You’ll get something like this:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   500G  0 disk
├─sda1   8:1    0   1M    0 part
├─sda2   8:2    0   2G    0 part /boot
└─sda3   8:3    0   498G  0 part /
sdb      8:16   0   12.7T 0 disk

Here sda is your main disk and sdb is the empty drive. We’ll work with sdb for the rest of this tutorial.

⚠️ Caution: Double-check the disk name before you do anything destructive. Pick the wrong one and you wipe a drive full of data you wanted to keep.

Step 2: Launch fdisk

Open fdisk against the target disk:

sudo fdisk /dev/sdb

You’ll see a prompt like this:

Command (m for help):

Type m to see the available commands.

Step 3: Create a New Partition

1. Delete Old Partitions (Optional)

If the disk already has partitions you want gone, type d and follow the prompts to delete them.

2. Create a New Partition

To create a new partition, type n and press Enter. fdisk will ask:

  • Partition type: Choose p for primary or e for extended. Pick p for most use cases.

  • Partition number: Press Enter to accept the default (usually 1).

  • First sector: Press Enter to accept the default (start of the disk).

  • Last sector: Press Enter to use the entire disk, or specify a size like +100G for a 100GB partition.

When you’re done you’ll see the new partition listed.

3. Write Changes to Disk

Type w to save the changes and exit fdisk. This writes the partition table to the disk. Nothing you’ve done so far actually touches the disk until you hit w, so if you panicked halfway through you can always quit with q and walk away.

Step 4: Format the Partition

You’ve got a partition, but it has no filesystem on it yet. A common choice is ext4. For a media server hosting big files, I reach for XFS instead.

sudo mkfs.xfs /dev/sdb1

That formats the first partition on sdb with XFS. Swap xfs for ext4 or btrfs if you’d rather use those.

Run lsblk again and the output should look similar to this:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   500G  0 disk
├─sda1   8:1    0   1M    0 part
├─sda2   8:2    0   2G    0 part /boot
└─sda3   8:3    0   498G  0 part /
sdb      8:16   0   12.7T 0 disk
└─sdb1   8:17   0   12.7T 0 part

Step 5: Create a Mount Point

A mount point is where the system will hang the partition in the filesystem tree. For a media drive, something like this works:

sudo mkdir -p /mnt/media

The -p flag tells mkdir to create any parent directories that don’t exist yet.

Step 6: Mount the Partition (Temporary Test)

Before you commit anything to fstab, test the mount by hand:

sudo mount /dev/sdb1 /mnt/media

Verify it’s mounted:

df -h

You should see /dev/sdb1 listed with /mnt/media as its mount point. If you don’t, stop here and figure out why before you touch fstab.

Step 7: Add the Partition to fstab

Now you want this thing to come back automatically after a reboot. That’s what /etc/fstab is for. Start by grabbing the partition’s UUID:

sudo blkid /dev/sdb1

You’ll see output like this:

/dev/sdb1: UUID="1234-5678-90AB-CDEF" TYPE="xfs"

Copy that UUID and open fstab:

sudo nano /etc/fstab

Add this line at the end of the file:

UUID=1234-5678-90AB-CDEF /mnt/media xfs defaults 0 2

Here’s what each field does:

  • UUID=1234-5678-90AB-CDEF: Unique identifier for the partition. Survives drive reordering, unlike /dev/sdb1.

  • /mnt/media: Mount point.

  • xfs: Filesystem type.

  • defaults: Standard mount options.

  • 0 2: Dump and fsck options. Safe to leave as-is for a data drive.

Save the file and exit.

Step 8: Test the fstab Configuration

Now verify your changes work without rebooting. Unmount the partition, then remount everything in fstab:

sudo umount /mnt/media
sudo mount -a

If mount -a returns clean with no errors, your configuration is good. If it throws an error, fix the fstab line before you reboot. A broken fstab can drop the system into emergency mode on the next boot, and digging your way out of that is no fun.

Wrapping It All Up

You’ve carved up a disk, formatted it, and wired it into fstab so it mounts on every boot. That same pattern works for media storage, backup targets, Docker volume directories, or anywhere else you need a dedicated chunk of disk.

One last warning. Always double-check the disk name in lsblk before you run fdisk or mkfs, and back up anything important before you reorganize a drive that already has data on it. The commands here don’t ask for confirmation, and there’s no undo.

Was this useful?

Last updated on May 20, 2026 06:56 MDT