Configure local storage

Posted in Linux, last updated on and originally published on

Tags: LVM RHCSA Storage

Notes about the section 'Configure local storage' for RHCSA exam (EX200)

Objective details

List, create, delete partitions on MBR and GPT disks

Use fdisk to manage MBR partitions, use gdisk to manage GPT partitions

List partitions using fdisk -l

LVM - Logical Volume Manager

Quickstart

Create PV, create VG, create LV and format LV

pvcreate /dev/xvdb
vgcreate MyVG /dev/xvdb
lvcreate -L5G -n MyLV MyVG
mkfs.xfs /dev/MyVG/MyLV

Create physical volume

To use a physical volume with LVM you have to initialize it with the pvcreate command. You can use a whole disk or disk partition, so if you intend on using the entire drive you don't have to create a partition per se.

The pvcreate command has no real interesting options, so most usages will just be:

pvcreate /dev/xvdb

Create volume group and view details

A volume group groups one or more physical volumes. Create a volume group with the vgcreate command. You can view information about a volume group with vgdisplay

vgcreate MyVG /dev/xvdb
vgdisplay MyVG

A volume group has a number of Physical Extents, abbreviated as PE in all docs and commands. The PE Size multiplied by the number of PE's determines the volume group size. So a volume group with 500 PE's and a PE size of 4MB is 2GB large.

Create a logical volume

A logical volume is created within a volume group. Creating a logical volume group is done with the lvcreate command.

lvcreate -L5G -n MyLV MyVG

The command above creates a logical volume named MyLV in the volume group MyVG with a size of 5GB. The parameter -L specifies the size in MB, GB, etc. Use the parameter -l to specify the size in PE numbers.

Interesting parameter is -T or --thin, which enables thin provisioning. Note: I should blog about this.

Mount logical volume by UUID

Mount LV by UUID:

# use blkid to get UUID for a volume
blkid

# Update fstab
vim /etc/fstab

Add new physical volume to an existing volume group

Add new PV to existing VG

vgextend MyVG /dev/xvdf

Extending a logical volume

To extend a logical volume with additional space, you can use the lvextend command. Basic usage is very simple:

lvextend -L+3G MyLV

The parameter -L allows you to specify the new size of the logical volume. If you prefix the size with + or - the value is not absolute but relative and will thus add or subtract the size you specify. So the option -L+3G will add 3GB to the volume, -L3G will change the volume size to 3GB.

One interesting option is the -r or --resizefs parameter. Specifying this option will make lvextend resize the underlying filesystem so you don't need to do this afterwards.

Resize filesystem

To resize an xfs filesystem, use the xfs_grow command.

xfs_grow /dev/MyVG/MyLV