Welcome back to the weekly grind! We are going back to basics today with a critical skill: Storage Management.
Managing LVM (Logical Volume Manager) is easy when you have plenty of free space. But what happens when your Volume Group is full, and you need to physically add a new drive to expand a logical volume on the fly?
Your database server is down. The partition /var/lib/mysql (mapped to the Logical Volume lv_db) is 100% full.
You check the Volume Group (vgs) and it has 0 free space.
The Goal: You physically plug in a new 10GB drive (/dev/sdb). You must add this new drive to the existing group and extend the database volume by 5GB.
LVM is a layer cake. You have to build it from the bottom up. If you skip a layer, the command will fail.
man pvcreate (The Physical Layer)man vgextend (The Group Layer)man lvextend (The Logical Layer)Post the exact sequence of 4 commands you would use to solve this. Be careful with the final step!
/dev/sdb is ready to be used?vg_system?/dev/vg_system/lv_db?df -h still shows 100% full. lvextend that combines steps 3 and 4 into a single command. Do you know it?Let's see those storage skills!
Hi there
For today, the answers are:
1) You can tell the LVM the disk is available for use with the following command:
sudo pvcreate /dev/sdb
This initializes the physical volume for use with an LVM. You can check the list of physical volumes available with:
sudo pvdisplay
2) To add the new physical volume to an existing volume group, use:
sudo vgextend vg_system /dev/sdb
3) To extend an existing logical volume by 5GB, use:
sudo lvextend -L +5G /dev/vg_system/lv_db
4) Extend the XFS filesystem on the logical volume with the following command:
sudo xfs_growfs /dev/vg_system/lv_db
Bonus) Adding the -r option to the lvextend command will run both the logical volume extend and file system resize in one go!
Hi
Lets go
Initialize: How do you tell LVM that /dev/sdb is ready to be used?
# pvcreate /dev/sdb
Group Up: How do you add this new physical volume to the existing volume group named vg_system?
Extend the Volume: How do you add exactly 5GB to /dev/vg_system/lv_db?
# vgextend vg_system /dev/sdb
# lvextend -L +5G /dev/vg_system/lv_db
The Trap (Critical): After extending the volume, the filesystem (XFS or EXT4) doesn't know about the new space yet. df -h still shows 100% full.
What is the final command to resize the filesystem to match the new volume size? (Assume it is XFS).
# xfs_growfs /dev/vg_system/lv_db
Bonus Question (Pro Tip): There is a specific flag you can pass to lvextend that combines steps 3 and 4 into a single command. Do you know it?
# lvextend -L +5G -r /dev/vg_system/lv_db
Pro tips apart from the general answer :
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.