How-to: How to extend a LVM Volume-Group

How to extend a LVM Volume-Group

A Volume Group of an LVM can be enlarged by additional hard disks/SSD/NVMe at any time.

WARNING

Before you do any changes, make a backup and keep it handy!

Environment in this how-to:

  • Disk already in use: /dev/vda
  • New Disk to be used: /dev/sda
  • System-Version: UCS 4.4-7

Step 1: Format Storage-Device

First you need to know which device you want to format. In my case it is /dev/sda:

root@schuldc2-5:~# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   12G  0 disk
vda               254:0    0   50G  0 disk
├─vda1            254:1    0  487M  0 part /boot
├─vda2            254:2    0    1K  0 part
└─vda5            254:5    0 49,5G  0 part
  ├─vg_ucs-root   253:0    0 47,5G  0 lvm  /
  └─vg_ucs-swap_1 253:1    0    2G  0 lvm  [SWAP]

Then format it using fdisk:

root@schuldc2-5:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xc4a9dbf5.

Command (m for help): n                                                       # n for new
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p                                                         # we want to create a primary partition, so p
Partition number (1-4, default 1): 1                                          # use default value
First sector (2048-25165823, default 2048):                                   # use default value
Last sector, +sectors or +size{K,M,G,T,P} (2048-25165823, default 25165823):  # use default value

Created a new partition 1 of type 'Linux' and of size 12 GiB.

Command (m for help): t                                                       # t for table
Selected partition 1                                                          # partition-number, previously used
Partition type (type L to list all types): 8e                                 # 8e for LVM-Partition-Type
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w                                                       # write changes to disk
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

With fdisk -l, you can check if formatting worked.

root@schuldc2-5:~# fdisk -l /dev/sda
Disk /dev/sda: 12 GiB, 12884901888 bytes, 25165824 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: dos
Disk identifier: 0xc4a9dbf5

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1        2048 25165823 25163776  12G 8e Linux LVM

Step 2: Initializing the New Partition as a Physical Volume (pv)

Now you need to setup the new Disk as Physical Volume

root@schuldc2-5:~# pvcreate /dev/sda1
  Physical volume "/dev/sda1" successfully created.

Step 3: Extend your Volume Group (vg) with the new pv

root@schuldc2-5:~# vgextend vg_ucs /dev/sda1
  Volume group "vg_ucs" successfully extended

You can see if it worked with the pvscan command:

root@schuldc2-5:~# pvscan
  PV /dev/vda5   VG vg_ucs          lvm2 [49,52 GiB / 0    free]
  PV /dev/sda1   VG vg_ucs          lvm2 [12,00 GiB / 12,00 GiB free]
  Total: 2 [61,52 GiB] / in use: 2 [61,52 GiB] / in no VG: 0 [0   ]

Step 4: Extend your Logical Volume (lv)

root@schuldc2-5:~# lvextend -l +100%FREE /dev/vg_ucs/root
  Size of logical volume vg_ucs/root changed from 47,52 GiB (12165 extents) to 59,52 GiB (15236 extents).
  Logical volume vg_ucs/root successfully resized.

Step 5: Resize your filesystem so it uses all of the new free space

root@schuldc2-5:~# resize2fs /dev/mapper/vg_ucs-root
resize2fs 1.43.4 (31-Jan-2017)
Dateisystem bei /dev/mapper/vg_ucs-root ist auf / eingehängt; Online-Größenänderung ist
erforderlich
old_desc_blocks = 6, new_desc_blocks = 8
Das Dateisystem auf /dev/mapper/vg_ucs-root is nun 15601664 (4k) Blöcke lang.

This text will be hidden

2 Likes
Mastodon