cancel
Showing results for 
Search instead for 
Did you mean: 
TudorRaduta
Community Manager
Community Manager
  • 115 Views

Monday Mission: The "Data Tetris" Maneuver

How to expand a live filesystem when the volume group is full

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?

The Mission

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.

The Map:

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)

Your Challenge:

Post the exact sequence of 4 commands you would use to solve this. Be careful with the final step!

  1. Initialize: How do you tell LVM that /dev/sdb is ready to be used?
  2. Group Up: How do you add this new physical volume to the existing volume group named vg_system?
  3. Extend the Volume: How do you add exactly 5GB to /dev/vg_system/lv_db?
  4. 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).
  • 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?

Let's see those storage skills!

3 Replies
Ad_astra
Flight Engineer Flight Engineer
Flight Engineer
  • 83 Views

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!

Architect_005
Mission Specialist
Mission Specialist
  • 65 Views

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

Chetan_Tiwary_
Community Manager
Community Manager
  • 40 Views

Pro tips apart from the general answer :

  • Use mount point while using xfs_growfs : #xfs_growfs /mount-point
  • Even when it can grow online, use #lsof +D /mount-point to check anything holding open files when it is under heavy write leading to I/O wait.
  • -r works because lvextend calls xfs_growfs or resize2fs internally. 
  • if the LV holds critical data - backup/snapshot is life saver.

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/storage_administration_guid... 

0 Kudos
Join the discussion
You must log in to join this conversation.