mount: attach file systems
Unix has a single directory tree. To use a disk, USB stick or network share, you mount it on a directory, the mount point, and its files appear there.
Find the device
lsblk -f # disks, partitions, file system types, labels, UUIDs, mount points
sudo blkid # UUIDs and types of every partition
findmnt # what is mounted where, as a tree
findmnt -T /var # which file system holds /var
Examples
sudo mkdir -p /mnt/usb
sudo mount /dev/sdb1 /mnt/usb # type is detected automatically
sudo mount -o ro /dev/sdb1 /mnt/usb # read-only
sudo umount /mnt/usb # unmount before unplugging
sudo mount -o loop,ro ubuntu.iso /mnt/iso # an ISO image
sudo mount -t nfs fileserver:/export/data /mnt/data # NFS share
sudo mount -t cifs //nas/share /mnt/share -o username=anna,uid=$(id -u) # Windows/Samba share
sudo mount -o remount,rw / # make a read-only root writable (rescue mode)
sudo mount --bind /srv/data /var/www/data # make a directory appear in a second place
USB sticks formatted for Windows use exFAT or NTFS; current Linux kernels mount both. Network mounts need the client tools: nfs-common (Debian) or nfs-utils (RHEL) for NFS, cifs-utils for SMB.
Permanent mounts in /etc/fstab
Each line in /etc/fstab describes a file system to mount at boot. Use the UUID rather than /dev/sdb1, because device names can change when disks are added.
# <device> <mount point> <type> <options> <dump> <fsck>
UUID=3f1c2a9e-8d6b-4b6e-9c55-0d2a7e1f4b21 /srv/data ext4 defaults,noatime 0 2
fileserver:/export/backup /mnt/backup nfs defaults,_netdev,nofail 0 0
tmpfs /tmp tmpfs nosuid,nodev,size=2G 0 0
sudo findmnt --verify # check fstab for mistakes
sudo mount -a # mount everything in fstab that is not mounted yet
sudo systemctl daemon-reload # systemd systems: after editing fstab
A wrong line in /etc/fstab can stop the system from booting into normal mode. Run sudo mount -a and findmnt --verify after every change, and add nofail to disks that might be missing.
Useful mount options
| Option | Effect |
|---|---|
ro / rw | Read-only / read-write |
noatime | Do not record access times (fewer writes) |
nosuid, nodev, noexec | Security restrictions; see file system security |
nofail | Do not fail the boot if the device is missing |
_netdev | Wait for the network (for network file systems) |
uid=, gid=, umask= | Owner and permissions for file systems without Unix permissions (FAT, exFAT, CIFS) |
"target is busy"
umount refuses while any process uses a file or has its working directory on the file system. Find out who:
sudo fuser -vm /mnt/usb # processes using the mount
sudo lsof +f -- /mnt/usb
Often it is your own shell: cd out of the directory first. umount -l (lazy) removes it from the directory tree at once and finishes unmounting when it is no longer in use; do not unplug a USB drive before that has happened.
To see how full mounted file systems are, use df.