[How To] Remove a disk from a LVM volume group

Scenario: we want to add a new disk (usually bigger) to replace an older disk (smaller) from the LVM group

After we added the new disk, we need to create physical LVM volume on it, then move the data from the old disk, remove the old disk from the LVM group. Once we've done that, we can physically remove the disk from the system.

We are assuming the new disk added is /dev/vdd and we want to add this disk in a VG called "Jenkins" which already contains /dev/vdb (which needs to be removed from the system)

Bonus: resize the LVM volume (since we now have more available space in the volume group).

1. Create the physical LVM disk
# pvcreate /dev/vdd
Physical volume "/dev/vdd" successfully created

2. Add the new disk to the Volume Group
# vgextend Jenkins /dev/vdd
Volume group "Jenkins" successfully extended

3. Check the usage on the physical disks
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/vdb Jenkins lvm2 a--u 100.00g 1020.00m 99.00g
/dev/vdc Backup lvm2 a--u 20.00g 1020.00m 19.00g
/dev/vdd Jenkins lvm2 a--u 200.00g 200.00g 0

4. Move the data from the old disk to the new disk
# pvmove /dev/vdb
/dev/vdb: Moved: 100.0%

5. Remove the disk from the Volume Group
# vgreduce Jenkins/dev/vdb
Removed "/dev/vdb" from volume group "Jenkins"

6. Check how much available space we have in the volume group
# vgdisplay
--- Volume group ---
VG Name Jenkins
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 200.00 GiB
PE Size 4.00 MiB
Total PE 51199
Alloc PE / Size 25344 / 99.00 GiB
Free PE / Size 25855 / 101.00 GiB
VG UUID H9SKu0-C4ML-pCrk-bk80-n24x-Ficd-ml85pS

7. Resize the LVM volume (use the -r flag to resize the filesystem as well, so we don't have to do it afterwards)
# lvresize -L 199G /dev/mapper/Jenkins-Data -r
Size of logical volume Jenkins/Data changed from 99.00 GiB (25344 extents) to 199.00 GiB (50944 extents).
Logical volume Data successfully resized.
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/Jenkins-Data is mounted on /var/lib/jenkins; on-line resizing required
old desc_blocks = 7, new_desc_blocks = 13
Performing an on-line resize of /dev/mapper/Jenkins-Data to 52166656 (4k) blocks.
The filesystem on /dev/mapper/Jenkins-Data is now 52166656 blocks long.


All information provided is AS-IS, with no warranty.





Attached Files
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Security Code Security Code
Related Articles RSS Feed
[Issue] SSH session slow to start
Viewed 1316 times since Tue, Sep 23, 2014