"FEDORA/RHEL/CENTOS - some LVM command examples"

Published: Mon 17 December 2018

In content.

NOTE: This guide serves as tutorial to claim free space in my machine. I will attempt to explain what I am doing. Assumption is made such that there are 5 partitions in /dev/sda at the time of writing. I was trying to claim /dev/sda2 to extend /dev/sda5 which contained fedora root partition. This guide should help you in attempting RHEL RHCSA exam.

Introduction

LVM, known as Logical Volume Manager is a device mapper target that gives logical volume management for the Linux Kernel.

Command examples

In following series of commands, I am going to re-claim space for my root partition.

  • #fdisk -l /dev/sda- list available partitions in hdd

The output should be something like below:

[code lang=text]
Disk /dev/sda: 232.9 GiB, 250000000000 bytes, 488281250 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: 0xcd8f72e0

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1126399 1124352 549M 7 HPFS/NTFS/exFAT /dev/sda2 1126400 283475967 282349568 134.7G 7 HPFS/NTFS/exFAT /dev/sda3 283475968 285573119 2097152 1G 83 Linux /dev/sda4 285573120 488280063 202706944 96.7G 5 Extended /dev/sda5 285575168 488280063 202704896 96.7G 8e Linux LVM

[/code]

  • #pvs or #pvdisplay - Display available physical volume

  • #pvcreate /dev/sda2 - Create new physical volume

  • #vgs or #vgdisplay - Display volume groups available. Take note ofVG or VG Name. You will need it for next step.

  • #vgextend fedora /dev/sda2 - Extend volume group fedora with /dev/sda2 .

  • #vgdisplay - Take note of Free PE/Size

  • #lvextend -l +<FREE PE> /dev/fedora/root - Extend fedora root partition by Free PE/Size number

  • #resize2fs /dev/fedora/root - Resize root volume

  • #lvdisplay - display claimed free space, under LV Size

Take note that not all of RHEL RHCSA commands covered.

Resource:

1.https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/lv_extend

2.http://landoflinux.com/linux_lvm_command_examples.html

3.https://www.tecmint.com/extend-and-reduce-lvms-in-linux/

social