Notes about the section 'Configure local storage' for RHCSA exam (EX200)
- List, create, delete partitions on MBR and GPT disks
- Create and remove physical volumes
- Assign physical volumes to volume groups
- Create and delete logical volumes
- Configure systems to mount file systems at boot by universally unique ID (UUID) or label
- Add new partitions and logical volumes, and swap to a system non-destructively
List, create, delete partitions on MBR and GPT disks
Use fdisk to manage MBR partitions, use gdisk to manage GPT partitions
List partitions using
LVM - Logical Volume Manager
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:
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
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 -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.
To resize an xfs filesystem, use the xfs_grow command.