Linux Disk Management: Partition, Format, and Mount
You will add a new disk to a Linux server, create a GPT partition, format it, and mount it persistently. By the end you will have extra storage that survives reboots, with a verification check after every destructive step.
Learning Objectives
- Identify disks safely with lsblk before touching them.
- Create a GPT partition and format it with a journaling filesystem.
- Mount it persistently by UUID.
- Time: ~2 hours · Difficulty: Intermediate · Prereqs: a server with a second, empty disk.
Architecture Overview
Environment Setup
You will need: a Linux server and a second empty block device (a fresh virtual disk works well).
Before you begin: double-check the target device, formatting the wrong disk destroys data.
Prerequisites
- A Linux system with a spare empty disk (VM disk or loop device; never practice on data disks).
- parted and e2fsprogs installed:
sudo apt install -y parted e2fsprogs. - Root or sudo access for partitioning and formatting.
- The install VM lab if you need a safe sandbox.
Step-by-Step Execution
Confirm the device name and that it is empty before any change, this prevents catastrophic mistakes.
Expected output:
What this teaches: lsblk renders the block topology (disk, part, mountpoint) so you pick the right device; confirming emptiness here prevents catastrophic wrong-disk mistakes.
GPT is the modern partition table supporting large disks and many partitions.
sudo parted -s /dev/sdb mklabel gpt mkpart primary ext4 1MiB 100%Expected output:
(no output on success; verify with: lsblk /dev/sdb)
sdb 10G disk
`-sdb1 10G part
What this teaches: mklabel gpt writes a modern partition table; mkpart carves one full-disk partition non-interactively. Starting at 1MiB aligns the partition with physical sector boundaries, while a 0% start can trigger alignment warnings; GPT replaces MBR's 2 TB and 4-partition limits.
ext4's journal protects metadata consistency across crashes.
sudo mkfs.ext4 -L data /dev/sdb1
Expected output:
Creating filesystem with 2621440 4k blocks and 655360 inodes
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
What this teaches: mkfs.ext4 writes the journaling filesystem structures; -L sets a human-readable label as a second stable identifier alongside the UUID.
UUID-based fstab entries stay correct even if device order changes.
BACK UP FSTAB AND CREATE THE MOUNT POINT
sudo cp -a /etc/fstab /etc/fstab.bak && sudo mkdir -p /mnt/dataRead the UUID with sudo blkid. The $() substitution runs in your shell before tee elevates privileges, so an unprivileged blkid here can return an empty UUID and write a broken fstab line. Validate the syntax with findmnt --verify before mounting.
APPEND THE FSTAB ENTRY, VALIDATE, THEN MOUNT
UUID=$(sudo blkid -s UUID -o value /dev/sdb1)
[ -n "$UUID" ] || { echo "ERROR: empty UUID"; exit 1; }
echo "UUID=$UUID /mnt/data ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
sudo findmnt --verify && sudo mount -a
Expected output:
UUID=a1b2c3d4-5678-90ab-cdef-1234567890ab /mnt/data ext4 defaults,nofail 0 2
(mount -a produced no errors)
What this teaches: sudo blkid reads the UUID reliably; findmnt --verify checks fstab syntax before anything mounts; nofail keeps a missing disk from hanging the boot, but it does not forgive malformed fstab syntax, which is why validation comes first.
How It Works
Disks become usable storage in four layers: the partition table describes layout, partitions are address ranges, filesystems organize bytes within them, and mounts graft them into the directory tree. parted edits the first layer, mkfs the third, and fstab plus mount handle the fourth. Confusing the layers is how data gets destroyed, so each step targets exactly one.
GPT is the modern partition table: 128 partitions by default, disks beyond 2 TB, and a backup header at the end of the disk for recovery. parted -s scripts it deterministically, which matters because interactive fdisk sessions are not reproducible and not auditable.
ext4's journal is the reliability feature: metadata changes are written to the journal first, so a crash replays to a consistent state instead of requiring a full fsck. The label (-L data) and UUID together give two stable identifiers, so mounts survive device reordering.
Progress So Far
Testing & Validation
df -h /mnt/data && touch /mnt/data/test && ls -l /mnt/dataYou should see the mounted size and a writable test file. If both pass, your new storage is ready and persistent.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| parted warns the disk is in use | A partition table is mounted or held by the kernel | Unmount everything on the disk and confirm with lsblk before proceeding |
| mkfs refuses: device contains a filesystem | Residual signatures from previous use | Wipe first with wipefs -a when you are certain the disk is expendable |
| New partition missing after parted | Kernel did not re-read the table | Run partprobe or partx -u to force a re-read |
| mount: wrong fs type | fstab TYPE field mismatches the formatted filesystem | Match blkid TYPE= output; use auto only as a fallback |
| System booted to emergency shell | fstab entry for the new disk is wrong | nofail lets the boot continue past a failed mount; fix the entry and reboot. Validate new entries with findmnt --verify first |
| 4K alignment warnings | Partition start not aligned to physical sectors | Start the partition at an explicit aligned offset (mkpart primary ext4 1MiB 100%); a 0% start can trigger alignment warnings |
Troubleshooting
- mount -a errors: a bad fstab line; the
nofailoption prevents a boot hang while you fix it. - Device busy: something is using it; check with
lsof /dev/sdb1. - Wrong disk formatted: stop immediately; restore from backup. Always verify with lsblk first.
Extension Ideas
- Make the storage flexible with Logical Volume Management.
- Explore mount options further in Mounting & Filesystem Management.
- Try XFS instead of ext4 and compare resize behaviour.
Key Results
- Added and prepared a 10GB disk with a verified mount.
- Used GPT and a journaling filesystem for resilience.
- Made the mount persistent and boot-safe via UUID + nofail.
- Validated every destructive step before proceeding.
Key Takeaways
- lsblk before parted: identify the right disk every time.
- GPT plus parted -s gives scriptable, modern partitioning.
- mkfs.ext4 -L labels the filesystem for human-friendly identification.
- Mount by UUID with nofail for reboot-safe persistence.
- Validate with mount -a before trusting a reboot.
Practice Challenges
Challenge 1: Two-partition layout
Goal: split a 10G disk into a 6G ext4 data partition and a 4G xfs scratch partition, both mounted by UUID.
Hint: mkpart with percentage ranges, then two fstab lines.
Challenge 2: Wrong-disk drill
Goal: in a VM with two identical empty disks, document a procedure that guarantees you partition the right one.
Hint: compare /dev/disk/by-id entries before touching parted.