Mastering Linux: How to Mount and Unmount Drives Like a Pro.

Mastering Linux: How to Mount and Unmount Drives Like a Pro.
Mounting USB drives on linux

Mounting and unmounting drives are essential skills for managing storage devices on Linux. Whether you're handling USB drives, external hard disks, or disk images, understanding these processes ensures your drives are ready for use. This guide will walk you through the steps, making it easy to work with Linux systems , confidently.

How to Mount Drives in Linux

Mounting a drive in Linux involves 3 easy steps:

  • identifying the drive you want to mount,
  • creating a mount point,
  • and using commands or tools to attach the drive to the system.

Here's how to get started:

Creating a Mount Point

Bonus TIP: Choosing the correct mount directory

In Linux, you have two primary directories commonly used for mounting drives: /media and /mnt. While both serve as mount points for external devices or additional storage, they differ in purpose, usage, and suitability for specific tasks. Here's an explanation of each, their benefits, and when to use them.

1. /media – Designed for Removable Drives

The /media directory is part of the Filesystem Hierarchy Standard (FHS) and is intended for removable media, such as USB drives, external hard disks, DVDs, and SD cards.

Benefits of Using /media:

  • Automatic Mounting: Modern Linux desktop environments (like GNOME, KDE) automatically mount removable drives to /media/<device-name>.
  • User-Friendly Integration: Drives mounted in /media are easily accessible through graphical file managers, making it ideal for casual users.
  • Best for Temporary Mounting: Drives that are frequently connected and disconnected, such as USB sticks, fit naturally in this directory.

When to Use /media:

Use /media if you:

  • Plan to use the drive temporarily or as a removable device.
  • Want the system or graphical interface to handle drive mounting automatically.

2. /mnt – Ideal for Manual or Static Mounts

The /mnt directory is also defined by the FHS but is intended for manually mounted filesystems. It’s a generic mount point for drives not automatically handled by the system, such as network drives, additional internal disks, or external drives as mostly static, i.e. once you mount them, they stay on the server you are mounting them on.

Benefits of Using /mnt:

  • Custom Usage: Great for system administrators who want to organize manually mounted devices or configure specialized mounts.
  • Isolation: Filesystems mounted here are less likely to be affected by automated system tools or scripts, ensuring stable and predictable behaviour.
  • Best for Persistent Mounting: Drives used regularly in the exact location, such as backup drives or secondary storage, are well-suited for /mnt.

When to Use /mnt:

Use /mnt if you:

  • Are mounting a drive permanently or for administrative purposes.
  • Need a stable, predictable location not influenced by desktop environments or auto-mounting tools.

Which Should You Choose?

The choice between /media and /mnt depends on how the drive will be used:

  • For removable drives (USBs, SD cards): Mount them in /media for ease of use and automatic integration with graphical interfaces.
  • For static or system-critical drives, Mount them in /mnt to ensure stability and avoid interference from auto-mounting tools.

By understanding the distinction, you can make informed decisions about where to mount drives, ensuring your setup is both functional and efficient.

A mount point is a directory where your drive's contents will be accessible. To create one:

Open the terminal and enter the following command to create a directory:

sudo mkdir /media/pendrive

Mounting and Unmounting the Drive

Mounting the Drive

Finding the Drive to Mount

The first step in mounting a drive in Linux is to identify the correct device. Follow these clear instructions to find the drive you want to mount:

Step 1: Plug in the Drive

Ensure the USB drive, external hard disk, or other device is physically connected to your system.

Step 2: List Attached Drives

Use the lsblk command to display all connected storage devices:

lsblk

Example Output:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk 
├─sda1        8:1    0   500M  0 part /boot
├─sda2        8:2    0   931G  0 part /
sdb           8:16   1  28.9G  0 disk 
└─sdb1        8:17   1  28.9G  0 part
  • The NAME column shows device names (sda, sdb, etc.).
  • TYPE indicates whether the entry is a disk (entire device) or part (partition).
  • MOUNTPOINT shows where the device is mounted, if applicable. Unmounted drives will have no entry here.

Step 3: Match the Drive Size

Identify your target drive by its size in the SIZE column. For example, if your USB drive is 28.9 GB, it’s likely. sdb.
If you are unsure, still remove the drive and reenter the above command; if one of the drives is missing, that's your USB drive.

Step 4: Display Filesystem Information

To confirm the partition type (e.g., NTFS, ext4), used with the following command:

lsblk -f

Example Output:

NAME   FSTYPE FSVER LABEL       UUID                                 MOUNTPOINT
sda                                                                  
├─sda1 vfat   FAT32             DC22-63C3                           /boot
├─sda2 ext4   1.0               b28e9977-f9b7-4b35-91db-fa799f17f4f4 /
sdb                                                                  
└─sdb1 ntfs                     226AFB1D6AFAED03                    

Look for:

  • FSTYPE to verify the file system (e.g., NTFS, ext4).
  • LABEL or UUID to identify the drive if multiple devices have similar sizes. You will also use this UUID to mount the drive on your server permanently, so note this.

Step 5: Use the fdisk Command (Optional)

For more detailed information about connected drives:

sudo fdisk -l

Example Output:

Disk /dev/sdb: 28.9 GiB, 31018229760 bytes, 60554240 sectors
Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        2048 60554239 60552192 28.9G  7 HPFS/NTFS/exFAT

Here, /dev/sdb1 is the partition you want to mount.

Step 5: Mount the drive

Now, you can temporarilymount mout the drive to your directory with the following command,

sudo mount /dev/sda1 /media/pen-drive

you can then use the ls command to see what files are on the drive

ls -la /media/pen-drive


Trouble shooting: Format the Disk

If you have not already done so, the drive must be formatted for Linux compatibility, especially if it’s preformatted for Windows (e.g., NTFS). Here’s how:

  1. Use tools like fdisk, parted, or GUI tools like GParted.
  2. To reformat via the terminal:
    • Identify the drive using lsblk.
  3. After formatting, remount the drive to access it.

Format the drive to ext4 for Linux:

sudo mkfs.ext4 /dev/sdb1

⚠️ IMPORTANT: Make Sure You Are Formatting the Correct Drive

Formatting a drive will erase all data on the selected device permanently. Before proceeding:

  • Double-Check the Device Name: Use the lsblk or fdisk -l commands to identify the correct drive. Pay close attention to the device name (e.g., /dev/sdb1) and the size or label of the drive.
  • Verify the UUID or Label: Confirm the drive’s unique identifier using:lsblk -f
  • Unplug Unnecessary Drives: To avoid confusion, disconnect any external drives or devices not involved in the process.

If you accidentally format the wrong drive, recovering the data may be difficult or impossible. Proceed with extreme caution!

When in Doubt: Stop and double-check the drive details before running any formatting commands. It's better to be safe than sorry!



Permanent USB Mount in Linux

To ensure your drive mounts automatically after reboot, edit the /etc/fstab file.

First, copy the fstab file before making any changes; this is good practice as if you make a mistake, you can revert back to the original easily

sudo cp /etc/fstab ~/

this will copy the file to your home directory.

Identify the drive's UUID if you have not done so from above:

lsblk -f

Example UUID: 11bcd17d-06b0-4345-8b5f-cc0fcbf88f41.

With this, you can add the following line at the end of your fstab file like in the example below

#USB DRIVE MOUNT
UUID=11bcd17d-06b0-4345-8b5f-cc0fcbf88f41 /media/pendrive ext4 defaults 0 0

Your drive will now mount automatically at the specified location whenever the system boots.


FAQs on Mounting Drives on a Linux System

Why won’t my USB drive auto-mount?

Auto-mounting may fail if the system lacks the necessary configurations or drivers. Use the mount command to manually mount the drive.

How do I check which drives are connected to my Linux system?

Use the lsblk or fdisk -l command to list all connected drives and their details.

What’s the best filesystem for a USB drive in Linux?

For Linux-only use, ext4 is the most compatible. For cross-platform use, consider vfat or NTFS.

Can I mount an ISO image as a drive?

Yes. Use the following command:

sudo mount -o loop path/to/image.iso /media/iso
What’s the difference between mounting and formatting a drive?

Mounting makes a drive's contents accessible to the system, while formatting prepares a drive with a new filesystem, erasing all its contents.


FAQs About jimgogarty.com

FAQs About jimgogarty.comWhat kind of content does jimgogarty.com provide?

Jim Gogarty’s blog focuses on IT support, cybersecurity, and Linux tips. It includes tutorials, technical guides, and insights into backup systems and infrastructure.

Does Jim Gogarty offer services beyond blogging?

Jim Gogarty specialises in IT support and cybersecurity with over 10 years of experience. For consulting inquiries, visit the contact page.

Can I subscribe to updates on jimgogarty.com?

Yes! Visit the homepage to subscribe and receive the latest blog posts and updates directly to your inbox.

Does the blog cover topics for beginners and experts?

Absolutely! The content is tailored for all levels, offering both beginner-friendly guides and advanced technical deep-dives.


Following this guide, you can easily mount and unmount drives in Linux, making storage management a breeze. Explore more IT tutorials and tips on jimgogarty.com.