πŸ’Ύ Linux/Unix: Storage, Archiving & Compression
Estimated reading: 3 minutes 24 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

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

Or Copy Link

CONTENTS
Scroll to Top