This tutorial will guide you through the process of extending an existing Logical Volume Manager (LVM) setup by creating new partitions and incorporating them into the volume group. We’ll use fdisk
to create new partitions and then extend the LVM.
Table of Contents
Prerequisites
- Ensure you have root or sudo privileges.
- Identify the disks and volume groups you wish to extend.
Step 1: Unmount File Systems (if necessary)
Ensure that the file systems on the disks are unmounted to avoid any potential issues.
sudo umount /dev/nvme0n1pX
sudo umount /dev/nvme2n1pX
Replace X
with the appropriate partition number if they are currently mounted. If they are not mounted, you can skip this step.
Step 2: Create New Partitions Using fdisk
We’ll create new partitions non-interactively using echo
and fdisk
. This method ensures that the process is automated and reduces the risk of human error.
For /dev/nvme0n1
:
echo -e "n\np\n\n\n+465G\nw" | sudo fdisk /dev/nvme0n1
For /dev/nvme2n1
:
echo -e "n\np\n\n\n+465G\nw" | sudo fdisk /dev/nvme2n1
Explanation:
n
: Create a new partition.p
: Create a primary partition.\n
: Accept the default partition number.\n
: Accept the default first sector.+465G
: Specify the size of the new partition.w
: Write the changes to the disk.
Step 3: Verify the New Partitions
After creating the partitions, verify that they have been created correctly using lsblk
.
lsblk
You should see the new partitions, e.g., /dev/nvme0n1p2
and /dev/nvme2n1p2
.
Step 4: Create Physical Volumes
Create physical volumes on the new partitions.
sudo pvcreate /dev/nvme0n1p2 /dev/nvme2n1p2
Step 5: Extend the Volume Group
Extend the existing volume group to include the new physical volumes. Assuming your volume group is named vg_storage
:
sudo vgextend vg_storage /dev/nvme0n1p2 /dev/nvme2n1p2
Step 6: Extend the Logical Volume
Extend the logical volume lv_storage
with the newly added space.
sudo lvextend -l +100%FREE /dev/vg_storage/lv_storage
Step 7: Resize the Filesystem
Finally, resize the filesystem to use the new space. Assuming you are using ext4:
sudo resize2fs /dev/vg_storage/lv_storage
Complete Command Sequence
Here is the complete sequence of commands:
# Create new partitions on /dev/nvme0n1 and /dev/nvme2n1
echo -e "n\np\n\n\n+465G\nw" | sudo fdisk /dev/nvme0n1
echo -e "n\np\n\n\n+465G\nw" | sudo fdisk /dev/nvme2n1
# Verify the new partitions
lsblk
# Create physical volumes
sudo pvcreate /dev/nvme0n1p2 /dev/nvme2n1p2
# Extend the volume group
sudo vgextend vg_storage /dev/nvme0n1p2 /dev/nvme2n1p2
# Extend the logical volume
sudo lvextend -l +100%FREE /dev/vg_storage/lv_storage
# Resize the filesystem
sudo resize2fs /dev/vg_storage/lv_storage
This tutorial ensures a careful and systematic approach to extending your LVM setup by creating new partitions and incorporating them into your existing volume group.