πŸ’Ύ Linux/Unix: Storage, Archiving & Compression
Estimated reading: 3 minutes 279 views

Linux/Unix: Mounting Drives – mount, umount Commands Explained with Examples

Introduction – Why Learn Mounting in Linux?

In Linux/Unix systems, everything is a file, including storage devices. To access files on USBs, CDs, partitions, or remote file systems, you need to mount them. The mount and umount commands are crucial for attaching and detaching filesystems, whether manually or via scripts.

In this guide, you’ll learn:

  • How mounting works in Linux
  • How to mount and unmount filesystems
  • Options for temporary, persistent, and safe mounting
  • Real-world examples and error handling

1. What Is Mounting?

Mounting is the process of associating a filesystem (like a USB drive or partition) with a directory in your Linux system (called a mount point) so its contents can be accessed.

Example:

A USB drive /dev/sdb1 might be mounted at /mnt/usb so you can browse files in that directory.


2. mount – Attach a Filesystem

What is mount?

The mount command attaches a storage device or partition to a specific location in the filesystem hierarchy.

Syntax:

sudo mount [OPTIONS] device mount_point

Example 1: Mount a USB drive

sudo mount /dev/sdb1 /mnt/usb

Output: (No output if successful)
Now, /mnt/usb will contain the contents of /dev/sdb1.


Example 2: View mounted filesystems

mount | grep "^/dev"

Output:

/dev/sda1 on / type ext4 (rw,relatime)
/dev/sdb1 on /mnt/usb type vfat (rw,nosuid,nodev)

Example 3: Mount with specific filesystem type

sudo mount -t ext4 /dev/sdb1 /mnt/usb

Example 4: Mount ISO image

sudo mount -o loop disk.iso /mnt/iso

-o loop treats the ISO file as a block device.


3. umount – Detach a Filesystem

What is umount?

The umount command safely disconnects a mounted filesystem from the directory hierarchy.

Syntax:

sudo umount [device|mount_point]

Example 1: Unmount using mount point

sudo umount /mnt/usb

Example 2: Unmount using device name

sudo umount /dev/sdb1

If the device is busy, you’ll get:

umount: /mnt/usb: target is busy.

Use lsof or fuser to find processes:

lsof /mnt/usb
fuser -vm /mnt/usb

4. Persistent Mounts via /etc/fstab

To auto-mount devices on boot, add an entry in the /etc/fstab file.

Example Entry:

UUID=1234-5678  /mnt/usb  vfat  defaults,noauto,user  0  0

Get UUID using:

blkid

Mounting Options Summary

OptionDescription
-tFilesystem type (ext4, vfat, ntfs, etc.)
-oComma-separated mount options
loopTreat file as block device (e.g., ISO)
rw/roRead-write or read-only mode
noexecPrevent execution of binaries
nosuidIgnore setuid bits
defaultsUse default mount options

Command Comparison

CommandActionTargetPermissions Required
mountAttach filesystemDevice β†’ DirYes (sudo)
umountDetach filesystemDevice or DirYes (sudo)

Summary – Recap & Next Steps

Mounting and unmounting are fundamental for managing removable media, external drives, and network filesystems. Whether you’re scripting a backup or exploring a new USB, mount and umount are go-to commands.

Key Takeaways:

  • Use mount to attach devices or images to directories
  • Use umount to safely detach them
  • Combine with /etc/fstab for persistent configurations

FAQs

What happens if I remove a USB without unmounting?
Data may be corrupted or lost. Always unmount first.

How do I check what’s mounted?
Use:

mount | column -t

How do I mount an NTFS drive?
Install ntfs-3g and run:

sudo mount -t ntfs-3g /dev/sdX1 /mnt/ntfs

How do I fix “target is busy” error?
Use:

lsof /mnt/usb
fuser -vm /mnt/usb

Can I mount without sudo?
Only if the /etc/fstab entry allows user or users option.


Share Now :
Share

πŸ”΅ Linux/Unix: Mounting (mount, umount)

Or Copy Link

CONTENTS
Scroll to Top