Extending LVM Volume

It is time to take advantage of using LVM volumes when installing Linux servers. I got a Virtual Machine that I’ve used for a while now and I run out of disk space. So here are my steps for extending LVM volume.

Add additional Disk Space

I’ve chosen to add an additional virtual disk not to increase the capacity on my current one.  I’ll be adding an additional 1TB thin-provisioned disk and reboot the system.

ADVERTISEMENT

VMware add Hard Disk

Now I have 120GB  /dev/sda disk and 1TB /dev/sdb disk that I need to add into my LVM group. To check that I need to type lsblk

root@linux01:~# lsblk
NAME                   MAJ:MIN  RM  SIZE    RO  TYPE MOUNTPOINT
sda                    8:0      0    120G   0   disk
├─sda1                 8:1      0    487M   0   part /boot
├─sda2                 8:2      0    1K     0   part
└─sda5                 8:5      0    119.5G 0   part
 ├─linux01--vg-root    252:0    0    118.5G 0   lvm  /
 └─linux01--vg-swap_1  252:1    0    976M   0   lvm  [SWAP]
sdb                    8:16     0    1T     0   disk
sr0                    11:0     1    62M    0   rom

Partition the new disk

Now we need to partition the new disk with Linux LVM file type 8e with fdisk. In  my case, the choices will be: n(for new partition), p(for primary), 1(for partition number sdb1), then few hits of Enter for the defaults, After that I’m changing the partition type to 8e so I press t(to change partition type) and 8e(for Linux LVM) and at the end w to write the changes

root@linux01:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
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 0xc2ce9a65.

Command (m for help): n
Partition type
 p primary (0 primary, 0 extended, 4 free)
 e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-2147483647, default 2048): <enter>
Last sector, +sectors or +size{K,M,G,T,P} (2048-2147483647, default 2147483647):<enter>

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

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

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

Now to check that everything is OK we’ll type fdisk /dev/sdb -l and this is what you should see at the end of the output:

Device     Boot Start         End     Sectors  Size   Id  Type
/dev/sdb1        2048  2147483647  2147481600  1024G  8e  Linux LVM

Extend the LVM Volume

Now we are going to convert the physical volume into a logical volume for use in LVM groups.

root@linux01:~# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created

Check the Volume Group name and extend it in our case the Volume Group Name is linux01-vg (the name is under the first VG)

root@linux01:~# vgs
 VG        #PV #LV #SN Attr   VSize    VFree
 linux01-vg 1  2   0   wz--n- 119.52g  36.00m
root@linux01:~# vgextend linux01-vg /dev/sdb1
 Volume group "linux01-vg" successfully extended

Now we are going to add all additional space that we have from the new disk

root@linux01:~# df -h /
Filesystem                   Size Used Avail Use% Mounted on
/dev/mapper/linux01--vg-root 117G 78G  34G   71%  /
root@linux01:~# lvextend /dev/mapper/linux01--vg-root /dev/sdb1
 Size of logical volume linux01-vg/root changed from 118.53 GiB (30344 extents) to 1.12 TiB (292487 extents).
 Logical volume root successfully resized.
root@linux01:~# resize2fs /dev/mapper/linux01--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/linux01--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 8, new_desc_blocks = 72
The filesystem on /dev/mapper/linux01--vg-root is now 299506688 (4k) blocks long.

And now confirm that we have the space that we allocated

root@linux01:~# df -h /
Filesystem                   Size  Used  Avail  Use%  Mounted on
/dev/mapper/linux01--vg-root 1.1T   78G  1001G  8%    /

So, from 120GB now we have 1.1TB of space which should be enough for the purpose of this Virtual Machine.

Logical Volume Manager (Linux): https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)

ADVERTISEMENT