Jaime Frutos Morales's blog

29/01/2010

How to reduce a logical volume in GNU/Linux using LVM

Filed under: Linux, SysAdmin — acidborg @ 14:01

Description: previously, on this post, I explain how to extend a logical volume using LVM. Now, I’m going to explain how to reduce it without data loss (if you aren’t using all the available space, of course). In this example, I’m going to reduce a logical volume called logical_volume1 belonging to the volume group volume_group1 to 85 Gb of disk space. It’s mounted on /mnt/logical_volume1 .

Steps:

  1. Umount the logical volume: umount /mnt/logical_volume1
  2. Make a backup of the logical volume
  3. Check the filesystem integrity: fsck -f -y -v /dev/volume_group1/logical_volume1
  4. Resize the filesystem to something smaller than the final size (around 80GB in this case): resize2fs /dev/volume_group1/logical_volume1 80000M
  5. Check the filesystem integrity again: fsck -f -y -v /dev/volume_group1/logical_volume1
  6. Reduce the logical volume: lvreduce -L 85G /dev/volume_group1/logical_volume1
  7. Resize the filesystem to fit the logical volume: resize2fs /dev/volume_group1/logical_volume1
  8. Check the filesystem to know whether the reduction went fine: fsck -f -y -v /dev/volume_group1/logical_volume1
  9. Mount the logical volume: mount /mnt/logical_volume1

NOTE: if you aren’t careful with the disk space you are using and the final disk space you are going to be using, this operation can cause data loss. I recommend to backup the logical volume before the reduction and to use around 5GB of “safe space” while reducing the filesystem in order to avoid data loss.

Advertisements

Blog at WordPress.com.

%d bloggers like this: