![]() |
In the Linux operating system, everything is treated as a file. Every Linux administrator must know how to organize and access files better. In this article, we will learn about the Mount and Unmount commands. What are mounting and unmounting in Linux?Mounting and Unmounting are essential tasks in any Linux Operating System. It allows users to access and manage file systems on various storage devices. Let’s see the definition of mounting and unmounting.
PrerequisitesBefore mounting or unmounting drives, you need two things.
Step-by-Step Guide to Mounting Drives on LinuxBefore mounting a dive, you need to identify it. Use the ‘lsblk’ or ‘fdisk -l’ command to list all available storage devices and their partitions.
Command lsblk
Output ![]()
sudo fdisk -l
![]()
![]() Creating a Mount PointA mount point is a directory in linux system where the partition will be attached. Create a mount point using the mkdir command in linux. Example: Create a mount point folder using the mkdir command. sudo mkdir /mnt/mydrive
Mouting the Drive Use the mount command for attach the partition to the mount point. sudo mount /dev/sdb1 /mnt/mydrive
We can verify is mounted with ‘df -h’ command df -h
This command list all mounted file system along with their mount point Output ![]() Configuring /etc/fstab for Automatic Mounting at BootTo automatically a mount drives at boot, you need to configure that ‘/etc/fstab’ file.
sudo vi /etc/fstab
drive_name where_to_mount Device_Format defaults 0 2
Step-by-Step Guide to Unmounting Drives on LinuxIn this section, we will see the easiest way to unmount drives on Linux. We can use the “umount” command for unmount drives on Linux system. Note: The “unmount” command should not be mispeled for “unmount” as there are no “unmount” commands on Linux command. To unmount, you can either specify a directory of a device name. $ sudo umount <device|directory>
The following example demonstrates the unmount command working. sudo umount /mnt/data
![]() Handling Busy Drives and Forced UnmountingSometimes, a drive might be busy and can’t be unmounted. You can identify the processes using the drive with the ‘lsof’ or ‘fuser’ command in the linux operating system.
lsof +f -- drive_name
![]()
sudo umount -l drive_name
The ‘-l’ option will perform a lazy unmount, detaching the drive immediately but cleaning up references when the drive is no longer busy. ![]() ConclusionMounting and unmounting drives on Linux is a fundamental skill for effectively managing your storage devices. Whether you are working with internal drives, external USB drives, or network file systems. Understanding these processes ensures that you can access and manage your filesystems efficiently. Matering the mount and unmount commands empower yous to mange your linux environment with confidence, making storage devices accessible and secure. Mount and Unmount Drives on Linux – FAQsWhat does “mounting” a drive mean?
How do I check which drives are currently mounted?
Do I always need to use ‘sudo’ to mount drives?
Can I mount network drives or remote fileystems?
How do I unmount all mounted filesystems?
|
Reffered: https://www.geeksforgeeks.org
Linux Unix |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 20 |