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,xfsorntfsbefore 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/fstabfile 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:
- 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).
- The device name (such as
- Mount Point: such as
/mntor/media. - File System: such as
xfsorext4. - Mount Options: such as
defaults,ro(read-only),noexec(prevents execution). - Backup (Dump):
0means no backup. - Disk check (Fsck Order):
0means no check,1for the highest priority (such as/),2for other partitions.
- Device: you can use:
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/fstabto avoid problems if the device name changes. -
Example of getting the UUID:
blkid /dev/nvme0n1p1 -
Avoid writing
/etc/fstabby 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 themountcommand. - Using a UUID or Label is safer than using device names.