Step 1: Identify the logical volume to be unmounted
Before unmounting a logical volume, you need to identify the volume’s name and location. You can use the `lsblk` command to list all the storage devices and their logical volumes on your system. The command will output the following details:
“`
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 17.5G 0 part
├─ubuntu–vg-root 253:0 0 14.5G 0 lvm /
└─ubuntu–vg-swap_1 253:1 0 3G 0 lvm
“`
In the above example, the logical volume named `ubuntu–vg-root` is mounted on the root directory (`/`). To unmount this volume, we need to follow the next step.
Step 2: Unmount the logical volume
Now that we know the logical volume’s name and location, we can proceed to unmount the volume. To unmount a logical volume, use the `umount` command followed by the volume’s name or location. For instance, to unmount the `ubuntu–vg-root` logical volume, run the following command:
“`
sudo umount /dev/ubuntu-vg/root
“`
If the command executes successfully, you will not see any output. However, if the volume is currently in use, you may receive an error message similar to the following:
“`
umount: /mnt/test: target is busy.
“`
This error indicates that some process or application is currently using the logical volume, and you cannot unmount it until the process is terminated or closed.
Step 3: Verify the logical volume has been unmounted
After unmounting the logical volume, you can verify its status by running the `df` command. The `df` command displays the usage and available space of file systems on your system, including logical volumes. If the volume is successfully unmounted, it will not appear in the output of the `df` command.
For instance, let’s run the `df` command again after unmounting the `ubuntu–vg-root` logical volume:
“`
FileSystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 394M 2.2M 392M 1% /run
/dev/sda3 14G 1.7G 11G 14% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda2 1.9G 47M 1.8G 3% /boot
/dev/sda1 511M 4.6M 507M 1% /boot/efi
“`
As you can see from the output above, the `ubuntu–vg-root` logical volume is no longer mounted on the root directory (`/`).
Conclusion
Unmounting a logical volume is a crucial operation that enables you to manage and perform tasks on it, such as resizing or removing it. It’s essential to ensure that the volume is not in use before unmounting it to avoid data loss or corruption. By following the steps outlined in this article, you can easily unmount logical volumes in Linux.