how to Mount volumes, drives, and file systems in Raspberry Pi

What does mount mean?
Mount refers to the mounting or embedding of a data medium in the local file system under Linux. It does not matter what form the disk has. This can be a hard disk, a USB stick or a directory share of a NAS with NFS or Samba in the local network.
It should be noted that under Linux no hard disks or USB sticks are mounted, but file systems.
No matter what type of drive, there are always one or more partitions on which a file system is set up, mounted by the Linux kernel in the local file system.
Although you attach file systems to the mount, it is generally referred to as mounting drives, disks, and NAS. This is not a problem as long as it is clear that one does not attach the physical data carrier in the form of the hardware, but a logical data carrier in the form of a file system.
Mount Point
The mount point is the location where the external file system hooks into the local file system. The mount point is nothing more than a local directory through which the external file system can be reached after being mounted.
Since the mount point must exist in the form of a directory when mounting, it may be that there are already files or other directories in this directory. When mounting then what is already in the directory is “invisible” made.
rights management
If a drive has a partition with a file system that is compatible with Linux rights management (for example, ext3, ext4, btrfs, or xfs), the rights of that file system will apply. If a drive has been formatted with a Linux file system, the root directory on that file system belongs to the user “root”.
The root directory of this file system is mounted during mounting in a directory (mount point) of another file system. This directory (mount point) then obtains the permissions of the root directory of the mounted file system.
If there is a file system on the drive that is NOT compatible with Linux rights management (eg FAT32 or NTFS) then all files and directories on it belong to the user “root”. This is always the case if the permissions stored in the file system can not be mapped under Linux. However, when mounting, you can specify that the files should belong to a different user or user group than the user “root” (mount options “uid” and “gid”).
Manually mount local drives
As a rule, drives or file systems are mounted via their device name. The device name must first be determined before you can mount the file system.
lsblkAn existing partition can be mounted using the following command:
mount /dev/sda1/media/usb
It must be noted that the location “/ media / usb” must exist, so that the disk can be mounted there. If in doubt, the mount point must be created as an administrator beforehand.
sudo mkdir /media/usb
Usually, the Linux kernel automatically detects which file system is on the disk. Should it be necessary to specify a file system when mounting for any reason, you can do so with the parameter “-t”.
mount -t vfat /dev/sda1/media/usb
Manually mount Samba share
Mount of network drives that are provided as a Samba directory share can be mounted with the following command:
sudo mount -t cifs //192.168.1.2/release /media/release -o user = pi, pass = raspberry
Please note that the IP address of the share, the mount point as well as the user name and password must be adapted to the respective scenario.
Automatically mount / unmount file systems with “/ etc / fstab”
The manual mount has the disadvantage that you have to repeat it every time after a reboot. However, there are ways and means that file systems are mounted automatically at boot time. The mount commands are entered in the file “/ etc / fstab”.
If “fstab” is mentioned, then this is not a program or command meant, but a file in which drives in the form of hard disks, memory cards, USB sticks and directory shares are registered in the network, which automatically at system startup in the local File system to be mounted.
Let’s take a look at the file “/ etc / fstab” first. For example, on a Raspberry Pi, it could look like this:
proc / proc proc defaults 0 0
/dev/mmcblk0p1/boot vfat defaults 0 2
/dev/mmcblk0p2/ext4 defaults, noatime 0 1
The file is tabular, even if you do not see it at first glance. The character between the columns or entries is a tabulator character or 4 spaces. This must always be exactly correct, otherwise the file will be read and interpreted incorrectly. Therefore, caution should be exercised when editing the file. An error will usually cause the system to boot incorrectly or perhaps not at all.
The first column displays the devices to mount, the second column the corresponding mount points (none for the swap partition, if any), and the third column shows the file system.
Usually “auto” is enough here. This means the kernel must automatically detect the file system. Alternatively, the file system is entered here: z. Ext2, ext3, ext4, reiserfs, vfat, ntfs or cifs.
The fourth column is usually followed by multiple mount options, which may be separated by commas.
The most important option for controlling the mount process is “defaults” (stands for the preferences rw, nouser and async), which does not always make sense.
Furthermore, the following options are possible (incomplete), with some options mutually exclusive.
user: The drive may be mounted by a normal user without root privileges. But only Root or the user who has hung it up, can also unmount it.
- users: Any user may mount and unmount the device.
- nouser: This preference does not allow normal users to mount . Only root is allowed to do that.
- ro: Only read access is possible (read-only).
- rw: Both read and write access is possible (read-write).
- auto: The file system is automatically mounted at boot time.
- noauto: The file system is not automatically mounted at boot time. This can be useful for network shares or drives.
- nofail: If the device does not exist, the system start is continued without interruption, but also without an error message.
- exec: Programs on this file system are allowed to run.
- noexec: programs must not be executed.
- sync: All writes are executed directly on the disk without using the cache. That makes sense with USB data carriers.
- async: All write operations are cached, which is faster, especially with high data volumes.
- …, user, rw, umask = 000: All users are allowed to read and write to the drive. For FAT file systems on USB sticks makes sense.
The fifth column defines whether the file system will be handled by “dump” (to create backups). Since this program is rarely used, you usually enter “0” here.
The sixth and final columns define the order in which the file system check checks with “fsck” at boot time. A “0” means that the file system is not checked. This is useful for swap partitions, CDs / DVDs and network drives. The root partition should have a “1” for it to be checked first. All other file systems get a default “2”.
fstab: car or no car?
Basically, the mount option “noauto” prevents the mount when booting. That is, you would have to manually mount this drive after booting by a program or by a user. If you want a drive to be mounted at boot time, then you have to replace the option “noauto” with “auto”.
“noauto” only makes sense if you want to bind a specific drive to a specific mount point, and there is a process that takes care of the mount at the right time.
By “systemd” (from Raspbian Jessie) you can automatically mount such a drive at the first access. This can be achieved with the mount option “noauto, x-systemd.automount”. This is useful for file systems that can delay booting. For example, directory sharing over the network with Samba or NFS.
Automatically mount / unmount USB stick with “usbmount”
When it comes to automatically mount USB sticks automatically at runtime, the “usbmount” tool is best for that.
Automatically mount / unmount USB stick and USB hard disks with “fstab”
If you want to integrate volumes, drives and shares permanently or automatically at system startup, then you have to create an entry for each file system in the file “/ etc / fstab”. Here are defined all file systems that are mounted at system startup.
Automatically mount / unmount samba shares with “fstab”
In principle, a Samba share always consists of two pages. The server side and the client side. The Samba server was configured successfully in the best case. Now it’s about setting up or automatically mount the shared directory to the local file system of a client or other server.
Samba shares and mount / mount automatically with “fstab”
Automatically mount / mount NFS shares with “autofs”
It does not always have to be the file “/ etc / fstab”. The tool “autofs” is an automounter.
Leave a Reply