Cart 0
No products in the cart.

How to use mount command in Linux ?

How to use mount command in Linux ?

The mount command is a powerful Linux command used to mount a file system or disk partition onto a specific directory in Linux. It is used to enable access to the file systems or disk partitions from the Linux operating system. The mount command also allows you to mount multiple file systems or disk partitions at the same time.

The mount command is commonly used to mount removable media like CD-ROMs, hard drives, and USB flash drives. It is also used to mount network file systems (NFS) and network resources such as printers and scanners.

Here at Fixwebnode, we shall look into the mount command. We will also provide some practical examples of the mount command in action.

 

Syntax of mount command 

The basic syntax of the mount command is as follows:

$ mount [options] source target

Where:

  • Options: This is an optional parameter that is used to specify the mount options.
  • Source: This is the source of the file system or disk partition to be mounted. This can be a device name, a folder path, or a network resource.
  • Target: This is the directory where the file system or disk partition will be mounted.

 

Options for mount command 

The mount command has several options that can be used to modify how it behaves. These options include:

  • -t: This is used to specify the file system type.
  • -o: This is used to specify the mount options.
  • -v: This is used to enable verbose mode.
  • -a: This is used to mount all file systems listed in the /etc/fstab file.
  • -l: This is used to list all mounted file systems.

 

Examples of mount command 

Now that we have covered the basics of the mount command, let’s look at some practical examples of how to use it.

1. Mounting a USB Flash Drive 

To mount a USB flash drive, you first need to identify the device name. You can do this by running the lsblk command. Once you have identified the device name, you can mount it with the following command:

$ mount /dev/sdb1 /mnt/usb

 

2. Mounting an ISO Image 

To mount an ISO image, you first need to create a mount point. This can be done with the following command:

$ mkdir /mnt/iso

Once the mount point has been created, you can mount the ISO image with the following command:

$ mount -t iso9660 -o loop /path/to/image.iso /mnt/iso

 

3. Unmounting a File System 

To unmount a file system, you can use the umount command. For example, to unmount the USB flash drive mounted in the previous example, you can use the following command:

$ umount /mnt/usb

 

4. Mounting a Network File System (NFS) 

To mount an NFS share, you first need to identify the IP address and the mount point. Then, you can mount the NFS share with the following command:

$ mount -t nfs 192.168.1.100:/mnt/nfs /mnt/local

 

5. Mounting a File System with Read/Write Access 

By default, the mount command mounts a file system with read-only access. To mount a file system with read/write access, you can use the -o rw option. For example, to mount the USB flash drive with read/write access, you can use the following command:

$ mount -o rw /dev/sdb1 /mnt/usb

 

6. Mounting a File System at Boot Time 

To mount a file system at boot time, you can add an entry to the /etc/fstab file. This file contains the details for all the file systems that should be mounted when the system boots. For example, to mount the USB flash drive at boot time, you can add the following line to the /etc/fstab file:

/dev/sdb1 /mnt/usb auto defaults 0 0

 

7. Mounting a File System with no auto Option 

By default, the mount command will try to mount all file systems listed in the /etc/fstab file. To prevent a file system from being automatically mounted, you can use the noauto option. For example, to mount the USB flash drive manually, you can add the following line to the /etc/fstab file:

/dev/sdb1 /mnt/usb auto noauto 0 0

 

8. Mounting a File System with noexec Option 

The noexec option can be used to prevent any executable files from running on the mounted file system. To mount the USB flash drive with noexec, you can add the following line to the /etc/fstab file:

/dev/sdb1 /mnt/usb auto noexec 0 0

 

9. Mounting a File System with User Access 

By default, the mount command will mount a file system with root access only. To allow other users to access the file system, you can use the user option. For example, to mount the USB flash drive with user access, you can add the following line to the /etc/fstab file:

/dev/sdb1 /mnt/usb auto user 0 0

 

10. Mounting a File System with Group Access 

The group option can be used to allow a specific group of users to access the mounted file system. To mount the USB flash drive with group access, you can add the following line to the /etc/fstab file:

/dev/sdb1 /mnt/usb auto group 0 0

 

[Need Linux Support ? We can help you. ]

 



CONCLUSION

This article covers the basics of the mount command and how to use it in different Linux distributions. With this knowledge, you should now have a better understanding of how to use the mount command in Linux.

 

How to  fix Mount Command Not Found Error in Linux ?

The mount command is a Linux utility used to attach a filesystem to the Linux directory tree. If you receive an error stating that the mount command is not found, then you will need to install the necessary packages in order to use it. 

Follow the below steps to fix the mount command not found error in Linux.

Before you begin, you will need to be logged in as a user with sudo or root privileges.

 

1. Install the Necessary Packages

The first step is to install the necessary packages for the mount command. The packages will vary depending on your Linux distribution. For example, on Ubuntu, you need to install the util-linux package:

$ sudo apt install util-linux

On CentOS, you need to install the util-linux-ng package:

$ sudo yum install util-linux-ng

 

2. Check the Installation

Once you have installed the packages, you can check to make sure that the mount command is installed correctly by running the following command:

$ which mount

This should return the path to the mount binary. If the command is not found, then you may need to add the path to your $PATH environment variable.

 

3. Use the Mount Command

Now that you have installed the necessary packages and verified that the mount command is installed correctly, you can use it to mount a filesystem. For example, to mount a filesystem located at /dev/sda1 to the /mnt/data directory, you can run the following command:

$ sudo mount /dev/sda1 /mnt/data

Now you should be able to use the mount command without any issues.

 


icon

Sign up to Newsletter

...and receive a free support ticket.