Loading...

Lab 18: Partitioning a Disk Using fdisk

Identify a newly attached disk, create a primary partition using fdisk, and write the partition table safely. Verify the new device node exists and prepare it for use by formatting the partition with ext4.

storage core troubleshooting

Scenario

A new 10GB disk has been attached at /dev/sdc. You are tasked with confirming the disk is present, creating a new primary partition using fdisk, writing the changes, and preparing the partition for use by formatting it.

Operator context

Partitioning is irreversible when done wrong. The job is proving you targeted the correct disk, wrote the expected table, and verified the partition exists before you touch filesystems.

Objective

  • Confirm /dev/sdc is present and unpartitioned.
  • Launch fdisk and create a new primary partition.
  • Write the partition table and exit cleanly.
  • Verify the new partition device node exists (example: /dev/sdc1).
  • Format the partition as ext4 to prepare it for use.

Concepts

  • You run fdisk against the disk device (example: /dev/sdc), not a partition.
  • Changes are not committed until you write them. In fdisk, n defines a partition and w writes it to disk.
  • Verification is part of the task. After writing, confirm the kernel sees the new partition device node (example: /dev/sdc1).
  • Filesystem creation is destructive. Format only after you confirm the partition is the one you intended to create.

Walkthrough

Step 1: Confirm the new disk is present.
Command
lsblk

lsblk is your first proof that the kernel can see the disk. Confirm size and naming so you do not partition the wrong device.

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk
├─sda1   8:1    0  512M  0 part /boot
└─sda2   8:2    0 39.5G  0 part /
sdc      8:32   0   10G  0 disk
Step 2: Launch fdisk on the whole disk.
Command
sudo fdisk /dev/sdc

You run fdisk on the disk device (not a partition). From here you create the partition interactively. Nothing is committed until you write changes.

Welcome to fdisk. Type 'm' for help.
Step 3: Create a new primary partition inside fdisk.
Command
n

n creates a new partition definition in the in-memory table. For a single partition lab scenario, you typically accept defaults (partition 1, default first sector, default last sector).

Partition type: primary (default p)
Partition number: 1
First sector: (default)
Last sector: (default)
Created a new partition 1 of type 'Linux' and size ~10 GiB.
Step 4: Write the partition table and exit.
Command
w

w commits changes to disk and exits fdisk. After writing, the kernel should pick up the new table and the partition device node should appear.

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Step 5: Verify the new partition exists.
Commands
lsblk
sudo fdisk -l /dev/sdc

Confirm the kernel sees the partition (example: /dev/sdc1). If the partition does not appear, stop and re-check the device you modified before taking any further action.

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdc      8:32   0   10G  0 disk
└─sdc1   8:33   0   10G  0 part
Step 6: Format the new partition for use.
Command
sudo mkfs.ext4 /dev/sdc1

Formatting creates the filesystem the OS can mount and use. Once complete, the partition is ready to be mounted to a directory and used for storage.

mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: 11112222-3333-4444-aaaa-bbbbccccdddd
Filesystem created successfully.

Common breakpoints

I targeted the wrong disk

Stop immediately and document what happened. This is why you confirm with lsblk -p and match by size and layout before running fdisk. Treat it as a high-risk change.

The partition device node did not appear

Re-check with lsblk and sudo fdisk -l /dev/sdc. If the table did not write as expected, do not format anything until you can prove what is on disk.

mkfs was run on the disk instead of the partition

Formatting should target the partition node (example: /dev/sdc1), not the whole disk (example: /dev/sdc). Confirm the target with lsblk -f before re-running mkfs.

I exited fdisk without writing

If you quit without w, no changes were committed. Re-run sudo fdisk /dev/sdc and confirm whether the partition exists before repeating steps.

Cleanup checklist

This lab is safe to leave as-is if you are using the partition in the next storage lab. If this was a disposable test disk, confirm you created the expected partition and filesystem before moving on.

Commands
lsblk -f
sudo fdisk -l /dev/sdc
Success signal

lsblk -f shows /dev/sdc1 exists and has an ext4 filesystem.

Reference

  • lsblk: Lists block devices and partitions to confirm device presence and structure.
    • -f: Show filesystem type, UUID, and label for each device.
    • -p: Show full device paths (example: /dev/sdc, /dev/sdc1).
  • fdisk <disk>: Interactive partition editor for creating and writing a partition table.
    • n: Create a new partition definition.
    • w: Write changes to disk and exit.
    • p: Print the current partition table in the session.
    • q: Quit without writing changes.
  • fdisk -l <disk>: Lists the partition table for a disk (verification view).
  • mkfs.ext4 <partition>: Creates an ext4 filesystem on a partition.
    • -L <label>: Set a filesystem label (example: -L DATA).