Mounting Filesystems in Linux

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search

You can mount a file system, such as a hard drive partition that is formatted, solid state storage, a CD or DVD ROM, to name a few examples, by various means. Some examples of ways to mount a file system in Linux include From the command prompt (CLI), at boot in the fstab file, or using file management utility software such as NEMO or PCManFM.

If you mount a filesystem at boot using fstab, mount it on the fly from the command prompt, or click on the disk in PCManFM, (to name a few example methods) and the file system successfully mounts, it will create an entry in a file called mtab. To view mounted file systems you can simply look at the mtab file

cat /etc/mtab

To see what is configured to mount for you on boot you can look at the fstab file

cat /etc/fstab

You can mount a number of different types of media or systems in addition to physical devices. You can mount network file systems, remote file systems, and virtual file systems to name a few.

Discussion on using fstab, and ways to mount file systems shall be discussed.

fstab

The file fstab contains descriptive information about the filesystems the system can mount. fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file. The order of records in fstab is important because fsck, mount, and umount sequentially iterate through fstab doing their thing.

Each filesystem is described on a separate line. Fields on each line are separated by tabs or spaces. Lines starting with '#' are comments. Blank lines are ignored.

The following is a typical example of an fstab entry:

LABEL=t-home2   /home      ext4    defaults,auto_da_alloc      0  2

Mounting on Boot

Adding a second hard drive

In this example we have added another harddrive to an existing system. We will add a rotating aka mechanical hard drive of the type SATA.


If this is the output from blkid:

/dev/sda2: UUID="913aedd1-9c06-46fa-a26e-32bf5ef0a150" TYPE="ext4"

2

By default, if your fstab entry is:

UUID=913aedd1... /media/Schijf-2 ext4 rw,relatime 0 2

your partition will not be shown as Schijf-2 in your sidebar, unless it is labelled Schijf-2. You have two options:

Leave the fstab entry as is and label your partition (e.g. if sda2 is your partition):

e2label /dev/sda2 Schijf-2

Leave the partition as is and add x-gvfs-name=Schijf-21 to your mount options in fstab:

UUID=913aedd1    /media/Schijf-2   ext4    rw,relatime,x-gvfs-name=Schijf-2   0    2

blkid

Which shows a list of all partitions and the assigned UUID. The list should look similar to this:

/dev/sda5: UUID="180cab2a-300a-4e3d-8c8e-0e1df46b9bf7" TYPE="swap"
/dev/sda1: UUID="cd0c7b2c-bf50-4557-bc01-0048764a41d2" TYPE="ext4"
/dev/sdb1: UUID="359d90df-f17a-42f6-ab13-df13bf356de7" TYPE="ext4"

fstab entry:

UUID=359d90df-f17a-42f6-ab13-df13bf356de7 /disk2 ext4 errors=remount-ro 0 1

lsblk 

to list block devices.

lsblk | grep sd

refine list to drives

lsblk -o +ROTA | grep sd

To tell solid state drives from mechanical drives. SSD do not "rotate" so ROTA (short for rotate) is 0

Mine is

/dev/sdb2: UUID="a261659f-4f57-43b2-8994-e041e6ed5a37" TYPE="ext4" PARTUUID="4ef871af-1d0b-46ec-90c1-726879b9a0ed"

UUID=359d90df-f17a-42f6-ab13-df13bf356de7 /mnt/disksdb2 ext4 errors=remount-ro 0 2

helpful: https://www.howtogeek.com/444814/how-to-write-an-fstab-file-on-linux/

        https://serverfault.com/questions/547237/explanation-of-nodev-and-nosuid-in-fstab

If we mount with pcfilefm and then look how it created the entry in mtab

mnt # cat /etc/mtab|grep sdb
/dev/sdb2 /media/nicolep/a261659f-4f57-43b2-8994-e041e6ed5a37 ext4 rw,nosuid,nodev,relatime,data=ordered 0 0

blkid | grep sd[b-c]
/dev/sdb1: UUID="AD0D-FA00" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="000ff742-a5ed-472c-806a-5f276043a754"
/dev/sdb2: UUID="a261659f-4f57-43b2-8994-e041e6ed5a37" TYPE="ext4" PARTUUID="4ef871af-1d0b-46ec-90c1-726879b9a0ed"

Example of cfis fstab

fstab example: persistent mounts using exposed credentials

There are more than one ways to do this. This example uses cifs to permanently mount the shares so that they will be available after reboot. If the system complains add the 'noauto' parameter.

  • First edit your /etc/hosts file and add the hostname and IP address of the windows share or file server
  • Next create mount points in /mnt for each windows share
  • Make sure you have cifs installed
  • Edit /etc/fstab and add a line for each windows share, see examples:
//apollo/public/ /mnt/public cifs username=nicolep,password=yourpass,iocharset=utf8,sec=ntlm  0  0
//apollo/media/ /mnt/media cifs username=nicolep,password=yourpass,iocharset=utf8,sec=ntlm  0  0
//apollo/video/ /mnt/video cifs username=nicolep,password=yourpass,iocharset=utf8,sec=ntlm  0  0
  • mount the shares
mount -a
  • This provides read-only access to the network shares.

Example with file permission specified and full rw access

//apollo/public /mnt/public cifs defaults,dir_mode=0777,file_mode=0777,domain=workgroup,username=nicolep,password=yourpass,uid=1000

troubleshooting: devs keep breaking samba

KERNEL CHANGE BREAKS CIFS.

Somewhere between kernel 4.10.0-38 4.15.0-20 a change was made that COULD PREVENT your cifs shares from mounting. Kernels at and before 4.10 used SMB (Server Message Block) version 1.0 as the default if not specified. Most folks did not specify it so it defaulted to 1.0 and worked. Microsoft ditched 1.0 in Windows 10 and dropped support. Linux kernel developers decided to change the kernel code to no longer default to SMB 1.0 and now default to a newer version. For people that are using legacy networks or NAS devices, it breaks the mounting example from above.

Solution: Specify the SMB version.

The solution is to tell mount.cifs to use the SMB2, SMB2.1 or SMB3.0 protocol using the "vers" parameter. in Linux CIFS Utils and Samba Specify 1.0, 2.0, 2.1, or 3.0.

For the following full line example a linux desktop is connecting to an older NAS device. It is necessary to specify SMB version 1.0. Example:

//apollo/video/ /mnt/video cifs defaults,vers=1.0,domain=workgroup,username=nicolep,password=mythtv,iocharset=utf8,sec=ntlm 0 0

FAILED TO CLOSE BROKEN PIPE

Update 2024 Kernel 5.15 Samba 2:4.15.13+dfsg-0ubuntu1.6 -

cp: failed to close 'filename': Broken pipe

A problem with this latest at the time samba Can't copy large files to Windows share - Error closing file: Input/output error issue workaround, specify prior version of cifs on fstab, see example:

//apollo/video/ /mnt/video cifs vers=2.0,defaults,domain=workgroup,username=nicolep,password=yourpass,uid=1000

 

 

Cleaningduck176.gif
Note: This page is notably untidy. Information is unkept or not arranged neatly and in order. Organization is needed to clean up this page including the removal of options and revision of information presentation. You can help. Please contribute by registering your email address and adding your knowledge to this page. The D.U.C.K. wiki was created to be a free informative place that allows an open exchange of accurate information.
Learn more...