Why do we need to mount partitions on the disk, and How to mount it?

When we insert a disk into our system, what would the system do to get the data in the disk?

C.C.
NTUST-AIVC
5 min readApr 25, 2022

--

Co-Author: Y. S. Huang, a master’s student studying AIVC, likes open-source.
If you are interested, go to check my Github!

First, after partitioning your disk to a part and formatting it to a readable file format, this file can’t be used by the Linux system directly, before we use this file, we have to mount this file in the Linux system.

How does mounting work, and how do mounting partition in Linux?

First of all, you have to place your disk under a catalog, and we call the catalog mount_point.
Using the command $ lsblk -f or $ dl -h to get the disk list, the command $ lsblk -f shows more details than the command $ dl -h.

lsblk -f
df -h

The command $ lsblk -f will show your disk UUID, find the disk that you just separated, and format it, if you don’t know how to partition your disk:

If you haven’t decided the path where you want to mount your device, Use this command to create a new mount_point.

After all preparation, we can start mounting now!

First, use the following command below to mount your device.

Then, we use the command lsblk -f to see whether the device has mounted or not, and copy your UUID. Later, we will use the UUID.

After mounting the device, we can open out fstab file.

So, what is the fstab file?

All the information on your storage devices and their file systems are included in the fstab file, in the nutshell, fstab file can automatically mount your hard disks, partitions, and so on.

For Windows and Linux double boot users, fstab file can also mount the disk in which format is Fat or NTFS.

We can see the path of this file is /etc/fstab

There are six different types in this file, <file system>, <mount point>, <type>, <options>, <dump>, <pass>.

What are these types represent?

<file system>: The UUID of your hardware.

<mount point>: The address where we mount.

<type>: tell us the format of files, like ext4, ntfs, jfs, swap……

<options>: There are lots of arguments for options, these arguments are for permissions settings.

<dump>: Check the value to decide whether to back up this file system or not.

0 will ignore this system file

1 will create a file for backup.

<pass>: when you turn on your computer, the computer will check our file system with fsck, fsck will check the number to decide the tier of the file system.

0 will ignore this file system.

1 the file system will be the first order to check, usually use at /.

2 the file system will be checked later.

Additional information

About<type> swap

<type> swap

The swap partition is used as an overflow area for RAM. It is an individual disk partition, which was faster than a swap file.

But in modern Linux kernels, it can bypass the filesystem when using a swap file, making it essentially identical performance-wise unless your filesystem is hopelessly fragmented.

If you want to know how to setup your swap partitions and some commands for swap setting, you can see the following link below:

About <options>

noatime: close anotime, it can improve efficiency and reduce load cycle.

defaults : which include rw,suid,dev,exec,auto,nouser,and async.

ro : mount read-only.

rw: mount can read and write.

exec: Let the binary file in the partition can be executed.

auto: when you use the command $ mount -a, the partition will be auto mounted.

nouser: These partitions can only be mounted by the root user.

async : every I/O will be executed asynchronously.

If you want to know further information about opts arguments, you can see the following link below:

After understanding the information above, we can start mounting our device automatically.
Insert the UUID which we just copy from lsblk -f

Save the change and quit the fstab file, then we successfully mount the device!

The disk in the windows system can also be mounted in the Linux system, but there are some problems with NTFS files.

Q1: When you mount the disk whose format is NTFS, the disk is in read-only mode, if you want to change the read-only mode to write and read mode.

Sol: To solve this problem, you have to go Windows system to close the fast boot.

Q2: When I use the command chmod to change the permission or use the command chown or chgrp to change the owner and group. Why it doesn’t change or show the error?

Sol: Change the options to default, uid=1000, gid=1000, umask=022.

--

--