Commands To Mount & Unmount Partitions in Linux
Compilation of commands to be able to mount or unmount a partition in Linux systems in a simple way.
Mounting a disk in a Linux distro is the process that will allow us to access this unit and work on it either because it has a different file system or because of the partitions that have been created on the hard disk.
Although this is an automatic task, we can find ourselves in an error situation that has not made the process correctly, and it will be necessary to do it manually.
Today we will analyze how to perform this task through commands in Linux, in this case, we will use Ubuntu 16.10 but the process It is similar to everyone.
How to Check Active Partitions
The first step is to validate the partitions of the disk to proceed to mount some of the said partitions, for this we will use the command:
The result will display all the system partitions:
Note that the logical structure that Linux assigns to the partitions comes in the order sda, sdb, and sdc. SD is the abbreviation of Serial Device.
How to Mount a Disk with Udisk
Udisk is a command that allows us to manage and carry out multiple administrative tasks on hard drives and flash drives.
Udisk includes a particular command for the entire disk management process called udisksctl which will be quite practical and useful for this process. The basic syntax of this command is:
In this case, we will mount partition sdb1 so that we will use the following line:
udisksctl mount -b /dev/sdb1
In the last line, we must indicate the correct route (sdb2, sdb3, etc.).
We can see that the indicated partition has been mounted correctly. The -b parameter indicates that the mounted partition is a device.
Udisk allows us to mount images using the following syntax:
udisksctl loop-setup -r -f file.iso
With this syntax we indicate the following:
- First, it will enable you to recognize the image as a device.
- The -r parameter prevents data from being overwritten accidentally.
We can rerun the lsblk command to see the selected partition mounted:
With this simple but useful command, we mount disks in Linux environments.
How to Unmount a Disk with Udisk
To unmount a disk using Udisk we will use the following syntax:
udisksctl unmount -b /dev/sd (partition)
In this case, it will be:
udisksctl unmount -b /dev/sdb1
We see that the unit has been unmounted correctly. If we validate the partitions, we will notice that the selected partition is no longer mounted:
Next, we will enter the following command to shut down or remove the Linux system device safely:
udisksctl power-off -b /dev/sdb1
Remember to indicate the correct partition at the end of the command.
Mount & Unmount Discs [Old method]
For all those who wish to use the traditional method in the management process on the disks, it is still possible to use the sudo (root) command for this.
If we want to mount the disk using this method we will use the following line:
sudo mount /dev/sdb1 /mnt
The /mnt parameter indicates where the partition is to be mounted. Now, if we want to dismantle said partition the command to use will be:
sudo umount /dev/sdb1
If we want to know in detail all the available commands with this utility, we can execute the following command in the terminal:
We have options to perform this type of tasks in Linux environments mounting the partitions so that they are available for immediate use.