In my local machine, I have multiple logical volume. When I try to remove below logical volume, getting below error.
[root@redhat001:~]# lvremove /dev/mapper/system-lv_redhat
Logical volume /dev/mapper/system-lv_redhat contains a filesystem in use.
To remove this logical volume in redhat linux system, please follow the below methods.
1. Please check if any logical volume mounted on your system. To check this you can simply use "mount" command with grep option.
[root@redhat001:~]# mount | grep /dev/mapper/system-lv_redhat
Above command will provide you information if logical system is mount or not. If you found, file system is mount, then please umount it first, remove entry from /etc/fstab then try to remove logical volume.
2. In case no logical volume mounted but still you are not able to remove logical volume then you need to check this method if any file is open or any active process using by this logical volume. To check this please run the below command.
[root@redhat001:~]# lsof | grep /dev/mapper/system-lv_redhat
or
[root@redhat001:~]#ps -ef | grep /dev/mapper/system-lv_redhat
Using first command you can find if any file is open at system end and it is use by this logical volume, so please check this and close files.
Second command use when you get any process using by this logical volume. please kill the particular process. If process use by root file system, I would suggest instead of killing the process, please stop any application if running and reboot the server, so it would automatically kill your process.
3. You can deactivate logical volume and remove it
[root@redhat001:~]# lvchange -an /dev/mapper/system-lv_redhat
[root@redhat001:~]#lvs
[root@redhat001:~]#lvremove -f /dev/mapper/system-lv_redhat
Please deactivate logical volume using lvchange command and run lvs to verify that logical volume deactivate or not.
Hope using above three methods you can resolve this error. In case of any query, please drop a comment on this article.