Disks and devices can’t be used without being mounted. They aren't allowed to be removed without being unmounted. Removing Floppy disks or Flashcards without un-mounting first will block the device. A option to remove such media is eject. File systems are mounted with the mount command and unmounted with the umount command.
/etc/fstab
holds what has to be mounted during boot. mount -a does this again without the need to boot and allows to modify and test /etc/fstab
/etc/mtab
contains actual loaded file system. cat /etc/mtab or mount without any arguments show what is mounted.
lsof /mnt/gentoo/boot/ shows the processes that access the directory.
fuser shows the user that blocks the device. This process can be killed to free the device.
fuser /dev/lirc/0 or fuser -m /dev/usbhd to see processes that have mounted the device
/dev/lirc/0: 20123
20123 is the PID of lircd daemon. To get it more verbose
fuser -v /dev/lirc/0 or kill the process kill -9<PID>
df –T shows file systems with there types
There are different ways to mount the file systems automatically. Since those ways can be used in parallel a directory should be mounted just by one way. As example a network filesystem that will be mounted using autoFS should not have entries in fstab.
Mount mounts a filesystem (as a disk) under a directory (mounting point). Sometimes it is desired to mount just a directory of a filesystem under a mounting point.
Two mount commands are necessary, the first mount the drive as under /mnt
and the second uses the --bind option to mount the directory
mount --bind /mnt/sda3/home/<username>
/<userdir>
/ /home/<username>
/<userdir>
Bind mounts can also be done in /etc/fstab
/mnt/sda3/home/<username>
/<userdir>
/ /home/<username>
/<userdir>
none defaults,bind 0 0
A similar effect can be done with a symbolic link.
The file/etc/fstab
holds defaults for different filesystems and their mounting points and is used during boot. An fstab entry could look as follows:
/dev/sdb1 /mnt/sdb1 ext2 user,exec 0 1
The columns show:
the device file or alternatively UUID=<Universally Unique Identifier>
or LABEL=<the string that you set with e.g. e2label <device> <label>>
. blkid will print out the UUID and when the label.
the mounting point
the file system
mounting options as the members of the user group can mount it and programs on the file systems are allowed to be executed. See man fstab and man mount
tells if the file system need to be dumped
configures how fsck is used on the file system after boot
The mount options of the storage device can also make use of its UUID or label in/etc/fstab
instead of the /dev
file).
The command mount -a mounts everything that is in the /etc/fstab
file except what is marked with the option noauto. This command does the same as the boot.
Add the option nofail if a device might not be present at boot. This prevents stopping and failing the boot process.
The kernel (of a client computer) can be configured to support auto mount CONFIG_AUTOFS4_FS. If an access to an unmounted file system is requested the kernel request the automounter to try to do the mount.
The automounter can just mount filesystems that are configured to be mounted by the linux system. This means as example network file systems must be configured first and be working before automounter can mount them.
To get the automounter install on the client autofs and check it options (Gentoo Linux Use flags).
There are two configuration files in /etc
or /etc/autofs
: auto.master
andauto.misc
.
auto.master
can hold a single line as
/mnt/auto /etc/autofs/auto.misc --timeout=15 --ghost
This defines that all mounting points are under /mnt/auto
and are defined in the fileauto.misc
, that it will be tried to unmount it after 15 seconds of the last access and if it creates empty folders when access is not possible.
The/etc/autofs/auto.misc
needs to be edited and holds the mounting points
cd -fstype=iso9660,ro :/dev/cdrom
Means that the mounting point is the combination ofauto.master
and auto.misc
and results in /mnt/auto/cd
and it is a read only iso9660 filesystem using the device /dev/cdrom
A more practical example using a network drive (first make sure manual mount/umount works)
<mountdir>
-fstype=nfs,rw<computer name or ip>
:/<path>
Do not create subdirectories under /mnt/auto
autofs does this automatically
To start the daemon using OpenRC /etc/init.d/autofs start and rc-update add autofs default and for systemd systemctl start autofs
Disable automounter as for OpenRC /etc/init.d/autofs stop
Mount the drive manually using the mount command
mount -t nfs 192.168.1.33:/home/lindegur/media /mnt/media
If it can not be mounted manually then also automounter can not do it. So fix the problem with manual mounting.