Ugacomp

How to mount and unmount partitions in Linux?

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM

CLOUD VPS M

$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM

CLOUD VPS L

$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

In the Linux operating system, mounting and unmounting partitions is a crucial task for managing storage devices effectively. Whether you’re dealing with external drives, network shares, or internal partitions, understanding how to mount and unmount them is essential for accessing data and maintaining system stability.

Identify the Partition

Mounting a partition in Linux involves attaching it to a directory in the file system hierarchy, allowing access to its contents. Here’s how you can do it:

First, you need to know the device name or partition label of the partition you want to mount. You can find this information using commands like lsblk, fdisk, or blkid.

lsblk

Here’s an example output of the lsblk command:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk 
└─sda1   8:1    0 232.9G  0 part /
sdb      8:16   0 931.5G  0 disk 
├─sdb1   8:17   0   100G  0 part 
├─sdb2   8:18   0   500G  0 part 
└─sdb3   8:19   0   331G  0 part 

This output displays information about block devices (disks and partitions) in a tree-like format. Each line represents a block device, with columns providing details such as device name, major and minor device numbers, whether it’s removable, its size, read-only status, type, and mount point (if applicable).

In the provided lsblk output:

  • sda is a disk with a size of 232.9GB. It contains a single partition labeled as sda1.
  • sdb is another disk with a size of 931.5GB. It contains three partitions labeled as sdb1, sdb2, and sdb3.

Create a Mount Point

A mount point in Linux is a directory within the file system hierarchy where a storage device, such as a disk partition or a network share, is attached or “mounted.” When you mount a storage device to a directory, the contents of the device become accessible through that directory, effectively integrating the storage device into the overall file system.

For example, if you mount a USB flash drive to the directory /mnt/usb, all the files and directories stored on the USB drive will be accessible under /mnt/usb. This allows you to interact with the contents of the USB drive as if they were part of the local file system.

Mount points are essential for accessing data stored on external devices, managing storage resources efficiently, and organizing the file system structure in a hierarchical manner..

Choose an empty directory where you want to access the contents of the partition. For example, /mnt/data.

sudo mkdir /mnt/data

Mount the Partition

Use the mount command followed by the device name or partition label and the chosen mount point.

sudo mount /dev/sdb1 /mnt/data

The default file system type in Linux is typically ext4 (Fourth Extended Filesystem). Ext4 is the default file system for many Linux distributions due to its robustness, stability, and features such as support for large file sizes and partitions. It is an evolution of the earlier ext3 file system, offering improvements in performance and scalability.

When mounting a partition with a filesystem type other than the default, such as NTFS, you can use the -t option with the mount command to specify the filesystem type. Here’s an example of how to mount an NTFS partition using the -t ntfs option:

sudo mount -t ntfs /dev/sdb1 /mnt/ntfs_drive

In this example:

  • sudo is used to execute the mount command with superuser privileges, as mounting often requires administrative rights.
  • -t ntfs specifies that the filesystem type of the partition to be mounted is NTFS.
  • /dev/sdb1 is the device file representing the partition you want to mount.
  • /mnt/ntfs_drive is the directory where you want to mount the NTFS partition. Replace this with the desired mount point on your system.

After executing this command, the NTFS partition represented by /dev/sdb1 will be mounted at the specified mount point, /mnt/ntfs_drive, and you’ll be able to access its contents through that directory.

Unmounting Partitions

Unmounting a partition in Linux is the process of detaching it from the file system hierarchy, ensuring that it’s safe to remove or disconnect the storage device. Here’s how to do it:

Check Mounted Partitions

Before unmounting, it’s a good practice to check which partitions are currently mounted and their mount points. You can use the mount command without any arguments for this.

 mount 

The mount command in Linux displays the currently mounted file systems. Here’s an example output:

/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)

Each line in the output represents a mounted file system and provides information about:

  • The device or partition (/dev/sda1, proc, sysfs).
  • The mount point (/, /proc, /sys).
  • The file system type (ext4, proc, sysfs).
  • Mount options (rw, noexec, nosuid, nodev).

This output indicates that /dev/sda1 is mounted as the root directory (/) with an ext4 file system, and /proc and /sys are virtual file systems used by the kernel with their respective mount points and file system types.

Use the umount command followed by the mount point where the partition is mounted.

sudo umount /mnt/data

If the partition is in use, you might encounter an error. Make sure no processes are accessing files on the partition before attempting to unmount it.

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.
 

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.