Mostafa Elhavary

Understanding Mounting in Linux

A detailed explanation of disk partitioning and mounting in Linux systems, with a short comparison to Windows.


1. What is a partition?

  • A partition is a reserved section of a hard disk with a defined start and end (expressed in sectors).
  • A partition table is created to record the start and end of each partition.
  • Without a partition table, the system will not know how to reach the data, even if it physically exists on the disk.

2. Formatting a partition

  • After a partition is created, it must be formatted with a file system such as ext4, xfs or ntfs before it is ready to store data.

  • Example:

    mkfs.xfs /dev/nvme0n1p1  # format the partition with the XFS file system

3. Mounting

  • Mounting is the process of attaching a partition to a directory in the Linux file system tree so it can be used.
  • Types of mount:
    • Temporary mount: disappears after a reboot.

      mount /dev/nvme0n1p1 /mnt
    • Permanent mount: recorded in the /etc/fstab file so it survives a reboot.

      /dev/nvme0n1p1  /mnt  xfs  defaults  0 0

4. The file /etc/fstab

  • This is the file responsible for permanent mounts. It has 6 columns:
    1. Device: you can use:
      • The device name (such as /dev/nvme0n1p1).
      • The UUID (better, because it does not change).
      • The Label (a name defined by the user).
    2. Mount Point: such as /mnt or /media.
    3. File System: such as xfs or ext4.
    4. Mount Options: such as defaults, ro (read-only), noexec (prevents execution).
    5. Backup (Dump): 0 means no backup.
    6. Disk check (Fsck Order): 0 means no check, 1 for the highest priority (such as /), 2 for other partitions.

5. Useful commands

  • List partitions:

    lsblk
  • Show current mounts:

    mount
  • Unmount:

    umount /mnt
  • Remount a partition with new options:

    mount -o remount,ro /dev/nvme0n1p1 /mnt

6. Temporary vs permanent mounts

Feature Temporary mount Permanent mount
Survives a reboot ❌ No ✔️ Yes
How it is done A direct mount command Added to /etc/fstab
Handled by The user (manually) systemd (automatically)

7. Important tips

  • Use the UUID instead of the device name in /etc/fstab to avoid problems if the device name changes.

  • Example of getting the UUID:

    blkid /dev/nvme0n1p1
  • Avoid writing /etc/fstab by hand if you are not sure:
    You can copy the line from /etc/mtab (which records the current mounts) and paste it into /etc/fstab.


8. Common errors

  • If you see the message “read-only file system”, the partition may be mounted read-only.
    Solution: remount it with write permissions:

    mount -o remount,rw /dev/nvme0n1p1 /mnt

Summary

  • A partition is a division of the disk, and mounting attaches it to the system.
  • Permanent mounts are done through /etc/fstab, temporary ones with the mount command.
  • Using a UUID or Label is safer than using device names.

All posts

Sign in to save your progress

Sign in with your Google account. Your course progress is saved to your account and follows you to any device.