| by Arround The Web | No comments

Linux Mount Command

In Linux, the file systems set the files in the form of a tree. This file system initiates from the root directory and all the child branches come out of this root directory. When we want to add a new child (file system) to this tree, the Linux mount command comes into practice. It allows us to attach a file to a specified mount point in the current file system. The command tells the kernel about the directory and the type of file system to mount and also the device name where the file system is present.

This article demonstrates the use of the Linux mount command using several examples.

Syntax:

The syntax for using the mount command is as follows:

mount -t [type] [dev] [directory]

Here, mount is the keyword for the mount command. The “-t[type]” refers to the type of file system; it is an optional parameter. We need to provide the “dev” device on which the provided file system is mounted. Lastly, the destination directory name has to be mentioned at which the file system is mounted.

Mount Options

Different options can be indicated to mount a file system. Here is a list of some of these possibilities:

  • -a

It is employed to attach all of the file systems that are listed in etc/fstab.

  • -l

It is utilized to list all the file systems that are mounted and adds the labels.

  • -h

All the options for commands could be generated from it.

  • -V

It displays the version information.

  • -t

It tells the type of the file system.

  • -T

It is used to describe the substitutes etc/fstab file.

  • -r

It enables the read-only mounting of the file system.

Utilizing the Linux Mount Command to Mount All the Files

We can display the list of all the file systems that are currently mounted by simply writing the mount command on the terminal. Launch the terminal first. Additionally, type the subsequent command:

omar@omar-VirtualBox:~$ mount

Hit “enter” and you get the currently mounted file systems list:

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

udev on /dev type devtmpfs (rw,nosuid,relatime,size=1946576k,nr_inodes=486644,mode=755,inode64)

devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)

tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=401848k,mode=755,inode64)

/dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro)

securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)

tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)

cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)

pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)

bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18327)

tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)

debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)

mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)

configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)

fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)

none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)

/dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=401844k,nr_inodes=100461,mode=700,uid=1000,gid=1000,inode64)

gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

Also, using the “-l” mount option, you can obtain the list of the mounted file.

omar@omar-VirtualBox:~$ sudo mount -l

After entering the sudo password, it displays the file systems here:

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

udev on /dev type devtmpfs (rw,nosuid,relatime,size=1946576k,nr_inodes=486644,mode=755,inode64)

devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)

tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=401848k,mode=755,inode64)

/dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro)

securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)

tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)

cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)

pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)

bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18327)

tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)

debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)

mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)

configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)

fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)

none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)

/dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=401844k,nr_inodes=100461,mode=700,uid=1000,gid=1000,inode64)

gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)

Checking the Mount Version

The version of the mount can be obtained using the following command:

omar@omar-VirtualBox:~$ sudo mount –V

This shows us the version information of the mount.

mount from util-linux 2.37.2 (libmount 2.37.2: selinux, smack, btrfs, verity, namespaces, assert, debug)

Listing the Particular File System with the Mount Command

Using the mount command, we can find out the mounts that are used by a particular file system. For instance, if we want to find the mounts that the “ext4” file system is using, we need to write the command in the proceeding syntax:

omar@omar-VirtualBox:~$ -t <filesystem-type>

To get the list of all the ext4 file systems, run this command:

omar@omar-VirtualBox:~$ sudo mount -t ext4

/dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro)

Utilizing the /Etc/Fstab

The /etc/fstab is used to find the mount location of the devices and has all the information about the system devices. It also tells us about the mount options that these system devices employ. To check if a particular file system is present in the /etc/fstab configuration file after reading its content, you need to provide one of the two parameters which are [device] or [directory] with the mount command.

To find the structure of /etc/fstab, run this command:

omar@omar-VirtualBox:~$ cat /etc/fstab

Here, you will see the structure that it follows:

# /etc/fstab: static file system information.

#

# Use 'blkid' to print the universally unique identifier for a

# device; this may be used with UUID= as a more robust way to name devices

# that works even if disks are added and removed. See fstab(5).

#

# <file system> <mount point> <type> <options> <dump> <pass>

# / was on /dev/sda3 during installation

UUID=3333d4f7-af61-4a62-9b78-46de26682e91 / ext4 errors=remount-ro 0 1

# /boot/efi was on /dev/sda2 during installation

UUID=6DAB-1E13 /boot/efi vfat umask=0077 0 1

/swapfile none swap sw 0 0

From this, we understand that the file system that is currently mounted is —————-. The mounting point for it is the root “/”. Next, the type of the file system is mentioned as “ext4”. The mount option that is used here is “defaults,noatime”. Lastly, the value for “dump” is “0” and the value for “pass” is mentioned as “1”.

If we want to mount a file system that is present in the /etc/fstab configuration file, you can either use the “mount [option] [directory]” command which tells you about the mounting point or “mount [option] [device]” which provides the mounting device.

Mounting a USB

We can mount a USB drive manually if the automated mounting fails to mount. To manually mount a USB, we first create a directory. Write the following mkdir command and make sure to write it with sudo privileges as we create a new directory which requires the admin rights.

omar@omar-VirtualBox:~$ sudo mkdir /media/usb-drive

[sudo] password for omar:

 

Now, the mounting point for the USB drive is created.

To locate the USB drive and the file system, we have to write the command on the terminal:

omar@omar-VirtualBox:~$ sudo fdisk –l

Here, we get the list of all the USB drives and files:

Disk /dev/sda: 17.95 GiB, 19273465856 bytes, 37643488 sectors

Disk model: VBOX HARDDISK

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: B1802B5F-BC14-4293-888D-BACCD438E53C

Device Start End Sectors Size Type

/dev/sda1 2048 4095 2048 1M BIOS boot

/dev/sda2 4096 1054719 1050624 513M EFI System

/dev/sda3 1054720 37642239 36587520 17.4G Linux filesystem

Mount any specific USB drive through the device identifier from the output of the fdisk output. From the previous output, we have three drives. We choose the /dev/sda3. We write the command as follows:

omar@omar-VirtualBox:~$ sudo mount /dev/sda /media/usb-drive

If the drive is not already mounted, it will be mounted.

mount: /media/usb-drive: /dev/sda already mounted or mount point busy.

As shown in our output, it says that the USB drive is already mounted.

Mounting the ISO Files and CD-ROM with the Mount Command

The ISO (identical storage image of optical media) files as well as the CD-ROMs can also be mounted using the mount command in Linux. As for the CD-ROMs, they are removable devices. So, Linux attaches them automatically when removed after insertion. But if it does not mount the CD-ROMs, you can mount it yourself. First, we run a command to attach a CD-ROM. Then, we go for ISO files.

To manually mount the CD-ROM, carry out the following command:

omar@omar-VirtualBox:~$ sudo mount -t iso9660 -o ro /dev/cdrom /mnt

Here, the iso9660 is the standardized file system for CD-ROMs.

Whereas to mount an ISO file, the –o loop mount option is used because an ISO file must have its data mapped to a loop device before it can be mounted.

Detaching a Mounted File System

Using the umount command, we can unmount an attached file system. Detachment can be done by either providing the device identifier or the point of mount for that specific file system.

For instance, to unmount a USB drive, the command is as follows:

omar@omar-VirtualBox:~$ sudo umount /media/usb-drive

Conclusion

The Linux mount command is explained in detail in this guide. We demonstrated the syntax and the mount options for this command in the initial section of this article. With the utilization of these options, you can obtain the required output. Either all of the file systems that are currently mounted or a single specified system can be found with the mount command options. The use of the mount command with different examples to mount a file system, USB drive, or ISO file is explained with practical implementation in Linux Mint 21.

Share Button

Source: linuxhint.com

Leave a Reply