Add Physical to LVM – Linux

LVM -Logical Volume Management – An alternative storage solution that allows for expanding a volume group without reformat.

Display Storage Devices On System

Display the existing storage devices (disks) on the system

sudo fdisk -l
Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: KINGSTON SNV2S1000G                     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: KINGSTON SA400S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: KINGSTON SV300S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: KINGSTON SV300S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdd: 447.13 GiB, 480103981056 bytes, 937703088 sectors
Disk model: KINGSTON SA400S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sde: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: KINGSTON SA400S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 5867CAB3-3317-446B-9B2F-6C775D152C5B

Device       Start       End   Sectors   Size Type
/dev/sde1     2048      4095      2048     1M BIOS boot
/dev/sde2     4096   4198399   4194304     2G Linux filesystem
/dev/sde3  4198400 234438655 230240256 109.8G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 1.78 TiB, 1958282788864 bytes, 3824771072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Here we can see both all the physical storage devices, like SDA, as well as the existing logical storage devices.


Display Existing Physical Volume

This will display all of the physical storage devices used in the existing logical volumes.

sudo pvs 
  PV           VG        Fmt  Attr PSize    PFree
  /dev/nvme0n1 ubuntu-vg lvm2 a--   931.51g    0 
  /dev/sda     ubuntu-vg lvm2 a--  <111.79g    0 
  /dev/sdb     ubuntu-vg lvm2 a--  <111.79g    0 
  /dev/sdc     ubuntu-vg lvm2 a--  <111.79g    0 
  /dev/sdd     ubuntu-vg lvm2 a--  <447.13g    0 
  /dev/sde3    ubuntu-vg lvm2 a--  <109.79g    0 

For more information, the following will show an additional amount of information.

sudo pvdisplay
 --- Physical volume ---
  PV Name               /dev/sde3
  VG Name               ubuntu-vg
  PV Size               <109.79 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              28105
  Free PE               0
  Allocated PE          28105
  PV UUID               n3n93n-3JFq-VrED-GZYQ-ngrv-Ak4C-2QKIen
   
  --- Physical volume ---
  PV Name               /dev/sda
  VG Name               ubuntu-vg
  PV Size               111.79 GiB / not usable 1.46 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              28618
  Free PE               0
  Allocated PE          28618
  PV UUID               y7837m-1cyF-uflc-C7j8-tUGg-2bvR-NZ4zxh
   
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               ubuntu-vg
  PV Size               111.79 GiB / not usable 1.46 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              28618
  Free PE               0
  Allocated PE          28618
  PV UUID               nziP0N-rlw1-57rf-dLUT-4DeA-Wyl0-09R1UA
   
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               ubuntu-vg
  PV Size               111.79 GiB / not usable 1.46 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              28618
  Free PE               0
  Allocated PE          28618
  PV UUID               wilruo-S0ZF-CQmZ-wWVp-QoKq-rfcj-3BQkqz
   
  --- Physical volume ---
  PV Name               /dev/sdd
  VG Name               ubuntu-vg
  PV Size               447.13 GiB / not usable <2.84 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              114465
  Free PE               0
  Allocated PE          114465
  PV UUID               sc0rSZ-h3vH-8N33-Kcon-J5s3-vTK2-ygSVBZ
   
  --- Physical volume ---
  PV Name               /dev/nvme0n1
  VG Name               ubuntu-vg
  PV Size               931.51 GiB / not usable 1.71 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              238467
  Free PE               0
  Allocated PE          238467
  PV UUID               6Ml4Yl-2XA9-5Jou-IG6R-VRn6-rEPN-S2dmYe

Create a Physical Volume Device

It is possible to create a physical volume, that can be used in an LVM system. By using the following command. This can afterward be viewed by using the previous command.

sudo pvcreate /dev/sdd

Add Physical Volume to Volume Group

Adding a physical device is done by using its device filename.

sudo vgextend ubuntu-vg /dev/sda4

Expand the Volume Group

Once the physical device has been added to the logical volume. It needs to be expanded to make use of the actual storage.

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

Finally, the filesystem needs to be resized to make use of the actual storage.

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