Menu Close

Linux LVM Example

Requirement: Wipe away /old and add the space recovered (5 GB) to /new for the following disk layout:

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VG01-LV01_app 5G 2.5G 2.5G 50% /old

/dev/mapper/VG02-LV02_app 5G 2.5G 2.5G 50% /new

  • /old is mounted on Logical Volume LV01 in Volume Group VG01
  • Volume VG01 comprises 1 Logical Volume /dev/mapper/VG01-LV01_app and1 Physical Volume /dev/sdb1
  • /new is mounted on Logical Volume LV02 in Volume Group VG02
  • System and other partitions (/, /boot, /home, etc.) are mounted on Logical Volumes in Volume Group VG00 (not considered in example).

Implementation: Here’s how I met the above requirement on RHEL 5.

STEP 1: Backup the partition to be extended

Backup /new before extending it with space recovered from wiping out /old.

 

STEP 2: Unmount the partitions

sudo umount /old
sudo umount /new

NOTE: You cannot unmount the partitions if they’re busy. You may use lsof to determine which files are using the partition and stop the associated services/processes.

 

STEP 3: Determine the number of extents used by the Logical Volume associated with /old

sudo lvdisplay /dev/mapper/VG01-LV01_app

 

STEP 4: Remove Volumes associated with /old

sudo lvremove /dev/mapper/VG01-LV01_app
sudo vgremove VG01
sudo pvremove /dev/sdb1

 

STEP 5: Extend Volumes associated with /new

sudo pvcreate /dev/sdb1
sudo vgextend VG02 /dev/sdb1
sudo lvextend -l+1599 /dev/mapper/VG02-LV02_app /dev/sdb1

Note that the above assumes that the number of extents associated with /dev/mapper/VG01-LV01_app is 1599 (determined in STEP 2).

 

STEP 6: Check and resize the filesystem

Now that the Volume Group and Logical Volume associated with /new has been extended, the filesystem for the Logical Volume must be checked and resized as follows:

sudo e2fsck -f /dev/mapper/VG02-LV02_app
sudo resize2fs /dev/mapper/VG02-LV02_app

 

STEP 7: Mount partitions

Mount the /new partition as follows:

sudo mount /new

You should see the following disk layout for /new:

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG02-LV02_app 10G 2.5G 7.5G 25% /new

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *