lvremove command examples in Linux [Cheat Sheet]

Introduction to lvremove command

lvremove command removes logical volumes in the volume group. lvremove asks for confirmation before removing any active logical volume. The removal of logical volume will also remove its dependent snapshots.

 

Are you new to LVM and still learning how it works?

We have written detailed articles covering different areas of managing logical volumes, which you can follow using the below links:

Advertisement

Manage Logical Volume in Linux - One STOP Solution
Understand LVM Architecture
Create LVM during installation RHEL/CentOS 7/8
How to use LVM Snapshot for Backup and Restore
Create Mirrored Logical Volume
Create Striped Logical Volume

 

Syntax for lvremove command

The syntax for lvremove command is as follows:

$ sudo lvremove option LV

 

Different examples to use lvremove command

1. Remove the logical volume in the volume group

You can use lvremove command to remove the specified logical volume in the volume group.

For example, the following command removes the logical volume lvol1 in the volume group vol_grp.

$ sudo lvremove vol_grp/lvol1

Sample Output:

It asks for confirmation before removing any active logical volume.

Advertisement

lvremove command to remove logical volume

NOTE:

Logical volumes cannot be deactivated or removed while they are open (e.g. if they contain a mounted filesystem). You can use  umount command to unmount the mount point.

 

2. Remove the logical volume without confirmation

The -f or --force option of lvremove command removes active logical volumes without asking for confirmation.

$ sudo lvremove -f vol_grp/lvol2

OR

$ sudo lvremove --force vol_grp/lvol2

Sample Output:

lvremove command to remove logical volume without confirmation

 

3. Remove all logical volumes in the volume group

If you specify only the volume group name as an argument to lvremove command, it removes all logical volumes in that volume group.

This command removes all logical volumes in the volume group vol_grp.

Advertisement
$ sudo lvremove vol_grp

Sample Output:

lvremove command to remove all logical volumes in the volume group

 

4. Remove logical volume that contains a filesystem in use

Sometimes, when removing a logical volume, you might get the error saying "filesystem in use".

golinux@ubuntu-PC:~$ sudo lvremove vol_grp/lvol6
  Logical volume vol_grp/lvol6 contains a filesystem in use.

In that case, check if the logical volume is mounted in the system.

golinux@ubuntu-PC:~$ sudo mount | grep lvol6
/dev/mapper/vol_grp-lvol6 on /golinux type ext3 (rw,relatime)

If it is mounted, you have to unmount the mount point.

golinux@ubuntu-PC:~$ sudo umount /golinux

Then you can remove the logical volume using the lvremove command.

golinux@ubuntu-PC:~$ sudo lvremove vol_grp/lvol6
Do you really want to remove and DISCARD active logical volume vol_grp/lvol6? [y/n]: y
  Logical volume "lvol6" successfully removed

 

Conclusion

This article teaches you to use lvremove command for removing logical volumes in the Linux system. It is one of the useful commands to manage logical volumes in the volume group. If you have any queries, please let us know in the comment section below.

 

Advertisement

What’s Next

10+ lvcreate command examples in Linux [Cheat Sheet]
vgcreate command examples in Linux [Cheat Sheet]

 

Further Reading

man page for lvremove command

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X