Linux··5 min

Disk Management

Disks on Linux are not plug and play. Understanding how partitions, filesystems, and mounting work gives you real control over your storage — and the knowledge to fix things when they go wrong.

Disks on Linux are not plug and play in the way Windows makes them feel. Understanding how partitions, filesystems, and mounting work gives you real control over your storage — and the knowledge to fix things when they go wrong.

How Linux sees disks

Linux represents disks and partitions as files in /dev.

  • /dev/sda — first SATA or SCSI disk
  • /dev/sdb — second disk
  • /dev/nvme0n1 — first NVMe disk
  • /dev/sda1 — first partition on sda
  • /dev/sda2 — second partition on sda

To see all block devices (disks and partitions) on your system:

lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0   500G  0 disk
├─sda1        8:1    0   512M  0 part /boot/efi
├─sda2        8:2    0     2G  0 part /boot
└─sda3        8:3    0 497.5G  0 part /
nvme0n1     259:0    0     1T  0 disk
└─nvme0n1p1 259:1    0     1T  0 part /data

For more detail including filesystem type and UUIDs:

lsblk -f

Partitions

A partition is a defined region of a disk. Partitioning a disk lets you divide it into separate sections with different purposes or filesystems.

fdisk

fdisk is the standard tool for managing MBR partition tables. For GPT (modern systems), gdisk or parted are preferred — but fdisk now handles GPT too.

sudo fdisk /dev/sdb

This opens an interactive prompt. Key commands:

  • p — print the current partition table
  • n — create a new partition
  • d — delete a partition
  • t — change partition type
  • w — write changes and exit
  • q — quit without saving

Be careful. fdisk on the wrong disk destroys data. Always confirm the device name with lsblk first.

parted

parted is more powerful and supports both MBR and GPT:

sudo parted /dev/sdb

Or non-interactively:

sudo parted /dev/sdb mklabel gpt
sudo parted /dev/sdb mkpart primary ext4 0% 100%

Filesystems

A partition is just raw space. Before you can store files on it, you need to create a filesystem — a structure that organises data into files and directories.

Creating a filesystem

sudo mkfs.ext4 /dev/sdb1

Common filesystem types:

  • ext4 — the standard Linux filesystem. Reliable, well-supported, good default choice.
  • xfs — high performance, good for large files and high throughput. Used by default on RHEL/Fedora.
  • btrfs — modern filesystem with snapshots, compression, and built-in RAID. More complex.
  • vfat / fat32 — compatible with Windows and macOS. Use for USB drives meant to work across systems.
sudo mkfs.xfs /dev/sdb1
sudo mkfs.vfat -F 32 /dev/sdb1

Mounting

On Linux, accessing a filesystem means mounting it to a directory. That directory is called the mount point.

sudo mkdir /mnt/data
sudo mount /dev/sdb1 /mnt/data

Now /mnt/data shows the contents of the filesystem on /dev/sdb1. Any path under /mnt/data reads from and writes to that partition.

To unmount:

sudo umount /mnt/data

To see all currently mounted filesystems:

mount | column -t

Or more readably:

df -h

df shows disk usage. -h makes sizes human readable.

/etc/fstab

Mounting manually only lasts until the next reboot. To mount filesystems automatically on boot, add them to /etc/fstab.

cat /etc/fstab

Each line defines one mount:

# device          mountpoint    fstype  options       dump  pass
UUID=abc123...    /             ext4    defaults      0     1
UUID=def456...    /boot/efi     vfat    umask=0077    0     1
UUID=ghi789...    /data         ext4    defaults      0     2

Using UUIDs instead of device names (/dev/sda1) is important. Device names can change between boots — UUIDs do not.

To find the UUID of a partition:

sudo blkid /dev/sdb1

fstab options

The options column controls how the filesystem is mounted:

  • defaults — standard options (rw, suid, exec, auto, nouser, async)
  • ro — read only
  • noexec — do not allow execution of binaries
  • noauto — do not mount automatically at boot
  • user — allow non-root users to mount this filesystem

The last two columns:

  • dump — whether the filesystem should be backed up by dump. Almost always 0.
  • pass — filesystem check order at boot. Root filesystem should be 1, others 2, 0 to skip.

After editing fstab, test it before rebooting:

sudo mount -a

This mounts everything in fstab that is not already mounted. If there is an error in fstab, you will see it now rather than on the next boot when a broken fstab can prevent the system from starting.

Checking disk usage

df -h

Shows used and available space on each mounted filesystem.

du -sh /home/jan/*

du shows disk usage of specific directories. -s summarises (one line per argument), -h is human readable. Useful for finding what is taking up space.

du -sh /* 2>/dev/null | sort -h

Sort all top-level directories by size. 2>/dev/null suppresses permission errors.


Disk management is one of those areas where a mistake can mean data loss. The pattern is always the same: identify the correct device with lsblk, partition it if needed, create a filesystem, mount it, and add it to fstab for persistence. Do not rush the first step.

Next up: users and groups in depth — /etc/passwd, /etc/shadow, and the sudoers file.

0 views