Mounting and Unmounting Storage

In Linux, storage is not automatically accessible when connected — it must be mounted at a directory in the file system tree. Understanding mount and umount is essential for managing disks, partitions, USB drives, NFS shares, and temporary file systems on Ubuntu servers.

How Linux mounting works

Physical layer:          /dev/sdb1  (block device)
                              |
                              | mount -t ext4 /dev/sdb1 /data
                              |
File system tree:    /         (root)
                     ├── /home
                     ├── /var
                     └── /data  ← /dev/sdb1 is now accessible here

The mount command

# Mount a partition to a directory
sudo mount /dev/sdb1 /data

# Mount with explicit file system type
sudo mount -t ext4 /dev/sdb1 /data
sudo mount -t xfs /dev/sdc1 /logs

# Mount with options
sudo mount -o ro /dev/sdb1 /data              # Read-only
sudo mount -o noexec,nosuid /dev/sdb2 /tmp   # Security: no exec, no suid

# Mount an ISO file (loop device)
sudo mount -o loop ubuntu-24.04.iso /mnt/iso

# Mount by UUID (more reliable than device names which can change)
sudo mount UUID=123e4567-e89b-12d3-a456-426614174000 /data

# Mount by label
sudo mount LABEL=mydata /data

# See all currently mounted file systems
mount | column -t
# or
findmnt

findmnt output

TARGET        SOURCE    FSTYPE  OPTIONS
/             /dev/sda1 ext4    rw,relatime
├─/dev/shm    tmpfs     tmpfs   rw,nosuid,nodev
├─/home       /dev/sda2 ext4    rw,relatime
└─/data       /dev/sdb1 ext4    rw,relatime

The umount command

# Unmount by mount point
sudo umount /data

# Unmount by device
sudo umount /dev/sdb1

# Lazy unmount (detaches immediately, waits for current users to finish)
sudo umount -l /data

# Force unmount (dangerous — may cause data loss)
sudo umount -f /data    # Use only for network mounts that are unresponsive

# Find what is using a mount point (preventing unmount)
lsof /data
fuser -mv /data

# Kill processes using the mount point, then unmount
sudo fuser -km /data
sudo umount /data

⚠️ WARNING: Never force-unmount (umount -f) a local file system that has active writes in progress. This can corrupt the file system. First find what is using the mount with lsof /mountpoint, stop those processes gracefully, then unmount normally.

Persistent mounts with fstab

# Get the UUID of a device (use UUID, not /dev/sdX, which can change)
blkid /dev/sdb1

# Add to /etc/fstab
sudo nano /etc/fstab

/etc/fstab entry for a data partition

# Format: device  mountpoint  fstype  options  dump  pass
UUID=abc12345...  /data  ext4  defaults,noatime  0  2

# Options explained:
# defaults   = rw, suid, dev, exec, auto, nouser, async
# noatime    = don't update access time on reads (performance)
# dump       = 0 (don't backup with dump command)
# pass       = 2 (fsck order: 1=root only, 2=other, 0=never)
# Test your fstab entry without rebooting
sudo mount -a    # Mounts all entries in fstab that aren't mounted

# Verify it mounted correctly
df -h /data
mount | grep /data

Mounting network shares

# Mount an NFS share
sudo apt install -y nfs-common
sudo mount -t nfs 192.168.1.10:/exports/data /data

# NFS in fstab
# 192.168.1.10:/exports/data  /data  nfs  defaults,_netdev  0  0

# Mount a CIFS/Samba share
sudo apt install -y cifs-utils
sudo mount -t cifs //192.168.1.10/share /data -o username=irfan,password=secret

# Credentials file (more secure than inline passwords)
echo "username=irfan" | sudo tee /etc/samba-creds
echo "password=secret" | sudo tee -a /etc/samba-creds
sudo chmod 600 /etc/samba-creds
# In fstab: //server/share  /data  cifs  credentials=/etc/samba-creds,_netdev  0  0

Troubleshooting mount problems

# "mount: wrong fs type, bad option, bad superblock"
# Check the device and file system type
sudo file -s /dev/sdb1
sudo blkid /dev/sdb1

# "device is busy" when unmounting
lsof /data    # See what has files open on the mount

# "special device does not exist"
lsblk         # Check if the device is actually present
dmesg | tail  # Check for disk errors

# fstab typo causing boot failure
# Boot into recovery mode → root shell → fix /etc/fstab → remount root rw:
# mount -o remount,rw /
# nano /etc/fstab

Conclusion

Use UUIDs (not device names like /dev/sdb1) in /etc/fstab because device names can change between reboots when adding or removing drives. Always test fstab entries with sudo mount -a before rebooting. Use lsof /mountpoint to find what is preventing unmounting. Add noatime to fstab options for data volumes to reduce unnecessary writes, especially on SSDs.

FAQ

Is Mounting and Unmounting Storage important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support