How to Disable or Delete Logical Volume(LVM) in Linux Using 4 Easy Steps

In this article, I will take you through the steps to disable or delete Logical Volume in Linux. Logical Volume is a virtual storage carved out from a Volume Group to perform the storage operations. It is this volume which we need to mount on a temporary or permanent mount point to use this storage. This storage can be used as any other storage devices. Logical volume also provides multiple advantages over other types of storage in which primary is the manageability. It is relatively easier to manage than any other storage.

How to Disable or Delete Logical Volume(LVM) in Linux Using 4 Easy Steps 1

Delete Logical Volume(LVM) in Linux

Also Read: How to extend LVM Partition using lvextend command in Linux (RedHat/CentOS 7/8)

1. Check Logical Volume

First you need to find out the volume and its mounting point using df -h command as shown below. From the below output you can see that log_grp1 is currently mounted on /u01 mount point.

[root@localhost ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
devtmpfs                         484M   0    484M   0%    /dev
tmpfs                            496M   0    496M   0%   /dev/shm
tmpfs                            496M  6.8M  489M   2%   /run
tmpfs                            496M   0    496M   0%   /sys/fs/cgroup
/dev/mapper/centos-root           37G  1.5G  36G    4%     /
/dev/sda1                       1014M  193M  822M  19%   /boot
tmpfs                            100M   0    100M   0%   /run/user/0
/dev/mapper/vol_grp-log_grp1     384M  2.3M  358M   1%   /u01

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to User.

2. Unmount the Volume using umount command

You can unmount the logical volume using umount command. Here we are unmounting log_grp1 volume using umount /u01 command as shown below.

[root@localhost ~]# umount /u01

Check and verify volume again if it got unmounted or not using df -h command as shown below.

[root@localhost ~]# df -h
Filesystem                Size  Used  Avail Use% Mounted on
devtmpfs                  484M   0    484M   0%   /dev
tmpfs                     496M   0    496M   0%  /dev/shm
tmpfs                     496M  6.8M  489M   2%   /run
tmpfs                     496M   0    496M   0%  /sys/fs/cgroup
/dev/mapper/centos-root   37G   1.5G  36G    4%    /
/dev/sda1                 1014M 193M  822M   19%  /boot
tmpfs                     100M   0    100M    0%  /run/user/0

After umounting the volume you need to make sure to remove any entry of Logical volume if available from /etc/fstab file.

Advertisements
[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Apr 23 12:36:31 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=1e70f026-ce6f-4938-a74c-ec9c5f6ce74a /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
#/dev/sdb1 swap swap defaults 0 0
#/root/testswap swap swap defaults 0 0
#/dev/vol_grp/log_vol swap swap defaults 0 0

3. Disable Logical Volume using lvchange command

Before you go ahead and delete logical volume you need to first disable it using lvchange command as shown below. To know more about LVM configuration you can check on How to configure LVM (pvcreate, vgcreate and lvcreate ) in Linux Using 6 Easy Steps.

[root@localhost ~]# lvchange -an /dev/vol_grp/log_grp1

Check Logical Volume status using lvscan command as shown below. From the below output you can see that log_grp1 volume is now showing in Inactive state.

[root@localhost ~]# lvscan
ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit
ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit
inactive '/dev/vol_grp/log_grp1' [400.00 MiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [36.99 GiB] inherit

NOTE:

Please note that if you do not want to delete logical volume and want to keep it for future use then you can just disable and keep it. If needed again you can just run lvchange -ay /dev/vol_grp/log_grp1 to enable the volume and mount it to use this volume again.

4. Delete Logical Volume using lvremove command

After disabling the volume you can now delete logical volume by using lvremove command as shown below.

[root@localhost ~]# lvremove /dev/vol_grp/log_grp1
Logical volume "log_grp1" successfully removed

Check Logical Volume Status again by running lvscan command. From the below output, you can check that log_grp1 does not exist now.

[root@localhost ~]# lvscan
ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit
ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [36.99 GiB] inherit

 

 

Popular Recommendations:-

Disable ICMP timestamp responses in Linux

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

9 useful w command in Linux with Examples

12 Most Popular rm command in Linux with Examples

8 Useful Linux watch command examples (RedHat/CentOS 7/8)

25 Useful Linux SS Command Examples to Monitor Network Connections

Advertisements

Leave a Reply