Difference between revisions of "Extend or Reduce size of ext3/ext4 LVM partition in Centos"

From vpsget wiki
Jump to: navigation, search
(Created page with " [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/archi...")
 
 
Line 8: Line 8:
  
  
Extend LVM to use all free space:
+
'''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.
+
Be sure that you have free space on the VolumeGroup.
 +
Suppose we want to extend LogVol01 which is LVM and formated as ext4 to use all VolumeGroup unused space.
 +
If not in RescueMode than unmount:
 +
umount /dev/vg_kvm/LogVol01
 +
Check/fix  errors for any case:
 +
e2fsck -f /dev/mapper/vg_cloud-LogVol01
 +
 
 +
Extend to use all free space in VolumeGroup:
 +
lvm lvextend -l +100%FREE /dev/vg_kvm/LogVol01
 +
resize2fs -f /dev/vg_kvm/LogVol01
 +
#reboot
 +
 
 +
'''Reduce LVM size.
 +
 
 +
[Copied from http://www.linuxtechi.com/reduce-size-lvm-partition/]
 
First of all there should be free space on the LogicalVolume.  
 
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.
 
The decrease MB/GB amount should be less or equal [better less] that free space on the volume.
Line 61: Line 72:
 
  9.9G  9.2G  208M  98% /home
 
  9.9G  9.2G  208M  98% /home
  
[Copied from http://www.linuxtechi.com/reduce-size-lvm-partition/]
+
 
  
 
Usefull links:
 
Usefull links:

Latest revision as of 15:51, 30 September 2015

[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.

Be sure that you have free space on the VolumeGroup. Suppose we want to extend LogVol01 which is LVM and formated as ext4 to use all VolumeGroup unused space. If not in RescueMode than unmount:

umount /dev/vg_kvm/LogVol01

Check/fix errors for any case:

e2fsck -f /dev/mapper/vg_cloud-LogVol01

Extend to use all free space in VolumeGroup:

lvm lvextend -l +100%FREE /dev/vg_kvm/LogVol01
resize2fs -f /dev/vg_kvm/LogVol01
#reboot

Reduce LVM size.

[Copied from http://www.linuxtechi.com/reduce-size-lvm-partition/] 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


Usefull links:

http://coding.infoconex.com/post/2012/10/12/Running-FSCK-on-an-LVM-(Logical-Volume-Manager)-using-Linux-Rescue-Disk

http://serverfault.com/questions/433275/lvm-logical-volume-partition-corrupted-after-lvreduce

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/mdatarecover.html

""