Jarkko's guides
You are here: Home » Linux » Partitions & mounting

Partitions & mounting

File systems

A file system is how files are stored on a storage device, including the structure of storing the file data itself, but also its metadata such as the filename, creation/access time, etc. Common file systems were/are:

File system Since Used by which OS Is default in this Linux distribution
FAT32/VFAT 1996 Windows 95; still common on USB sticks and the ESP partition
NTFS 1.x 1993 Windows NT 3.1
NTFS 3.x 2000 Windows 2000 up to now (Windows 10/11)
Ext 1992 Linux
Ext2 1993 Linux
Ext3 2001 Linux
Ext4 2008 Linux Debian, Ubuntu, Linux Mint
XFS 1994 Linux Red Hat Enterprise Linux
Btrfs 2009 Linux Fedora, openSUSE

Ext2 was the standard file system for Linux for quite a while since the 1990s. Ext3 introduced a journal, which protects against data corruption in case the system crashes or loses power. Before a change in made to a file on the disk a journal entry is created first. The journal entry is marked as completed after the change is made. Multiple levels of protection are possible. By default only metadata (not the file contents) is put in the journal. Ext4 has enhanced performance, support for larger files and better allocation techniques.

XFS and Btrfs are mostly used by enterprises:

  • XFS has metadata journaling, Copy on Write and is optimized for scalability, large files and high-performance workloads.
  • Btrfs has support for snapshots, self-healing through checksums and integrated RAID. It focuses on data integrity and efficient storage management.

Partitions

Partitions were invented to split up a hard disk into multiple pieces. There are several reasons why, e.g. to place different data on different partitions or to install multiple operating systems.

There are two partitioning technologies for PCs:

  • MBR (Master Boot Record): Was introduced in 1983 and is now a legacy system. A maximum of four primary partitions is supported. To have more partitions you need to make one of the four primary partitions an extended partition. Within an extended partition you can create logical partitions.
  • GPT (GUID Partition Table): The modern method that should be used when your motherboard has UEFI (the successor of the old BIOS). There is practically no limit to the amount of partitions. You need an EFI System Partition (ESP) to hold the boot loader.

Hard disks and SSD disks (connected via SATA) are available as /dev/sda, /dev/sdb, etc. in Linux. The partitions on the disks are /dev/sda1, etc. SSD disks connected via NVMe are available as /dev/nvme* and MMC/SD memory cards (e.g. the usual storage for a Raspberry Pi) are available as /dev/mmc*.

Getting an overview of existing drives and partitions:

lsblk                  # List found drives
sudo fdisk -l /dev/sda # List partitions on a particular drive

Besides the traditional device files modern Linux distributions also allow referencing drives/partitions by UUID (unique identifier for storage devices). They can be found in /dev/disk/by-uuid (which are symlinks to the standard /dev/* device). The benefit is having a stable reference that doesn't change if you shuffle drives around.

Changing partitions

Options to change partitions:

  • During the installation of a Linux distributions there is typically a tool available that can also resize/shrink existing partitions.
  • The low-level fdisk tool. It can create and delete partitions, but not resize them.
  • The graphical GParted tool, which can resize partitions.
  • Windows 10/11 can shrink an existing NTFS partition. Press ⊞ Windows+X, choose “disk management”, right click on the partition and choose “shrink volume”.

After creating a new partition, you will also need to create a file system (also called formatting) on that partition: mkfs.ext4 in case of Ext4.

Mounting

In Unix systems there are no drive letters like C: in Windows, but everything exists under root directory /. Anything containing files (like partitions, removable media or network drives) is “mounted” somewhere in the tree to make the files accessible. The location in the tree where it is attached is called the mount point.

Getting an overview of mounted drives and partitions:

mount  # list what is mounted
df -h  # show disk space

Example of how to mount a partition:

sudo mount /dev/sda1 /mnt/something

Usually mount can autodetect which file system is used, but it can be specified with argument -t. Unmounting is done with command umount. Use the mount point or device as argument.

You can mount an image of a partition, CD-ROM or DVD.

File /etc/fstab defines the default options when mounting and what to mount automatically when booting. Example line:

/dev/sda1  /  ext4  defaults  0  1

From left to right the columns mean:

  1. The device file, UUID or label
  2. The mount point (where it is attached in the directory hierarchy)
  3. File system type (e.g. Ext4 or NTFS)
  4. Options. Using “defaults” is the same as “auto,rw,nouser,exec,suid”. If listing multiple options they must be separated with commas and without spaces in between. Common options are “auto” for mounting when booting, “noauto” for not doing so, “user” to allow users to (un)mount the partition, “nouser” to not users to do so.
  5. Archiving schedule: 0=disabled, 1=enabled. Is often not actually used for anything.
  6. Order for disk checking. The root device should be 1, other partitions 2 or 0 (disables checking).

Swap space

Swap space is disk space that is used in case the physical memory is full. A disk is much slower than physical memory, so it's not ideal to need it for actively running software. Modern computers have a lot of memory, so you hopefully never run out of physical memory. To use hibernation on a laptop a swap disk is needed (to save the memory contents to).

The installation of most distributions creates a swap partition between 1 and 2 times the size of your physical memory. If you never run out of physical memory you could live without any swap space.

Previous Next

ALL THE TOPICS ON THIS WEBSITE:

Linux

Raspberry Pi

Digital room correction

Web design

By Jarkko Huijts
Jarkko's guides

Table of Contents

Table of Contents

  • Partitions & mounting
    • File systems
    • Partitions
    • Changing partitions
    • Mounting
    • Swap space

LINUX

  • Intro
  • History
  • Open source
  • Distributions
  • Command line
  • Tool help
  • Remote access
  • Directory hierarchy
  • Basic commands
  • Viewing & editing files
  • Processes
  • GNU & other utilities
  • Users & permissions
  • Partitions & mounting
  • System administration
  • Software packages
  • Desktop environments
  • Scripting
  • Audio

AVAILABLE TOPICS

  • Linux
  • Raspberry Pi
  • Digital room correction
  • Web design