- How to remove logical and physical volume from Volume Group in Linux
- Remove Physical Volume from Volume Group
- Linux remove logical volume
- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- Examples
- SEE ALSO
- lvremove command examples in Linux [Cheat Sheet]
- Are you new to LVM and still learning how it works?
- Syntax for lvremove command
- Different examples to use lvremove command
- 1. Remove the logical volume in the volume group
- 2. Remove the logical volume without confirmation
- 3. Remove all logical volumes in the volume group
- 4. Remove logical volume that contains a filesystem in use
- Conclusion
How to remove logical and physical volume from Volume Group in Linux
NOTE: Make sure the logical volume to be removed is unmounted.
Once the logical volume is unmounted run the below command from the terminal
# lvremove /dev/NewGroup/office
Do you really want to remove active logical volume office? [y/n]: y
Logical volume «office» successfully removed
Verify the changes (As you see «office» logical volume is successfully deleted)
[root@test2 ~] # lvdisplay
— Logical volume —
LV Path /dev/NewGroup/root
LV Name root
VG Name NewGroup
LV UUID 52mm9d-feyC-AWVH-NTMC-VwNa-Ns1p-cJc8vJ
LV Write Access read/write
LV Creation host, time test2.example, 2014-03-14 02:37:58 +0530
LV Status available
# open 1
LV Size 9.92 GiB
Current LE 2539
Segments 1
Allocation inherit
Read ahead sectors auto
— currently set to 256
Block device 253:0
— Logical volume —
LV Path /dev/NewGroup/swap
LV Name swap
VG Name NewGroup
LV UUID 48hszS-I0uT-Zsxr-jnoY-yEbj-hfBJ-isofU7
LV Write Access read/write
LV Creation host, time test2.example, 2014-03-14 02:38:00 +0530
LV Status available
# open 1
LV Size 1.95 GiB
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
— currently set to 256
Block device 253:1
Remove Physical Volume from Volume Group
Verify the physical volume to be removed
# vgdisplay -v
Finding all volume groups
Finding volume group «VolGroup»
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 25
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 10.81 GiB
PE Size 4.00 MiB
Total PE 2767
Alloc PE / Size 2265 / 8.85 GiB
Free PE / Size 502 / 1.96 GiB
VG UUID uH5AP5-b24E-92h7-nL8b-7Bio-fXe3-pstWIW
— Logical volume —
LV Path /dev/VolGroup/root
LV Name root
VG Name VolGroup
LV UUID Qn8TnI-TLNm-rl4Y-ORnd-zU3p-2Kj1-ALSLAg
LV Write Access read/write
LV Creation host, time ,
LV Status available
# open 1
LV Size 6.85 GiB
Current LE 1753
Segments 2
Allocation inherit
Read ahead sectors auto
— currently set to 256
Block device 253:0
— Logical volume —
LV Path /dev/VolGroup/swap
LV Name swap
VG Name VolGroup
LV UUID M1ucwx-2sjb-o9Q4-a2td-aPvi-FO1C-ggHuPn
LV Write Access read/write
LV Creation host, time ,
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
— currently set to 256
Block device 253:1
— Physical volumes —
PV Name /dev/sda2
PV UUID uYfzd6-4jh1-YTP7-I3hx-WdSJ-4mTR-HZcdtq
PV Status allocatable
Total PE / Free PE 2509 / 244
PV Name /dev/sdb1
PV UUID Am341r-9WLV-NgWo-Un0Y-sVLQ-fyXM-0zyDix
PV Status allocatable
Total PE / Free PE 258 / 258
As you can see my VolGroup contains /dev/sda2 and /dev/sdb1 partition. Let us try to remove /dev/sdb1
To remove a Physical Volume first we need to remove it from the Volume group using below syntax
# vgreduce name_of_vol_grp path/of/pv
# vgreduce VolGroup /dev/sdb1
Removed «/dev/sdb1» from volume group «VolGroup»
Once reduce from volgroup we can easily remove the PV using below command
I hope I made my self clear. Please let me know your success and failures.
Linux remove logical volume
NAME
lvremove — remove a logical volume
SYNOPSIS
lvremove [-A|--autobackup y|n>] [--commandprofile ProfileName] [-d|--debug] [-h|--help] [-S|--select Selection] [-t|--test] [-v|--verbose] [--version] [-f|--force] [--noudevsync] [LogicalVolumeName|Path>. ]
DESCRIPTION
lvremove removes one or more logical volumes. Confirmation will be requested before deactivating any active logical volume prior to removal. Logical volumes cannot be deactivated or removed while they are open (e.g. if they contain a mounted filesystem). Removing an origin logical volume will also remove all dependent snapshots. If the logical volume is clustered then it must be deactivated on all nodes in the cluster before it can be removed. A single lvchange command issued from one node can do this.
OPTIONS
See lvm(8) for common options. -f, --force Remove active logical volumes without confirmation. Tool will try to deactivate unused volume. To proceed with damaged pools use -ff --noudevsync Disable udev synchronisation. The process will not wait for notification from udev. It will continue irrespective of any possible udev processing in the background. You should only use this if udev is not running or has rules that ignore the devices LVM2 creates.
Examples
Remove the active logical volume lvol1 in volume group vg00 without asking for confirmation: lvremove -f vg00/lvol1 Remove all logical volumes in volume group vg00: lvremove vg00
SEE ALSO
lvcreate(8), lvdisplay(8), lvchange(8), lvm(8), lvs(8), lvscan(8), vgremove(8)
© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
lvremove command examples in Linux [Cheat Sheet]
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:
Syntax for lvremove command
The syntax for lvremove command is as follows:
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.
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
$ sudo lvremove --force vol_grp/lvol2
Sample Output:
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 .
Sample Output:
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.