In Linux, mounting is the process of making a filesystem available somewhere inside the main directory tree.
This can feel unusual if you come from Windows. In Windows, storage devices usually appear as separate drive letters, such as:
C:\
D:\
E:\
Linux works differently. Linux has one main directory tree that starts at:
/
Storage devices, partitions, USB drives, ISO files, and network shares are attached somewhere inside that tree.
For example, a USB drive might be mounted at:
/mnt/external
or:
/media/user/USB_DRIVE
Once mounted, the device looks like an ordinary directory. You can use commands such as cd, ls, cp, mv, and rm to work with its files.
Many different things can be mounted in Linux.
Common examples include:
- hard disk partitions
- SSD partitions
- USB flash drives
- external hard drives
- CD/DVD/ISO images
- network shares
- special system filesystems
Network filesystems can also be mounted, such as:
NFS common on Unix/Linux networks
SMB/CIFS common for Windows file shares
Linux also mounts special pseudo-filesystems that do not represent normal storage devices. These include:
/proc
/sys
/dev
/run
These provide information about processes, hardware, devices, and runtime system state.
Some filesystems are required for the system to work.
For example:
/ root filesystem
/proc process and kernel information
/sys hardware and kernel information
/dev device files
These are usually mounted automatically during boot.
Other filesystems are optional. These include USB drives, extra partitions, external disks, ISO images, and network shares.
Optional filesystems may be mounted manually by the user or automatically by the desktop environment.
On desktop distributions such as Ubuntu, Fedora, or Linux Mint, removable devices are often mounted automatically.
For example, when you plug in a USB drive, the file manager may automatically mount it under something like:
/media/username/USB_NAME
This is convenient for normal desktop use.
Manual mounting is still useful when:
- a device is not auto-mounted
- you are working on a server
- you are troubleshooting
- you want a custom mount point
- you are mounting an ISO file
- you are mounting a network share
- you need specific mount options
Mounting attaches a filesystem to a directory.
That directory is called a mount point.
Before mounting, the directory is just an ordinary directory. After mounting, the contents of the mounted filesystem appear there.
Linux Directory Tree Before Mounting:
/
├── bin
├── etc
├── home
│ └── user
├── mnt
├── usr
└── var
Now suppose a USB drive partition is available as:
/dev/sdb1
and we mount it at:
/mnt/external
After mounting, the tree may look like this:
Linux Directory Tree After Mounting /dev/sdb1 at /mnt/external:
/
├── bin
├── etc
├── home
│ └── user
├── mnt
│ └── external <-- Mounted device /dev/sdb1
│ ├── documents
│ ├── photos
│ └── videos
├── usr
└── var
The files are physically stored on /dev/sdb1, but they are accessed through /mnt/external.
A simple way to remember this is:
Device or filesystem + mount point = accessible files
Mounting does not copy files into the mount point.
It simply makes the filesystem visible at that location.
For example:
sudo mount /dev/sdb1 /mnt/externaldoes not copy the USB drive into /mnt/external.
It attaches the filesystem on /dev/sdb1 so that its contents can be accessed through /mnt/external.
A mount point is a directory where a filesystem is attached.
Common mount point locations include:
/mnt traditional temporary mount location
/media common location for removable media
/backup custom mount point for backup drives
/data custom mount point for data disks
For example:
/mnt/external
/mnt/iso
/media/usb
/data
/backup
A mount point should usually be empty before mounting.
If the directory already contains files, those files are not deleted, but they become hidden while another filesystem is mounted on top of that directory.
Example:
Before mounting:
/mnt/external contains oldfile.txt
After mounting /dev/sdb1 at /mnt/external:
/mnt/external shows the USB drive contents
After unmounting:
/mnt/external shows oldfile.txt again
This can confuse beginners, so it is best to use an empty directory as the mount point.
Linux represents storage devices using files under:
/dev
Examples:
/dev/sda first disk
/dev/sda1 first partition on first disk
/dev/sdb second disk
/dev/sdb1 first partition on second disk
/dev/nvme0n1 NVMe disk
/dev/nvme0n1p1 first partition on NVMe disk
A USB drive might appear as:
/dev/sdb
and its first partition might appear as:
/dev/sdb1
However, device names can change after rebooting or reconnecting hardware. For persistent configuration, it is usually better to use a UUID instead of a device name.
Before mounting a device, first check whether Linux can see it.
Useful commands include:
lsblksudo fdisk -lblkidThe lsblk command is often the easiest for beginners.
Example:
lsblkExample output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 256.0G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 255.5G 0 part /
sdb 8:16 1 32.0G 0 disk
└─sdb1 8:17 1 32.0G 0 part
This shows that /dev/sdb1 exists but is not currently mounted.
The fdisk -l command gives more detailed partition information:
sudo fdisk -lExample output:
Disk /dev/sdb: 32 GB
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 62521343 62519296 29.8G 83 Linux
This means:
/dev/sdb is the disk
/dev/sdb1 is a partition on that disk
29.8G is the partition size
Linux is the partition type
The partition is usually what you mount, not the whole disk.
So you usually mount:
/dev/sdb1
not:
/dev/sdb
The mount command attaches a filesystem to a mount point.
Basic syntax:
mount [OPTIONS] DEVICE MOUNT_POINTExample:
sudo mount /dev/sdb1 /mnt/externalThis means:
Mount the filesystem on /dev/sdb1 at /mnt/external.
The general workflow is:
Find the device
|
v
Create a mount point
|
v
Mount the device
|
v
Access files through the mount point
Suppose a USB drive partition is available as:
/dev/sdb1
and you want to access it at:
/mnt/external
First, create the mount point:
sudo mkdir -p /mnt/externalThen mount the device:
sudo mount /dev/sdb1 /mnt/externalNow list the files:
ls /mnt/externalYou can also move into the mounted filesystem:
cd /mnt/externalTo see mounted filesystems, you can run:
mountHowever, the output can be long.
A cleaner command is:
findmntTo check one mount point:
findmnt /mnt/externalExample output:
TARGET SOURCE FSTYPE OPTIONS
/mnt/external /dev/sdb1 ext4 rw,relatime
This means:
| Description | |
|---|---|
| TARGET | Where it is mounted |
| SOURCE | Device being mounted |
| FSTYPE | Filesystem type |
| OPTIONS | Mount options |
You can also use:
df -hThis shows mounted filesystems and available space in a human-readable format.
A mount entry might look like this:
/dev/sdb1 on /mnt/external type ext4 (rw,relatime)
Breaking it down:
/dev/sdb1 device
/mnt/external mount point
ext4 filesystem type
rw read-write
relatime access-time update behavior
The rw option means the filesystem is mounted read-write.
A read-only mount would show:
ro
A filesystem type describes how data is organized on the device.
Common filesystem types include:
| Filesystem | Description |
|---|---|
| ext4 | Common Linux filesystem |
| xfs | Common on servers |
| btrfs | Modern Linux filesystem with advanced features |
| vfat | FAT32, common for USB drives |
| exfat | Common for large USB drives and SD cards |
| ntfs | Common Windows filesystem |
| iso9660 | CD/DVD ISO filesystem |
| nfs | Network File System |
| cifs | Windows/Samba network share |
Usually Linux can detect the filesystem automatically.
If needed, you can specify it manually with -t.
Example:
sudo mount -t ext4 /dev/sdb1 /mnt/externalFor an NTFS drive:
sudo mount -t ntfs3 /dev/sdb1 /mnt/externalOn some systems, especially older ones, NTFS support may use ntfs-3g:
sudo mount -t ntfs-3g /dev/sdb1 /mnt/externalIf you get an error about an unknown filesystem type, you may need to install support for that filesystem.
Mount options control how the filesystem is mounted.
Options are passed with -o.
Example:
sudo mount -o ro /dev/sdb1 /mnt/externalThis mounts the filesystem as read-only.
Common options include:
| Option | Description |
|---|---|
| ro | Read-only |
| rw | Read-write |
| noexec | Do not allow execution of programs from the filesystem |
| nosuid | Ignore set-user-ID and set-group-ID bits |
| nodev | Do not interpret device files |
| uid=1000 | Set file owner for filesystems without Unix ownership |
| gid=1000 | Set group owner |
| defaults | Use default options |
Examples:
sudo mount -o ro /dev/sdb1 /mnt/externalsudo mount -o noexec,nosuid,nodev /dev/sdb1 /mnt/externalRead-only mounting is useful when you want to inspect a disk without accidentally changing it.
Unmounting detaches a mounted filesystem from the directory tree.
The command is:
umountNotice the spelling:
umount
not:
unmount
To unmount a filesystem, use either the mount point or the device.
Example using the mount point:
sudo umount /mnt/externalExample using the device:
sudo umount /dev/sdb1After unmounting, the files from the device are no longer visible at the mount point.
You should unmount removable storage before physically removing it.
Linux often caches writes. This means that when you copy a file to a USB drive, the command may finish before all data has actually been written to the physical device.
Unmounting makes sure pending writes are completed.
The safe workflow is:
Copy files
|
v
Unmount the device
|
v
Wait for command to finish
|
v
Physically remove the device
If you unplug a device without unmounting it, you may cause:
- corrupted files
- incomplete writes
- damaged filesystem metadata
- lost data
The sync command asks Linux to flush cached writes to storage.
syncThis can be useful before unmounting removable media.
However, sync is not a replacement for umount.
A safer sequence is:
sync
sudo umount /mnt/externalSometimes unmounting fails with an error like:
umount: /mnt/external: target is busy
This means something is still using the mounted filesystem.
Common causes include:
- a terminal is currently inside the mount point
- a file is open in an editor
- a program is reading or writing files there
- a shell process has that directory as its current working directory
For example, if your terminal is currently in:
/mnt/external
then unmounting may fail.
Move out of the directory:
cd ~Then try again:
sudo umount /mnt/externalTo see which processes are using a mount point, use lsof:
sudo lsof +f -- /mnt/externalExample output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 1234 user cwd DIR 8,17 4096 2 /mnt/external
This means a Bash process with PID 1234 has its current working directory inside /mnt/external.
The most important fields are:
| Field | Description |
|---|---|
| COMMAND | Process name |
| PID | Process ID |
| USER | User running the process |
| FD | File descriptor |
| NAME | File or directory being used |
Another useful command is:
sudo fuser -vm /mnt/externalTo close the issue, first try to close the application or move the terminal out of the directory.
If needed, terminate the process:
sudo kill 1234Use kill carefully. Terminating a process that is writing data may cause data loss.
The umount command has advanced options.
Lazy unmount:
sudo umount -l /mnt/externalThe -l option detaches the filesystem now and cleans it up after it is no longer busy.
Forced unmount:
sudo umount -f /mnt/externalThe -f option forces the unmount.
Forced unmounts should be used carefully, especially for local disks, because they can risk data corruption.
A good rule is:
- Normal unmount first.
- Find and close processes if busy.
- Use lazy or forced unmount only when you understand the risk.
Sometimes Linux does not automatically detect the filesystem type, or you want to be explicit.
Example for ext4:
sudo mount -t ext4 /dev/sdb1 /mnt/externalExample for NTFS:
sudo mount -t ntfs3 /dev/sdb1 /mnt/externalExample for FAT32:
sudo mount -t vfat /dev/sdb1 /mnt/externalExample for exFAT:
sudo mount -t exfat /dev/sdb1 /mnt/externalIf mounting fails, check the filesystem type with:
lsblk -for:
sudo blkid /dev/sdb1Example:
/dev/sdb1: UUID="ABCD-1234" TYPE="exfat" LABEL="MYUSB"
An ISO image is a file that contains the contents of a CD, DVD, or installation image.
For example:
ubuntu.iso
You can mount an ISO file without burning it to a disc.
First create a mount point:
sudo mkdir -p /mnt/isoThen mount the ISO:
sudo mount -o loop ubuntu.iso /mnt/isoThe loop option lets Linux treat a regular file as if it were a block device.
After mounting, view the files:
ls /mnt/isoWhen finished, unmount it:
sudo umount /mnt/isoThe workflow looks like this:
ubuntu.iso file
|
v
loop device
|
v
mounted at /mnt/iso
|
v
contents become accessible
Network shares can also be mounted.
Two common types are:
NFS common between Linux/Unix systems
CIFS used for Windows/Samba shares
Example NFS mount:
sudo mount -t nfs server:/export/data /mnt/dataExample CIFS mount:
sudo mount -t cifs //server/share /mnt/share -o username=myuserNetwork mounts are common for shared storage, home directories, backups, and file servers.
For persistent network mounts, /etc/fstab or systemd mount units are often used.
Manual mounts disappear after reboot.
To mount a filesystem automatically at boot, configure it in:
/etc/fstab
The file contains one filesystem per line.
Example:
/dev/sdb1 /mnt/external ext4 defaults 0 2
The fields are:
| Field | Value |
|---|---|
| Device | /dev/sdb1 |
| Mount point | /mnt/external |
| Filesystem | ext4 |
| Options | defaults |
| Dump | 0 |
| fsck pass | 2 |
The last two fields are older but still important:
0 do not use dump backup
2 check this filesystem after the root filesystem
The root filesystem usually has pass value 1.
Other local Linux filesystems often use 2.
Filesystems that should not be checked at boot often use 0.
Device names such as /dev/sdb1 can change.
For example, today a USB drive may be:
/dev/sdb1
but after reboot it may become:
/dev/sdc1
To avoid this problem, use a UUID.
Find the UUID:
sudo blkid /dev/sdb1Example:
/dev/sdb1: UUID="1234-ABCD" TYPE="ext4"
Then use the UUID in /etc/fstab:
UUID=1234-ABCD /mnt/external ext4 defaults 0 2
This is more reliable than using /dev/sdb1.
After editing /etc/fstab, do not reboot immediately.
First test it with:
sudo mount -aThis attempts to mount everything listed in /etc/fstab.
If there is an error, fix it before rebooting.
A bad /etc/fstab entry can cause boot problems, especially if it refers to an unavailable device without safe options.
For removable or optional drives, consider options such as:
nofail
x-systemd.automount
Example:
UUID=1234-ABCD /mnt/external ext4 defaults,nofail 0 2
The nofail option allows the system to continue booting even if the device is not present.
Before mounting:
/
├── bin
├── etc
├── home
│ └── user
├── mnt
├── usr
└── var
After mounting /dev/sdb1 at /mnt/external:
/
├── bin
├── etc
├── home
│ └── user
├── mnt
│ └── external
│ ├── data
│ └── projects
├── usr
└── var
The mounted filesystem becomes part of the normal directory tree.
You do not access it through a separate drive letter. You access it through the mount point.
A safe manual mounting workflow looks like this:
- Connect the device
- Identify the device name
- Check the filesystem type
- Create a mount point
- Mount the filesystem
- Access the files
- Unmount when finished
- Remove the device
Commands:
lsblk -fsudo mkdir -p /mnt/externalsudo mount /dev/sdb1 /mnt/externalls /mnt/externalsudo umount /mnt/externalAlways unmount removable filesystems before unplugging them.
This matters because Linux may delay writes for performance.
For example, copying a file may appear to finish quickly, but some data may still be waiting in memory.
Unmounting ensures that:
- pending writes are completed
- open files are closed
- filesystem metadata is updated
- the device is safe to remove
This reduces the chance of corruption or data loss.
Many desktop systems already automount removable drives.
For servers or custom setups, there are several ways to automate mounting:
- /etc/fstab
- systemd mount units
- systemd automount units
- udev rules
- desktop environment automounting
- autofs
For most users, /etc/fstab is the best starting point.
For advanced users, udev can run actions when hardware appears or disappears.
udev manages device events in Linux.
It can detect when a USB drive is connected and run a command or script.
However, using udev directly for mounting can be tricky. Long commands with shell features such as && may not work as expected unless run through a script or shell.
A cleaner approach is to have a udev rule call a script.
First, identify the device UUID:
sudo blkid /dev/sdX1Example:
/dev/sdX1: UUID="1234-ABCD" TYPE="ext4"
Create a script:
sudo nano /usr/local/sbin/mount-my-usb.shExample script:
#!/bin/sh
mkdir -p /media/my_usb
mount UUID=1234-ABCD /media/my_usbMake it executable:
sudo chmod +x /usr/local/sbin/mount-my-usb.shThen create a udev rule:
sudo nano /etc/udev/rules.d/99-usb-mount.rulesExample rule:
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="1234-ABCD", RUN+="/usr/local/sbin/mount-my-usb.sh"
Reload rules:
sudo udevadm control --reload-rules
sudo udevadm triggerThen unplug and reconnect the device to test.
For many real systems, systemd automounts or desktop automounting are easier and more reliable than custom udev mounting rules.
Example:
mount: permission denied
Possible causes:
- you forgot sudo
- the mount point permissions are restricted
- the filesystem permissions do not allow access
- security policy is blocking the mount
Try:
sudo mount /dev/sdb1 /mnt/externalIf the mount succeeds but your user cannot write to the mounted filesystem, check ownership and permissions.
For Linux filesystems such as ext4, use:
ls -ld /mnt/externalFor FAT, exFAT, or NTFS filesystems, ownership may need to be controlled with mount options such as uid and gid.
Example:
sudo mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/externalExample:
mount: unknown filesystem type 'exfat'
Possible causes:
- missing filesystem driver
- wrong filesystem type specified
- damaged filesystem
Check the type:
lsblk -for:
sudo blkid /dev/sdb1Then install the needed support package if necessary.
For example, NTFS or exFAT support may require additional packages on some systems.
Example:
umount: /mnt/external: target is busy
Find processes using it:
sudo lsof +f -- /mnt/externalor:
sudo fuser -vm /mnt/externalThen close the program, move out of the directory, or stop the process.
Common fix:
cd ~
sudo umount /mnt/externalExample:
mount: /dev/sdb1 does not exist
Check devices:
lsblkPossible causes:
- device not plugged in
- wrong device name
- kernel has not detected it yet
- bad cable or port
- device name changed
Check recent kernel messages:
dmesg | tailIf mount -a fails, inspect /etc/fstab.
Common mistakes include:
- wrong UUID
- wrong filesystem type
- missing mount point directory
- bad mount options
- incorrect spacing
Create the mount point if missing:
sudo mkdir -p /mnt/externalThen test again:
sudo mount -a- Plug a USB drive into your system and use
lsblkandfdisk -lto identify the device name and partition details. Discuss how device names are assigned and explain the difference between physical devices and partitions. - Create a new directory under
/mntor/media, and mount your USB drive to this directory using themountcommand. Describe the purpose of mount points and how they provide access to external storage devices on Linux. - Navigate to the mount point of the USB drive and perform basic file operations—create, read, edit, and delete a file. Discuss how mounting makes files accessible and how permissions might affect file access on mounted devices.
- What happens if you mount a USB drive onto an existing non-empty directory? Is this allowed, and if so, what happens to the directory’s original contents?
- Create a virtual disk file in your home directory using the
ddcommand, specifying its size and location. Discuss how virtual disk files can simulate actual disks and their potential uses in testing and development. - Format the virtual disk file with an
ext4filesystem usingmkfs.ext4. Explain the significance of different filesystem types and why choosing an appropriate filesystem is important for specific use cases. - Mount the formatted virtual disk file to a directory under
/mnt, just as you would a physical device. Discuss the concept of loopback devices and how they allow files to be mounted as if they were physical disks. - Investigate the differences between temporary and persistent mounting by adding an entry for your USB drive or virtual disk in
/etc/fstab. Explain how persistent mounts work and the benefits of configuring automatic mounts for commonly used devices. - Explore permissions on the mounted USB drive by changing the ownership and permissions of files on it. Discuss how Linux handles permissions for different users on mounted devices and the implications for shared drives.
- Create a script that automatically mounts and unmounts the USB drive upon insertion and removal, utilizing
udevrules for automation. Explain howudevhelps manage device events in Linux and the advantages of automated mounting for frequently used external devices.