The cart is empty

System administrators often encounter the need to expand storage on servers. LVM (Logical Volume Manager) offers flexible management of disk partitions, allowing for easy resizing of storage without the need to shut down the system. This article provides a detailed guide on how to add a new disk to a CentOS 7 system and extend the existing LVM volume.

1. Preparation and Identification of the New Disk

First, you need to add a physical or virtual disk to your server. After adding the disk, either restart the system or use the command echo "- - -" > /sys/class/scsi_host/host0/scan to detect the new disk without restarting.

To identify the newly added disk, use the command lsblk. The new disk should appear in the list without any partitions.

2. Creating a New Physical Partition

Before creating an LVM, you need to create a physical partition on the disk using the fdisk tool.

  • Run fdisk /dev/sdX, where sdX is the identifier of your new disk.
  • Choose n to create a new partition, then p for a primary partition, and 1 for the first partition. Confirm the default values for the start and end of the partition.
  • To change the partition type to LVM, select t, then 8e.
  • Save the changes and create the partition using w.

3. Creating a Physical Volume for LVM

Now that you have created a new partition, it's time to add it to LVM.

  • Use the command pvcreate /dev/sdX1 to initialize the physical volume, where /dev/sdX1 is the new partition.
  • Verify with pvs that the volume was successfully created.

4. Extending the Volume Group

If you already have an existing volume group to which you want to add the disk, use:

  • vgextend group_name /dev/sdX1, where group_name is the name of your volume group and /dev/sdX1 is the new physical volume.

5. Extending the Logical Volume and File System

  • Extending the logical volume can be done with the command lvextend -l +100%FREE /dev/group_name/volume_name, where /dev/group_name/volume_name is the path to the logical volume.
  • Finally, you need to extend the file system to the new size of the logical volume. For ext4 file systems, use resize2fs /dev/group_name/volume_name.

After completing these steps, the new disk should be successfully added to your system, and the LVM volume extended. Remember to regularly back up important data before making changes to disk partitions.