Drives and Filesystems
- Understanding Drives and Filesystems
- Partitioning Drives
- Creating and Checking Filesystems
- Mounting and Unmounting Drives
- Persistent Mounts with
/etc/fstab
In this chapter
- Learn the difference between a drive, a partition, and a filesystem
- Choose sensible defaults for desktop and data storage
- Create, check, mount, and persist filesystems with common Linux tools
- Understand when GPT, EFI, and `/etc/fstab` matter
Storage work on Linux becomes much less intimidating once you separate the ideas involved. A drive is the physical or virtual storage device. A partition is a slice of that drive. A filesystem is the data format stored on that partition. When those three concepts are clear, the commands start making sense.
Understanding Drives and Filesystems
A Linux system can have one or many drives, and each drive can hold one or many partitions. Those partitions are then formatted with filesystems such as ext4, XFS, FAT32, or NTFS.
Common Filesystem Types
- ext4: The safest default for most Linux desktops and laptops. It is mature, reliable, and widely supported.
- xfs: A strong choice for large data volumes and storage-heavy workloads.
- btrfs: Useful when you specifically want snapshots, checksumming, and more advanced filesystem features.
- vfat (FAT32): Common for USB drives, SD cards, and EFI system partitions.
- ntfs: Mainly used for compatibility with Windows systems and shared external drives.
- swap: Disk space reserved to support memory management when RAM is under pressure.
Recommendation: If you are new to Linux, use
ext4unless you have a clear reason to choose something else.
If you want to explore btrfs in more depth, this guide is a good starting point: https://christitus.com/btrfs-guide/.
Useful Drive Management Tools
- lsblk: Show drives, partitions, mount points, and filesystem types.
- blkid: Show UUIDs and filesystem signatures.
- cfdisk: A beginner-friendly partition editor in the terminal.
- gparted: A graphical partition editor.
- mount and umount: Attach and detach filesystems.
- mkfs: Create a filesystem on a partition.
- fsck: Check and repair a filesystem.
- df: See free space on mounted filesystems.
- du: See where space is being used inside directories.
- smartctl: Inspect drive health using SMART data.
Partitioning Drives
Partitioning means dividing a drive into sections that can be managed independently. For modern Linux installations, GPT should be your default partition table unless you are dealing with very old BIOS-only hardware.
GPT and MBR
- GPT (GUID Partition Table): Modern, flexible, supports large disks, and is required for standard UEFI setups.
- MBR (Master Boot Record): Older and more limited. Only use it when legacy compatibility requires it.
Most Linux systems need at least an EFI partition and a root partition. Many installations also create a separate home partition.
Warning: Storage commands are unforgiving. Confirm the target device with
lsblkbefore you run partitioning or formatting commands.
Wiping Old Signatures
If you are rebuilding a disk from scratch, remove the old filesystem signatures first:
sudo wipefs -a /dev/sdX
This removes old signatures and helps prevent confusing leftovers from previous installations.
Partitioning with cfdisk
Run cfdisk against the target disk:
sudo cfdisk /dev/sdX
A practical flow looks like this:
- Select the correct disk.
- Choose
gptif you are creating a new partition table. - Create an EFI partition first, usually between 300 MiB and 1 GiB.
- Create the root partition, and optionally a separate home partition.
- Write the changes and quit.
For the EFI partition, set the type to EFI System. For the main Linux partitions, use Linux filesystem.
Creating and Checking Filesystems
Creating Filesystems
Warning: Creating a filesystem erases the target partition.
Common examples:
sudo mkfs.ext4 /dev/sdX1
sudo mkfs.xfs /dev/sdX2
sudo mkfs.fat -F 32 /dev/sdX1
Use FAT32 for EFI system partitions. For most Linux data and root partitions, start with ext4.
Checking and Repairing Filesystems
To check an ext4 filesystem:
sudo fsck.ext4 /dev/sdX1
To automatically answer yes to repair prompts:
sudo fsck.ext4 -y /dev/sdX1
Do not run fsck casually on mounted writable filesystems. Unmount first unless your distribution documentation explicitly says otherwise.
Viewing Filesystem Information
These commands answer slightly different questions:
df -h
lsblk -f
blkid
df -hshows usage on mounted filesystems.lsblk -fshows devices, filesystems, and mount points in one view.blkidis useful when you need UUIDs for/etc/fstab.
Mounting and Unmounting Drives
Mounting attaches a filesystem to the directory tree. Unmounting detaches it cleanly.
Temporary Mounts
sudo mount /dev/sdX1 /mnt/mydrive
sudo umount /mnt/mydrive
If needed, you can also specify the filesystem type and options:
sudo mount -t ext4 -o rw /dev/sdX1 /mnt/mydrive
If a filesystem is busy, close the processes using it before you unmount. A lazy unmount is possible with umount -l, but use it as a recovery tool rather than your default workflow.
Persistent Mounts with /etc/fstab
The /etc/fstab file controls which filesystems are mounted automatically at boot.
fstab Field Order
- Device: Usually a UUID rather than a device path.
- Mount point: Where the filesystem appears in the directory tree.
- Filesystem type: Such as
ext4,vfat,ntfs, ornfs. - Options: Mount behavior, separated by commas.
- Dump field: Legacy backup flag. Usually
0. - fsck order:
1for the root filesystem,2for other Linux filesystems,0to skip checks.
Syntax:
# <device> <mount point> <file system type> <options> <dump> <pass>
Examples:
UUID=1234-5678 /mnt/data ext4 defaults 0 2
UUID=ABCD-1234 /boot vfat defaults 0 2
/dev/sdb1 /media/usb vfat defaults,nofail 0 0
Common Mount Options
defaults: Use the default read-write mount behavior.nofail: Do not stop boot if the device is absent.noauto: Do not mount automatically at boot.ro: Mount read-only.rw: Mount read-write.user: Allow a regular user to mount the filesystem.noexec: Prevent executable files from running from that mount.uid=1000andgid=1000: Set ownership for filesystems like FAT32 that do not store Linux ownership metadata.
After editing /etc/fstab, test it before rebooting:
sudo mount -a
If mount -a completes without errors, your entries are usually safe to use at boot.
Companion resources
Key takeaways
- Think in layers: drive, partition, then filesystem.
- Use GPT for modern systems and `ext4` as the default filesystem unless you need something more specialized.
- Check the target device with `lsblk` before using `wipefs`, `mkfs`, or partitioning tools.
- Use UUIDs in `/etc/fstab` and test changes with `mount -a` before rebooting.