Mounting

Complete Guide to File Mounting in Linux

Mounting is the process of making a storage device or filesystem accessible at a specific location in the directory tree. Below is a comprehensive guide covering all aspects of mounting in Linux.


1. Basics of Mounting in Linux

In Linux, filesystems and storage devices must be mounted before use. The mount command is used for this purpose.

Checking Mounted Filesystems

mount

or

df -h

This displays all currently mounted filesystems.

Check all filesystem

lsblk

here nvme0n1 - mounted to root path

You can see that our EBS disk (nvme1n1) is there, but it hasn't been mounted yet. Let's fix that.

First, we'll create a ext4 filesystem on the device, and mount it at /var/lib/clickhouse which is where all the ClickHouse data will be stored

Next, we'll register the volume in /etc/fstab so the volume is automatically mounted after instance restarts.


2. Mounting a Filesystem Manually

Syntax

Example: Mounting an Ext4 Partition

  • /dev/sdb1: The device (can be found using lsblk or fdisk -l).

  • /mnt: The directory where it will be mounted.

Mounting an NTFS Partition

Mounting a USB Drive


Feature

mkfs

mount

What it does

Creates a file system (formats)

Attaches file system to path

Destructive?

Yes – wipes existing data

No – non-destructive

When used?

Before first-time use of disk

Every time you want to use disk

Example use

mkfs.ext4 /dev/sdb1

mount /dev/sdb1 /mnt/data

3. Making Mounts Persistent (Auto-mount on Reboot)

To keep a device mounted after reboot, you need to add an entry to /etc/fstab.

Steps:

  1. Get the UUID of the device:

  2. Edit the fstab file:

  3. Add an entry in the format:

  4. Apply changes:


4. Unmounting a Filesystem

If the filesystem is busy, force unmount:


5. Bind Mounts (Mounting a Directory to Another Location)

To make it persistent:

in /etc/fstab.


6. Mounting Network Drives (NFS & CIFS)

NFS Share

CIFS (Windows Shared Folder)


7. Mounting ISO Files

To unmount:


8. Mounting TMPFS (In-Memory Filesystem)

To make it persistent:

in /etc/fstab.


9. Mounting External Drives Automatically (Udev Rules)

For auto-mounting USB devices, use udev rules or systemd.

  1. Create a rule:

  2. Add:


10. Checking Mount Points & Filesystem Details

  • List all partitions:

  • Check mounted filesystems:

  • View /etc/mtab (active mounts):


Final Thoughts

This guide covers everything from basic mounting to persistent and network mounting. If you need automation, fstab is your best choice, and for temporary mounts, mount works well. 🚀

Last updated