mount command in Linux with examples

We can use the mount command in Linux to attach file systems and removable devices such as USB flash drives. The default file system for most Linux distributions is ext4. We can also dismount file systems with the unmount command.

In this tutorial, we’ll show you, with examples, the best way to utilize the mount command and its various command line options to attach and detach file systems, ISO files, and USB drives.

In this tutorial you will learn:

  • How to use the mount command on Linux
mount command in Linux with examples
mount command in Linux with examples
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software mount
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Frequently Used Options



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

mount command in Linux Basic Examples

  1. Running the mount command by itself, without any arguments, will display all currently mounted file systems. Information about the directories the file systems are mounted to and their mount options can also be found in the output.
    $ mount
    
    Using the mount command without any arguments to display all currently mounted file systems
    Using the mount command without any arguments to display all currently mounted file systems
  2. We can specify what file systems we want the mount command to display by passing it the -t option on the command line. For example, if we wanted to see only ext4 file systems, we would use the syntax below.
    $ mount -t ext4
    
    Using the mount command with the -t option to display
    Using the mount command with the -t option to display
  3. When mounting a file system with the mount command, you must specify the directory or mount point you want to attach the files system to. We can use the general syntax below to attach a file system to a mount point.
    $ mount [options] ... DEVICE DIRECTORY
    
  4. Nowadays, most Linux distros will auto mount USB drives immediately upon insertion, but sometimes they’ll require a manual mount. When mounting a USB drive with the mount command, you’ll need to utilize the mkdir command to create a mount point.


    $ mkdir /media/usb-drive
    

    Once you’ve created a mount point, you can run the fdisk -1 command to find the block device path to your drive. For example, if the output of the fdisk -l command states that your USB is using /dev/sdc1, you can use the syntax below to mount the USB drive.

    $ sudo mount /dev/sdc1 /media/usb-drive
    
  5. Mounting an ISO works similarly, but you’ll need to use a loop device. A loop device is a block device that maps its data to other block devices such as an ISO file, which is why one is required. We can attach an iso file to our mount point with a loop device by passing the -o loop command line option to the mount command.
    $ sudo mount /image.iso /media/iso-file -o loop
    
  6. The general syntax and functionality for the unmount command is identical to the mount command. You can pass two kinds of arguments to the unmount command to detach a file system, the directory where its mounted and the name of the file system itself.
    $ unmount DIRECTORY
    
    $ UNMOUNT DEVICE
    
  7. By default, the unmount command is unable to detach a file system that is in use. You can ascertain which processes are using your file system with the fuser command. Upon running this command, you should be able to pinpoint the cause of the activity and halt the processes to proceed with the dismount.


    $ fuser /media/usb-drive
    
  8. Sometimes, though, you won’t always have time to check for and stop these processes. In cases such as these, you can perform a “lazy” dismount with the -l option. This will tell the unmount command to detach the file system as soon as it ceases activity.
    $ unmount --lazy DEVICE
    

Closing Thoughts

In this tutorial, we learned all about the mount and unmount commands on Linux. These commands are essential to master for users and administrators that frequently test and utilize different file systems and block devices, such as external hard drives, on Linux.