This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
mount
Mounting typically involves the attaching of an additional filesystem to the currently accessible filesystem of a computer.[1]
Installation
The mount command is part of the sys-apps/util-linux package. In Gentoo Linux sys-apps/util-linux is part of the system set and is installed on all Gentoo systems by default. If for some strange and unordinary reason it is missing it can be re-installed by running a simple emerge command:
root #
emerge --ask sys-apps/util-linux
Usage
Show mounted filesystems by running the mount command with no arguments or options:
root #
mount
Mount a filesystem. A device file, UUID or label or other means of locating the partition or data source and a mount point are required. Non-system relevant filesystems are normally mounted in the /mnt directory. The proper syntax for mounting a file system is as follows:
root #
mount <DEVICE> <DIRECTORY>
For further details see man 8 mount.
The /media directory is generally used to mount removable devices such as USB drives or SD cards. After determining which device the USB drive shows up as, a command like the following could be used to mount its contents to a newly created usb folder in /media
root #
mkdir /media/usb
root #
mount /dev/sdb1 /media/usb
To unmount a filesystem the device file or the mount point can be specified:
root #
umount <DEVICE>
root #
umount <DIRECTORY>
Sometimes mounting a filesystem requires special options.
root #
mount [OPTIONS] <DEVICE> <DIRECTORY>
Option | Description |
---|---|
-f
|
Simulate the mount |
-t
|
Specify the filesystem, e.g ext4 |
-o OPTION1,OPTION2,...
|
Specify the mount options (see below) |
-a
|
Mount all filesystems in /etc/fstab |
The filesystem being used must support the mount option being passed. Many options are common, but some are filesystem specific. For more information see the mount man page.
Option | Description |
---|---|
defaults
|
Use the default mount options: rw , suid , dev , exec , auto , nouser , async .
|
auto
|
Mount the filesystem automatically on boot. |
noauto
|
Do not mount the filesystem automatically on boot. |
ro
|
Mount the filesystem read-only. |
rw
|
Mount the filesystem read-write. |
sw
|
Mount a swap filesystem. |
atime
|
Update inode access times on every read. |
relatime
|
Update inode access times only on writes to improve I/O performance. |
noatime
|
Never update inode access times for best I/O performance. |
sync
|
Sync drive after each write. Can shorten life for e.g. some flash drives. |
async
|
Sync drive asynchronously. |
discard
|
The equivalent of trim support on Linux. |
exec
|
Allow execution of binaries. |
noexec
|
Do not allow execution of binaries. |
suid
|
Follow SUID and SGID bits. |
nosuid
|
Do not follow SUID and SGID bits. |
user
|
Allow a user to mount the filesystem. |
users
|
Allow every user to mount the filesystem. |
nouser
|
Allow only "root" to mount the filesystem. |
Mounting as non-superuser
According to man mount only the superuser can mount filesystems. However, when fstab contains the user
option on a line any user will be capable of mounting the corresponding partition, device, drive, etc.
Mounting removable media
See the relevant section in the Removable media article.
Despite fstab entries non-superuser mounts of Windows shares will fail (for security reasons). In the following example is found a fstab entry for Windows share; pay close attention to the cifs
option:
/etc/fstab
[...] //server/folder /home/larry/winmount cifs noauto,user 0 0 [...]
user $
mount /home/larry/winmount
This program is not installed setuid root - "user" CIFS mounts not supported.
The solution is to use sudo mount /home/larry/winmount in combination with a corresponding entry in /etc/sudoers to allow passwordless mounting. Be sure to read this before editing the /etc/sudoers file!
/etc/sudoers
[...] larry ALL = NOPASSWD: /bin/mount /home/larry/winmount/, /bin/mount /home/larry/winmount larry ALL = NOPASSWD: /bin/umount /home/larry/winmount/, /bin/umount /home/larry/winmount [...]
See also
- Mounting partitions in the Security Handbook
- fstab — Automatic mount at boot time.
- removable media — Mount on demand.
- AutoFS — Automatic mount upon access.
- Udevil — A small auto-mount utility with little dependencies.
- CurlFtpFS allows one to mount a FTP folder as a regular directory to the local directory tree.
- USB/Guide - Mounting a USB Mass Storage device
- UUIDs and labels