Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashiwanikumar/08c9c05f354991dea3e1808807fd4f6c to your computer and use it in GitHub Desktop.
Save ashiwanikumar/08c9c05f354991dea3e1808807fd4f6c to your computer and use it in GitHub Desktop.
Complete Guide on Extending LVM with a New Disk and Reconfiguring OS Disk

Complete Guide on Extending LVM with a New Disk and Reconfiguring OS Disk


Step 1: Scan for New Disks

To detect newly added disks without rebooting, use the following command:

echo "- - -" > /sys/class/scsi_host/host32/scan

Replace host32 with the appropriate host number if different on your system.

Step 2: Prepare the New Disk

Create a physical volume on the new disk:

sudo pvcreate /dev/sdx  # Replace /dev/sdx with your new disk identifier

Step 3: Extend Volume Group

Add the new physical volume to your existing volume group:

sudo vgextend your-vg-name /dev/sdx  # Replace your-vg-name and /dev/sdx appropriately

Step 4: Extend Logical Volume

Allocate the newly available space to the logical volume:

sudo lvextend -l +100%FREE /dev/your-vg-name/your-lv-name  # Replace with your volume group and logical volume names

Step 5: Resize the Filesystem

Resize the filesystem to use the new space on the logical volume:

sudo resize2fs /dev/your-vg-name/your-lv-name  # Adjust as necessary, assuming an ext4 filesystem

Step 6: Copying Data to the New Logical Volume

Before manipulating /var, ensure all data is backed up and services that write to /var are stopped:

sudo systemctl stop nginx zabbix-server grafana-server prometheus

Mount the new logical volume temporarily to /mnt and copy all data:

sudo mount /dev/your-vg-name/your-lv-name /mnt
sudo rsync -avxHAX /var/ /mnt/

Update /etc/fstab to use the new logical volume for /var:

# Open /etc/fstab with an editor, e.g., nano
sudo nano /etc/fstab
# Add or modify the line for /var
/dev/your-vg-name/your-lv-name /var ext4 defaults 0 2

Unmount and remount to verify:

sudo umount /mnt
sudo mount -a

Restart the stopped services:

sudo systemctl start nginx zabbix-server grafana-server prometheus

Step 7: Deleting an OS Disk Partition and Adding to LVM

a. Delete the Partition

Using fdisk or parted, remove the OS disk partition (e.g., /dev/sda3):

sudo fdisk /dev/sda

In fdisk, use d to delete and w to write changes to the disk.

b. Update the Kernel's Partition Table

Inform the kernel of the changes to the partition table:

sudo partprobe /dev/sda
c. Create a Physical Volume

Once the partition is deleted, convert it into a physical volume:

sudo pvcreate /dev/sda3
d. Extend the Volume Group and Logical Volume

Extend your volume group and logical volume as described in Steps 3 and 4.

Step 8: Verify Changes

Check the new size of the filesystem:

df -h /var

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment