Very Important

This is a risky operation and is not recommended unless the server has a backup.


After a new disk is added to the Linux system, it is explained step by step how to configure this disk using LVM (Logical Volume Manager).


Checking the disks:

lsblk
BASH


image-2024-10-10_17-32-6.png


As you can see in the image, the added disk appears as /dev/sdb.  The example commands will also proceed on /dev/sdb.


Creating a Partition on a New Disk:

sudo fdisk /dev/sdb
BASH


Follow the steps below in the fdisk interface:

  1. Add New Partition: Press n and create a new partition.
  2. Select Type: Press p to create a primary partition.
  3. Enter Partition Number: Specify the partition number by typing 1.
  4. Use Default Settings: Press Enter to accept all default settings.
  5. Use Default Settings: Press Enter to accept all default settings.
  6. Write and Exit: Press w to save the changes.



Creating Physical Volume:

sudo pvcreate /dev/sdb1
BASH



Listing Volume Groups:


vgdisplay
BASH

image-2024-10-10_17-33-24.png



Include New Disk in Existing Volume Group:


You can use the following command to add /dev/sdb1 disk to the volume group on your system.

sudo vgextend <VG-NAME> /dev/sdb1
BASH



List Logic Volumes:

lvdisplay
BASH

image-2024-10-10_17-45-10.png

Expanding Logic Volume:


You can run the following command to extend logic volume named ubuntu-lv with 100% free space in volume group named ubuntu-vg:


sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
BASH



Expand the file system:

sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
BASH