🌐 🇵🇱 Polski · 🇬🇧 EN
When administering a Linux environment, sooner or later, you will need to resize a logical volume. We have already covered LVM creation, and now we will configure the size. In case you run out of space on a given logical volume, you can add a new physical disk, attach it to the volume group, and then increase the size of the partition.
Extending a logical volume is performed using the lvextend command.
Step 1 - Add 2 GB more to the previously created SecretData volume.
# lvextend -L +2000 /dev/vg_group01/SecretData
Extending logical volume SecretData to 4.88 GB
Logical volume SecretData successfully resized
Step 2 - You can also perform the extension without the "+" sign.
# lvextend -L 6000 /dev/ vg_group01/SecretData
Extending logical volume SecretData to 5.86 GB
Logical volume SecretData successfully resized
Step 3 - A third alternative method is lvresize
# lvresize -L 7000 /dev/ vg_group01/SecretData
Extending logical volume SecretData to 6.84 GB
Logical volume SecretData successfully resized
Step 4 - Verifying the changes
# lvdisplay vg_group01
Using logical volume(s) on command line
-- Logical volume --
LV Name /dev/vg_group01/SecretData
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 6.84 GiB
Current LE 1750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
Now, let's assume we want to add another physical disk and increase the available space in this way.
Step 5 - Creating a new physical volume
# pvcreate /dev/hdc
Physical volume “/dev/hdc” successfully created
Step 6 - Extending the created volume group with the new physical disk
# vgextend vg_group01 /dev/hdc
Volume group “vg_group01” successfully extended
Step 7 - Checking detailed information about the volume group after the changes
# vgdisplay -v vg_group01
Using volume group(s) on command line
Finding volume group “vg_group01”
-- Volume group --
VG Name vg_group01
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 15.99 GiB
PE Size 4.00 MiB
Total PE 4094
Alloc PE / Size 1750 / 6.84 GiB
Free PE / Size 2344 / 9.16 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
-- Logical volume --
LV Name /dev/vg_group01/SecretData
VG Name vg_group01
LV UUID mk9dJM-3qt7-ypbC-nsks-I8Gh-9V3d-4BNE6s
LV Write Access read/write
LV Status available
# open 0
LV Size 6.84 GiB
Current LE 1750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
-- Physical volumes --
PV Name /dev/sdb
PV UUID B0K2qH-0UF4-gphE-MLi3-RFXH-HEP9-9FMbA9
PV Status allocatable
Total PE / Free PE 2047 / 297
PV Name /dev/sdc
PV UUID Wn52Tv-ZEJR-IkYb-2oi1-5Iw7-2oN7-wHihl4
PV Status allocatable
Total PE / Free PE 2047 / 2047
You can see that the group size has increased from 8GB to 15.99 GB. But what if we decide we don't need that much space and would like to shrink the logical volume a bit?
Step 8 - Shrinking the SecretData logical volume by 2GB.
# lvresize -L 4000 /dev/vg_group01/SecretData
WARNING: Reducing active logical volume to 3.91 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce SecretData? [y/n]: y
Reducing logical volume SecretData to 3.91 GiB
Logical volume SecretData successfully resized
Step 9 - Removing the added disk from the volume group
# vgreduce vg_group01 /dev/hdc
Removed “/dev/hdc” from volume group “vg_group01”
Step 10 - Checking changes after removing the disk
# vgdisplay vg_group01
-- Volume group --
VG Name vg_group01
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 12
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 8.00 GiB
PE Size 4.00 MiB
Total PE 2047
Alloc PE / Size 500 / 1.95 GiB
Free PE / Size 1547 / 6.04 GiB
VG UUID IvjXga-898Y-1vCC-azRt-pszL-PeWR-E5athz
The size has been reduced, and the volume group has returned to the state it was in when it was first created.
Comments