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.
Series: Learning Linux from Scratch
- 1. Learning Linux from Scratch — After a Full IT Apprenticeship
- 2. What is Linux?
- 3. The Filesystem
- 4. Users and Permissions
- 5. Installing and Managing Software
- 6. Text Editors
- 7. Shell Scripting Basics
- 8. Process Management
- 9. Networking Fundamentals
- 10. SSH
- 11. systemd and Services
- 12. Disk Management
- 13. Users and Groups — In Depth
- 14. Cron and Scheduled Tasks
- 15. Firewall — iptables and ufw
- 16. Environment Variables and the Shell
- 17. Log Management
- 18. Kernel Module Management
- 19. The /proc Filesystem — In Depth
- 20. The /sys Filesystem and udev
- 21. Kernel Parameters and sysctl
- 22. Compiling and Installing a Custom Kernel
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:
lsblkNAME 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 -fPartitions
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/sdbThis opens an interactive prompt. Key commands:
p— print the current partition tablen— create a new partitiond— delete a partitiont— change partition typew— write changes and exitq— 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/sdbOr 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/sdb1Common 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/sdb1Mounting
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/dataNow /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/dataTo see all currently mounted filesystems:
mount | column -tOr more readably:
df -hdf 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/fstabEach 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/sdb1fstab options
The options column controls how the filesystem is mounted:
defaults— standard options (rw, suid, exec, auto, nouser, async)ro— read onlynoexec— do not allow execution of binariesnoauto— do not mount automatically at bootuser— allow non-root users to mount this filesystem
The last two columns:
dump— whether the filesystem should be backed up bydump. Almost always0.pass— filesystem check order at boot. Root filesystem should be1, others2,0to skip.
After editing fstab, test it before rebooting:
sudo mount -aThis 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 -hShows 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 -hSort 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.