Adding physical volume into VG
Prerequisites
A new disk (
/dev/sdbin this case) that you wish to add to the volume group.sudoprivileges or root access to perform LVM management tasks.
Step-by-Step Guide
Step 1: Formatting the Disk Using fdisk
fdiskBefore you can add the new disk to the LVM, you need to partition it.
Open
fdiskto format the new disk (e.g.,/dev/sdb):sudo fdisk /dev/sdbCreate a new partition:
Type
nto create a new partition.Select the partition type and size (accept default values if unsure).
Type
tto change the partition type.Set the type to
8e(Linux LVM).
Write the changes:
Type
wto write the partition table and exitfdisk.
This creates a new partition, e.g.,
/dev/sdb1or/dev/sdb3, depending on how you partitioned the disk.
Step 2: Verify the Volume Group with vgdisplay
vgdisplayBefore adding the new partition to the volume group, you need to identify your existing volume group.
Check the current volume groups:
This will show information about the current volume group, such as its name, size, and free space. Make a note of the volume group name (e.g.,
ubuntu-vg), as you’ll need it for the next steps.
Step 3: Add the New Disk to the Volume Group
Now that you have a partition ready (/dev/sdb3), you can add it to your existing volume group.
Extend the volume group with the new physical volume:
Replace
<volume_group>with the name of your volume group (e.g.,ubuntu-vg).Example:
This command adds
/dev/sdb3to the volume group. You can verify the success of this command by runningvgdisplayagain. The "Free PE" (free space) should increase after extending the volume group.
Step 4: Extend Logical Volumes (Optional)
If you wish to allocate the newly added space to a logical volume, you need to extend it.
Check the logical volumes available:
Extend a specific logical volume to use the newly added space:
Replace
<volume_group>with your volume group name (e.g.,ubuntu-vg).Replace
<logical_volume>with the name of the logical volume you wish to extend (e.g.,ubuntu-lv).The
-l +100%FREEoption means you want to use all the available free space in the volume group.
Example:
Step 5: Resize the Filesystem
After extending the logical volume, you need to resize the filesystem to take advantage of the new space.
Resize the filesystem (for ext4 filesystems, for example):
This command will resize the filesystem to utilize all the newly available space in the logical volume.
Step 6: Verify the Changes
Check the logical volume size:
This will show the updated size of your logical volume.
Check the filesystem size:
This will show the updated space available on the mounted filesystem.
Last updated