How to Add a New Disk to Expand the Size of a Linux LVM

How to Add a New Disk to Expand the Size of a Linux LVM

The main benefit of LVM over conventional disc partitions is its ability for “dynamic partitions,” which allow us to construct and resize (expand or shrink) LVM volumes dynamically as needed. This article explains how to add a new disc to LVM. Since there is no physical disc boundary restriction for LVM logical volumes, it is possible to create a sizable LVM volume that spans several smaller physical drives. Due to the flexibility of partitioning, you can manage storage space more effectively as disc utilization fluctuates.

You may easily increase the size of an existing LVM volume by adding extra discs; the process is described below.

Merge Multiple Disks into a Volume Group

Configuration

Run the command `lsblk` which displays sdb is the New Disk

root@test-server:/home/badshah# lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
fd0                         2:0    1     4K  0 disk
loop0                       7:0    0 111.6M  1 loop /snap/core/12941
loop1                       7:1    0 110.6M  1 loop /snap/core/12834
sda                         8:0    0     1T  0 disk
+-sda1                      8:1    0     1M  0 part
+-sda2                      8:2    0     1G  0 part /boot
+-sda3                      8:3    0  1023G  0 part
  +-ubuntu--vg-ubuntu--lv 253:0    0  1023G  0 lvm  /
sdb                         8:16   0     1T  0 disk
sr0                        11:0    1  1024M  0 rom
001..lsblk

New Disk label type

GPT is the new disc label type for /dev/sdb

root@test-server:/home/badshah# parted /dev/sdb mklabel gpt
Information: You may need to update /etc/fstab.
002..parted

Run ‘fdisk’ to see if Linux on your machine has recognised the newly attached drives.

root@test-server:/home/badshah# fdisk -l
Disk /dev/loop0: 111.6 MiB, 117014528 bytes, 228544 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

Disk /dev/loop1: 110.6 MiB, 115986432 bytes, 226536 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

Disk /dev/sda: 1 TiB, 1099511627776 bytes, 2147483648 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
Disklabel type: gpt
Disk identifier: ACCB736D-3677-4E0A-B7EC-8CAAB74F6106

Device       Start        End    Sectors  Size Type
/dev/sda1     2048       4095       2048    1M BIOS boot
/dev/sda2     4096    2101247    2097152    1G Linux filesystem
/dev/sda3  2101248 2147481599 2145380352 1023G Linux filesystem

Disk /dev/sdb: 1 TiB, 1099511627776 bytes, 2147483648 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
Disklabel type: gpt
Disk identifier: 6876529E-1369-4256-AC36-7CA9BDD0F1F2

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 1023 GiB, 1098433691648 bytes, 2145378304 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
003..fdisk

Run the command `fdisk /dev/sdb` then press `p` for printed, `m` for help, `g` for create a new empty GPT partition table and `w` for write table to disk and exit

root@test-server:/home/badshah# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdb: 1 TiB, 1099511627776 bytes, 2147483648 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
Disklabel type: gpt
Disk identifier: 6876529E-1369-4256-AC36-7CA9BDD0F1F2

Command (m for help): m
Help:
  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

Command (m for help): g
Created a new GPT disklabel (GUID: 3881499E-5A22-044A-B714-2271EBB40282).

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
004..fdisk

Allocate the entire space of `/dev/sdb` to the same partition and press `Yes` to continue

root@test-server:/home/badshah# parted /dev/sdb mkpart primary 0 100%
Warning: You requested a partition from 0.00B to 1100GB (sectors 0..2147483647).
The closest location we can manage is 1049kB to 1100GB (sectors 2048..2147483614).
Is this still acceptable to you?
Yes/No? yes
Information: You may need to update /etc/fstab.
005..parted 100

Create physical volume

root@test-server:/home/badshah# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
006..pvcreate

The ‘lvs’ command can be used to determine whether LVM volume groups and logical volumes are available.

root@test-server:/home/badshah# lvs
  LV        VG        Attr       LSize     Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- <1023.00g
007..lvs

Volume group `ubuntu-vg` successfully extended. To verify that volume is added or not run, please check the below

root@test-server:/home/badshah# vgs
  VG        #PV #LV #SN Attr   VSize     VFree
  ubuntu-vg   1   1   0 wz--n- <1023.00g    0
root@test-server:/home/badshah# vgextend ubuntu-vg /dev/sdb1
  Volume group "ubuntu-vg" successfully extended
root@test-server:/home/badshah# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  ubuntu-vg   2   1   0 wz--n- <2.00t    0
008..vgs
008..vgs 1

Given the resized volume group, now extend the “root” logical volume itself

root@test-server:/home/badshah# lvextend -l+100%FREE /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <1023.00 GiB (261887 extents) to <2.00 TiB (524030 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

The final step is to enlarge the file system created inside the “root” volume. Otherwise, the file system will not recognize additional free space in the volume.

root@test-server:/home/badshah# resize2fs -p /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 128, new_desc_blocks = 256
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 536606720 (4k) blocks long.
010..resize2fs

Now check the Hard drive using command df -H

011..df

Follow us TwitterFacebookLinkedIn

Open Source Listing

Previous Post
Next Post

Leave a Reply