How to use mount command in Linux ?

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

Your Cart