How to Mount and Unmount Drives on Linux

This tutorial is about How to Mount and Unmount Drives on Linux. We will try our best so that you understand this guide. I hope you like this blog, How to Mount and Unmount Drives on Linux. If your answer is yes, please do share after reading this.

So lets keep reading for intertesting info:

Check How to Mount and Unmount Drives on Linux

File systems on Linux and Unix-like operating systems such as macOS can be mounted, unmounted, and remounted using the terminal. File systems on Linux, macOS, and other Unix-like operating systems don’t use separate volume IDs for storage devices like Windows does, for example. Windows assigns each volume a drive letter, such as C: or D:, and each volume’s file system is a tree of directories located under that drive letter. In Linux, the file system is a tree of directories all in one. A mounted storage device has its file system grafted onto this tree so that it appears as an integral part of a contiguous file system.

The newly mounted file system can be accessed from the directory in which it is mounted. This directory is called the mount point for this file system. Many file systems are automatically mounted at boot or on the fly as storage volumes that are attached to the computer at run time. Cautious system administrators can disable the automount features at runtime so they can control connections to the system.

This means that storage devices attached at runtime may not be mounted automatically and must be mounted manually. Manually mounting a file system allows you to make decisions about that file system, for example, B. where the mount point is and whether the file system should be read-only or read-only.

How to mount and unmount drives in Linux

Mount drives in Linux

To mount drives on Linux, you need to use the “mount” command using the following syntax

    • $ sudo mount

First of all, you need to check the already created disk partitions on your system which are not mounted yet. To list partitions with file system types, use the “lsblk” command with the “-f” option.

    • $ lsblk -f
    • NAME FSTYPE TAG UUID MOUNT POINT
    • sda
    • ├─sda1 ext4 0935df16-40b0-4850-9d47-47cd2daf6e59
    • sdb
    • ├─sdb1 ext4 b9df59e6-c806-4851-befa-12402bca5828 /

Alternatively, you can use the “blkid” command to locate and list blocking devices on your system. Unfortunately, this command does not display the current mount points used by your drives.

    • /dev/sda1: TYPE=”ext4″ PARTUUID=”0935df16-40b0-4850-9d47-47cd2daf6e59″
    • /dev/sdb1: UUID=”b9df59e6-c806-4851-befa-12402bca5828″ TYPE=”ext4″ PARTUUID=”269f8db7-90b7-4ebe-acf4-521d6dc2eadb”

In this case, we want to mount the “sda1” partition on our file system. To mount the “sda1” partition, use the “mount” command and specify the directory where you want it to be mounted (in this case, to a directory named “mountpoint” in your home directory.

    • $ sudo mount /dev/sda1 ~/mount point

If you didn’t get any error message in the process, it means your drive partition was mounted successfully.

Check mounted drives in Linux

To verify that your drive partition was mounted correctly, you can use “lsblk” and inspect the mount point column.

    • $ lsblk -f
    • NAME FSTYPE TAG UUID MOUNT POINT
    • sda
    • ├─sda1 ext4 0935df16-40b0-4850-9d47-47cd2daf6e59 /boot/user/mountpoint
    • sdb
    • ├─sdb1 ext4 b9df59e6-c806-4851-befa-12402bca5828 /

Your drive partition was successfully mounted at the mount point, however there is a small issue you need to be aware of when mounting the drives. Using the “mount” command does not make your mounts permanent: you must add them to the fstab file to make them permanent.

Mount drives permanently using fstab

The “fstab” file is a very important file on your file system. Fstab stores static information about file systems, mount points, and various options you may want to set. To list permanently mounted partitions on Linux, use the “cat” command on the fstab file located at /etc.

    • $ cat /etc/fstab
    • # /etc/fstab: static file system information.
    • #
    • # Use ‘blkid’ to print the universally unique identifier for a
    • # device; this can be used with UUID= as a more robust way of naming devices
    • # which works even if disks are added and removed. See fstab(5).
    • #
    • #
    • UUID=b9df59e6-c806/ext4 errors=remount-ro 0 1

The fstab contains several columns:

  • File system: You can specify a UUID (for a universally unique identifier), a label (if you choose a label for your disk), a network ID, or a device name (which is strongly discouraged);
  • Mountpoint: the directory on the file system that you will use to access data stored on the disk;
  • File system type: the type of file system you use to format your disk;
  • Options: some options you can specify to fine-tune your mount (“ro” for a read-only mount or “noexec” to prevent binary execution);
  • Dump – to enable or disable dumping of the file system on the system (using the dump command);
  • Pass Num – Sets the order used for the “fsck” utility to check your file system. If you are not mounting the root device, you must set this option to “2” or “0”, since “1” is reserved for the root device.

As you can see here, in addition to mounting the “sda1” partition in the previous section, only the partition with the UUID shown above would be mounted. To get the partition associated with this UUID, you can use the “blkid” command as follows.

Given the UUID of the fstab file, this would give us

    • $ child | grepb9df
    • /dev/sdb1: UUID=”b9df59e6″

Using the blkid command, I can tell that the “sdb1” partition is mounted at boot time. However, in this case, I need the “sda1” partition to be mounted on boot.

Unmount drives on Linux using umount

On Linux, the easiest way to unmount drives on Linux is to use the “unmount” command. To unmount, you can specify a directory or device name.

    • $ sudo umount

For example, to unmount the device “/dev/sdc1” that we mounted earlier, we would run

To verify that the drive partition was successfully unmounted, you can use the “lsblk” command and specify the drive partition name.

    • $ lsblk /dev/sdc1
    • MAJ NAME:MIN RM RO SIZE MOUNTING POINT TYPE
    • sdc1 8:33 0 29.3G 0 part

Alternatively, you can use the “findmnt” command and specify the device name.

    • $ findmnt /dev/sdc1

Removing fstab file entries

Even if you unmount the drives, they will be remounted (or at least the kernel will try to remount them) at boot time. To stop the system from remounting your drives on boot, you must remove them from the fstab file.

Lazily unmount drives

On Linux, it is also possible to lazily unmount drives with the “-l” option.

    • $ sudo umount -l

Lazily unmounting a device means that it detaches the filesystem from the file hierarchy (so the filesystem will no longer be accessible), but cleans up all references to it when it’s no longer busy. This command can be particularly useful if you are transferring files on the file system or if long operations are running on the file system.

Force unmount the drive

On the other hand, it is possible to force a device to be unmounted using the “-f” option or the “–force” option.

    • $ sudo umount –force

This option is not suitable for local drives, as you want them to be properly unmounted so you don’t lose any data. However, in some cases, you may lose connectivity to an NFS drive, for example: in this case, you can force unmount the drive.

Final words: How to Mount and Unmount Drives on Linux

I hope you understand this article, How to Mount and Unmount Drives on Linux. If your answer is no, you can ask anything via the contact forum section related to this article. And if your answer is yes, please share this article with your friends and family to give us your support.

James Hogan
James Hogan
James Hogan is a notable content writer recognized for his contributions to Bollyinside, where he excels in crafting informative comparison-based articles on topics like laptops, phones, and software. When he's not writing, James enjoys immersing himself in football matches and exploring the digital realm. His curiosity about the ever-evolving tech landscape drives his continuous quest for knowledge, ensuring his content remains fresh and relevant.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Articles

Hubspot Service Hub review 2024: a comprehensive platform

When it comes to customer support operations, HubSpot Service Hub is an all-encompassing customer service platform that is meant to...
Read more
When players on Windows 11 or 10 try to log in to Steam, they may get the error code E87....
Users of Windows 11 or 10 may find it frustrating to deal with the error number 147-0 in Microsoft Office....
The Microsoft Store is an important part of the Windows operating system because it gives users a single place to...
It can be hard to find the right balance between usefulness, durability, and cost when it comes to kitchen storage....
Both AirDroid and Vysor are well-known tools that help Android users control their devices and mirror them. One of the...