π 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
| Option | Description | 
|---|---|
| -t | Filesystem type (ext4, vfat, ntfs, etc.) | 
| -o | Comma-separated mount options | 
| loop | Treat file as block device (e.g., ISO) | 
| rw/ro | Read-write or read-only mode | 
| noexec | Prevent execution of binaries | 
| nosuid | Ignore setuid bits | 
| defaults | Use default mount options | 
βοΈ Command Comparison
| Command | Action | Target | Permissions Required | 
|---|---|---|---|
| mount | Attach filesystem | Device β Dir | Yes (sudo) | 
| umount | Detach filesystem | Device or Dir | Yes (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 mountto attach devices or images to directories
- Use umountto safely detach them
- Combine with /etc/fstabfor 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 :
