Extend or Reduce size of ext3/ext4 LVM partition in Centos
[DRAFT]
Backup all data better before any partition manipulation. At least bcp the VolGroup using
vgcfgbackup
You can restore after using:
vgcfgrestore -f /etc/lvm/archive/<file containing previous info> <volume group name>
Extend LVM to use all free space:
lvm lvextend -l +100%FREE /dev/vg_kvm/LogVol01 resize2fs -f /dev/vg_kvm/LogVol01 #reboot
Reduce LVM size. First of all there should be free space on the LogicalVolume. The decrease MB/GB amount should be less or equal [better less] that free space on the volume. Suppose we want to reduce /home by 2GB which is LVM and formated as ext4.
df -h /home/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_cloud-LogVol00 12G 9.2G 1.9G 84% /home
Unmount filesystem (if you need to reduce/change the root filesystem you need to use some LiveCD boot. For example use usual Centos OS install disk and select Rescue mode)
umount /home/
Check filesystem for error for any case:
e2fsck -f /dev/mapper/vg_cloud-LogVol00
Shrink the size of /home to desire size. As shown in the above scenario , size of /home is 12 GB , so by reducing it by 2GB , then the size will become 10GB.
[root@cloud ~]# resize2fs /dev/mapper/vg_cloud-LogVol00 10G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/vg_cloud-LogVol00 to 2621440 (4k) blocks. The filesystem on /dev/mapper/vg_cloud-LogVol00 is now 2621440 blocks long.
Now reduce the size using lvreduce command.
[root@cloud ~]# lvreduce -L 10G /dev/mapper/vg_cloud-LogVol00 WARNING: Reducing active logical volume to 10.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce LogVol00? [y/n]: y Reducing logical volume LogVol00 to 10.00 GiB Logical volume LogVol00 successfully resized
For the safer side , now check the reduced filesystem for errors
[root@cloud ~]# e2fsck -f /dev/mapper/vg_cloud-LogVol00 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/vg_cloud-LogVol00: 12/648960 files (0.0% non-contiguous), 2438425/2621440 blocks
Mount the file system and verify the size.
[root@cloud ~]# mount /home/ [root@cloud ~]# df -h /home/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_cloud-LogVol00 9.9G 9.2G 208M 98% /home
[Copied from http://www.linuxtechi.com/reduce-size-lvm-partition/]
Usefull links:
http://serverfault.com/questions/433275/lvm-logical-volume-partition-corrupted-after-lvreduce
""