Disk Management & Partitions
Every Linux server stores its data on disks, and knowing how those disks are organised is one of the most important skills in server administration. When you add a new disk to a cloud server, resize a volume, or troubleshoot a “disk full” error, you need to understand the layers that sit between the raw hardware and the folders you actually use. This page walks you through block devices, partitions, and filesystems on Ubuntu (22.04/24.04 LTS), and shows you how to inspect and prepare a disk safely.
The three layers: block device, partition, filesystem
It helps to picture disk storage as three stacked layers. Each one builds on the one below it.
- A block device is the raw disk hardware as Linux sees it (a “block device” is any storage device that reads and writes data in fixed-size chunks called blocks). On Ubuntu these show up as files under
/dev, such as/dev/sda(the first SATA/SCSI disk),/dev/sdb(the second), or/dev/nvme0n1(the first NVMe SSD). The whole physical disk is one block device. - A partition is a slice of a block device. You divide a disk into one or more partitions so you can use parts of it for different purposes. Partitions are numbered, so the first partition on
/dev/sdais/dev/sda1, the second is/dev/sda2, and so on. - A filesystem is the structure that organises files and folders inside a partition (think of it as the index and shelving system of a library). Common Linux filesystems are ext4 (the long-standing default on Ubuntu) and xfs. Until a partition has a filesystem, it can’t store files.
So the order is: a disk (block device) is split into partitions, each partition gets a filesystem, and then you mount that filesystem (attach it to a folder) so you can use it. This page covers the first three steps; mounting is covered in its own page.
A partition is just a boundary marker, not storage you can use yet. A common beginner mistake is creating a partition and expecting to write files to it. You must format it with a filesystem first.
Inspecting disks with lsblk
lsblk (list block devices) is the friendliest way to see your storage. It draws a tree of disks and their partitions, with no risk of changing anything. Use it any time you want a quick overview.
lsblk
Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 39.9G 0 part /
├─sda14 8:14 0 4M 0 part
└─sda15 8:15 0 106M 0 part /boot/efi
sdb 8:16 0 20G 0 disk
Here sda is a 40 GB disk that already has partitions, with sda1 mounted at / (the root of the filesystem). The disk sdb is 20 GB and has no partitions and no mount point — it’s brand new and unused. That is the disk we’ll prepare below.
Add -f to see filesystem types and labels, which is useful for confirming whether a partition is formatted:
lsblk -f
Output:
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 ext4 1.0 a1b2c3d4-1234-5678-9abc-def012345678 30.1G 18% /
└─sda15 vfat FAT32 1234-ABCD 99.5M 6% /boot/efi
sdb
sdb shows no FSTYPE, confirming it has no filesystem yet.
Inspecting partition tables with fdisk -l
fdisk is a partition-editing tool. With the -l (list) flag it only reads the partition table and prints it, so fdisk -l is safe to run. It needs sudo because reading raw disks is privileged.
sudo fdisk -l /dev/sdb
Output:
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
The absence of a partition table at the bottom tells you this disk is empty. On a partitioned disk you’d also see a “Disklabel type” line — either gpt (GUID Partition Table, the modern standard with no practical limit on disk size or partition count) or dos/MBR (the older standard, limited to 2 TB). Use GPT for anything new.
lsblk vs fdisk -l — when to use which
| Tool | What it shows | Needs sudo | Use it when |
|---|---|---|---|
lsblk | Tree of disks, partitions, sizes, mount points | No | Quick everyday overview of what’s mounted where |
lsblk -f | Same, plus filesystem type and UUID | No | Checking if a partition is formatted |
sudo fdisk -l | Partition table details, sector counts, label type | Yes | Inspecting the raw partition layout before editing |
sudo blkid | UUIDs and filesystem types per partition | Yes | Getting a UUID for /etc/fstab |
Creating and formatting a partition
WARNING: The commands below permanently erase data. Partitioning and formatting destroy everything on the target disk. Always double-check the device name with
lsblkfirst — formatting/dev/sdainstead of/dev/sdbwill wipe your running system. There is no undo.
Here is the full, safe workflow for taking the empty /dev/sdb from above and turning it into usable storage. Only do this on a disk you know is empty.
Step 1 — create a partition
We’ll use fdisk interactively to create one partition that fills the whole disk.
sudo fdisk /dev/sdb
At the Command (m for help): prompt, type these letters, pressing Enter after each. Accept the defaults (just press Enter) when asked for partition number, first sector, and last sector:
g (create a new empty GPT partition table)
n (add a new partition)
(press Enter to accept default partition number 1)
(press Enter to accept default first sector)
(press Enter to accept default last sector — uses the whole disk)
w (write the changes to disk and exit)
After w, fdisk saves the new table and exits. Confirm the new partition exists:
lsblk /dev/sdb
Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 20G 0 part
sdb1 now exists, but it still has no filesystem.
Step 2 — create a filesystem with mkfs
mkfs (make filesystem) writes a filesystem onto a partition. The variant mkfs.ext4 creates an ext4 filesystem, which is the safe default for general server storage on Ubuntu.
sudo mkfs.ext4 /dev/sdb1
Output:
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 7f9c2a18-3e4b-4c2d-9a1f-0b2c3d4e5f60
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Step 3 — verify
Run lsblk -f again and you’ll now see ext4 next to sdb1. The partition is ready to be mounted to a folder so you can store files on it (see the Mounting drives page for that final step).
lsblk -f /dev/sdb
Output:
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sdb
└─sdb1 ext4 1.0 7f9c2a18-3e4b-4c2d-9a1f-0b2c3d4e5f60
Best Practices
- Always run
lsblkand confirm the exact device name before any partitioning or formatting command — a wrong device name causes permanent data loss. - Prefer GPT partition tables (
gin fdisk) for any new disk; MBR is only needed for very old systems. - Use ext4 for general-purpose server storage unless you have a specific reason to choose xfs (good for very large files and high parallelism).
- Treat
lsblk,lsblk -f, andsudo fdisk -las your safe, read-only inspection tools — reach for them first whenever you’re unsure. - Record the filesystem UUID (from
lsblk -forsudo blkid); you’ll use it to mount the disk reliably in/etc/fstab. - Never format a disk that has a mount point under it (like
/or/boot/efi) — those are in active use by the running system.