knowledge/technology/linux/Mount.md
2024-07-08 10:43:20 +02:00

8.4 KiB
Raw Permalink Blame History

obj rev
concept 2024-07-08

Mount

Mounting is a fundamental concept in Linux and other Unix-like operating systems, enabling users to access and manage filesystems, storage devices, and partitions. Mounting is the process of making a filesystem accessible at a certain point in the directory tree. When you mount a storage device or a partition, you attach it to a specified directory, known as a mount point. This allows you to access the contents of the device or partition as if they were part of the overall filesystem.

mount Command

Usage:

mount [options] [source] [mount_point]

# Bind Mounts
mount --bind /var/www /mnt/www

# Loop Device
mount -o loop /path/to/file.iso /mnt/iso

# List mounts
mount -l

The source of the filesystem can be specified in other ways too (depending on the filesystem):

  • LABEL=label: Human readable filesystem identifier.
  • UUID=uuid: Filesystem universally unique identifier. The format of the UUID is usually a series of hex digits separated by hyphens.
  • PARTLABEL=label: Human readable partition identifier. This identifier is independent on filesystem and does not change by mkfs or mkswap operations. Its supported for example for GUID Partition Tables (GPT).
  • PARTUUID=uuid: Partition universally unique identifier. This identifier is independent on filesystem and does not change by mkfs or mkswap operations. Its supported for example for GUID Partition Tables (GPT).

Options

Option Description
-a, --all Mount all filesystems in /etc/fstab.
-B, --bind Mount a directory somewhere else
-m, --mkdir[=mode] Allow to make a target directory (mountpoint) if it does not exist yet. The default mode is 0755.
-o, --options opts Use the specified mount options. The opts argument is a comma-separated list.
-r, --read-only Mount the filesystem read-only. A synonym is -o ro.
--source device This option allows you to explicitly define that the argument is the mount source.
--target directory This option allows you to explicitly define that the argument is the mount target.
-t, --types fstype The argument following -t is used to indicate the filesystem type. The filesystem types which are currently supported depend on the running kernel. See /proc/filesystems and /lib/modules/$(uname -r)/kernel/fs for a complete list of the filesystems.

/etc/fstab

The /etc/fstab file is used to define filesystems to be automatically mounted at boot time. Nowadays the entries in this file will be converted to Systemd-Mounts.

Each file contains a mount instruction like this:
DEVICE MOUNT_POINT FILESYSTEM_TYPE OPTIONS DUMP PASS

Example: /dev/sdb1 /mnt/usb ext4 defaults 0 2

  • DEVICE: The device or partition to be mounted.
  • MOUNT_POINT: The directory where the filesystem will be mounted.
  • FILESYSTEM_TYPE: The type of filesystem.
  • OPTIONS: Mount options (e.g., defaults, ro, rw).
  • DUMP: Used by the dump utility to decide if a filesystem should be backed up.
  • PASS: Used by fsck to determine the order in which filesystems are checked.

Mount Options

  • async: All I/O to the filesystem should be done asynchronously.
  • atime: Update inode access times on each access.
  • noatime: Do not update inode access times on each access (useful for performance).
  • auto: Can be mounted with the mount -a command.
  • noauto: Can only be mounted explicitly.
  • defaults: Use default options (rw, suid, dev, exec, auto, nouser, and async).
  • dev: Interpret character or block special devices on the filesystem.
  • nodev: Do not interpret character or block special devices on the filesystem.
  • diratime: Update directory inode access times on each access.
  • nodiratime: Do not update directory inode access times on each access.
  • dirsync: All directory updates within the filesystem should be done synchronously.
  • exec: Permit execution of binaries.
  • noexec: Do not permit execution of any binaries.
  • group: Allow an ordinary user to mount the filesystem if they are a member of the group owning the device.
  • iversion: Increment the inode version field upon each change.
  • mand: Allow mandatory locks on this filesystem.
  • nomand: Do not allow mandatory locks on this filesystem.
  • relatime: Update inode access times relative to modify or change time.
  • norelatime: Do not use the relatime feature.
  • lazytime: Only update times on the in-memory version of an inode.
  • nolazytime: Do not use the lazytime feature.
  • ro: Mount the filesystem read-only.
  • rw: Mount the filesystem read-write.
  • suid: Permit set-user-identifier or set-group-identifier bits to take effect.
  • nosuid: Do not permit set-user-identifier or set-group-identifier bits to take effect.
  • silent: Suppress some error messages.
  • loud: Do not suppress error messages.
  • strictatime: Strictly update inode access times on each access.

Filesystem-Specific Options

Each filesystem type may support its own set of mount options. Here are some examples for a few common filesystems:

ext2, ext3, ext4

  • acl: Enable POSIX Access Control Lists.
  • noacl: Disable POSIX Access Control Lists.
  • user_xattr: Enable user extended attributes.
  • nouser_xattr: Disable user extended attributes.
  • journal: Enable journaling (ext3/ext4).
  • nojournal: Disable journaling (ext3/ext4).

btrfs

  • compress: Enable compression.
  • compress-force: Force compression.
  • nodatacow: Disable copy-on-write for data blocks.
  • nodatasum: Disable data checksumming.
  • subvol: Mount a specific subvolume.

xfs

  • logbufs: Number of in-memory log buffers.
  • logbsize: Size of each in-memory log buffer.
  • noquota: Disable quota enforcement.
  • quota: Enable quota enforcement.

nfs

  • rsize: Set the read buffer size.
  • wsize: Set the write buffer size.
  • timeo: Set the timeout value.
  • intr: Allow interrupts on hard mounts.
  • nointr: Do not allow interrupts on hard mounts.

vfat

  • shortname: Define behavior for handling of short filenames.
  • iocharset: Character set to use for input and output.
  • utf8: Encode and decode 8-bit characters as UTF-8.

Network Filesystems

cifs (Common Internet File System)

  • username: Username to connect to the CIFS share.
  • password: Password to connect to the CIFS share.
  • domain: Domain name for authentication.
  • uid: Set the owner of the files.
  • gid: Set the group of the files.

nfs (Network File System)

  • vers: Specify NFS version.
  • proto: Specify transport protocol (tcp or udp).
  • mountport: Specify port number for MOUNT service.