How to Extend or increase size of LVM partitions in RHEL/CentOS
# /usr/sbin/lvextend -L+50G /dev/mapper/VolGroup00-LogVol04
Extending logical volume LogVol04 to 149.75 GB
Logical volume LogVol04 successfully resized
# /usr/sbin/vgdisplay
# /sbin/resize2fs /dev/mapper/VolGroup00-LogVol04
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol04 is mounted on /var; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol04 to 39256064 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol04 is now 39256064 blocks long.
Its Done !!!
How to Shrink or reduce size of LVM partitons in RHEL/CentOS
1. Check disk partitions size
# df -hT
Filesystem | Type | Size | Used | Avail | Use% | Mounted on |
/dev/mapper/VolGroup00-LogVol00 | ext3 | 34G | 6.6G | 26G | 21% | / |
/dev/mapper/VolGroup00-LogVol03 | ext3 | 34G | 29G | 27G | 52% | /usr |
/dev/mapper/VolGroup00-LogVol04 | ext3 | 97G | 89G | 2.7G | 98% | /var |
/dev/sda1 | ext3 | 99M | 27M | 67M | 29% | /boot |
tmpfs | tmpfs | 56G | 0 | 56G | 0% | /dev/shm |
/dev/mapper/VolGroup00-LogVol02 | ext3 | 56G | 9.1G | 65G | 13% | /backup |
2. Unmount the partitions that want to shrink or reduce
# umount /dev/mapper/VolGroup00-LogVol02
3. Check a Linux ext2/ext3/ext4 file system partition.
# /sbin/e2fsck -f /dev/mapper/VolGroup00-LogVol02
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found. Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup00-LogVol02: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/VolGroup00-LogVol02: 2887/20971520 files (14.9% non-contiguous), 3019764/20971520 blocks
4. Resize the partition to 30 GB
# /sbin/resize2fs -p /dev/mapper/VolGroup00-LogVol02 30G
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mapper/VolGroup00-LogVol02 to 7864320 (4k) blocks.
Begin pass 2 (max = 1690914)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 640)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 201)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup00-LogVol02 is now 7864320 blocks long.
5. Reduce the size of a logical volume upto 30 GB
# /usr/sbin/lvreduce -L 30G /dev/mapper/VolGroup00-LogVol02
WARNING: Reducing active logical volume to 30.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol02? [y/n]: y
Reducing logical volume LogVol02 to 30.00 GB
Logical volume LogVol02 successfully resized
6. Recheck again, Linux ext2/ext3/ext4 file system partition.
# /sbin/e2fsck -f /dev/mapper/VolGroup00-LogVol02
e2fsck 1.39 (29-May-2006)
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/VolGroup00-LogVol02: 2887/7864320 files (14.9% non-contiguous), 2606289/7864320 blocks
7. Resize the partition to 30 GB
# /sbin/resize2fs -p /dev/mapper/VolGroup00-LogVol02
resize2fs 1.39 (29-May-2006)
The filesystem is already 7864320 blocks long. Nothing to do!
8. Now, Mount the partition.
# mount /dev/mapper/VolGroup00-LogVol02 /backup
9. Again, Check disk partitions size
# df -hT
Filesystem | Type | Size | Used | Avail | Use% | Mounted on |
/dev/mapper/VolGroup00-LogVol00 | ext3 | 34G | 6.6G | 26G | 21% | / |
/dev/mapper/VolGroup00-LogVol03 | ext3 | 34G | 29G | 27G | 52% | /usr |
/dev/mapper/VolGroup00-LogVol04 | ext3 | 97G | 89G | 2.7G | 98% | /var |
/dev/sda1 | ext3 | 99M | 27M | 67M | 29% | /boot |
tmpfs | tmpfs | 56G | 0 | 56G | 0% | /dev/shm |
/dev/mapper/VolGroup00-LogVol02 | ext3 | 30G | 9.1G | 19G | 33% | /backup |
Its Done !!!
Difference between RAID and LVM
S.No. | RAID | LVM |
1. | RAID is used for redundancy. | LVM is a way in which you partition the hard disk logically and it contains its own advantages. |
2. | A RAID device is a physical grouping of disk devices in order to create a logical presentation of one device to an Operating System for redundancy or performance or a combination of the two. | LVM is a logical layer that that can be anipulated in order to create and, or expand a logical presentation of a disk device to an Operating System. |
3. | RAID is a way to create a redundant or striped block device with redundancy using other physical block devices. | LVM usually sits on top of RAID blocks or even standard block devices to accomplish the same result as a partitioning, however it is much more flexible than partitions. You can create multiple volumes crossing multiple physical devices, remove physical devices without loosing data, resize the volumes, create snapshots, etc |
4. | RAID is either a software or a hardware technique to create data storage redundancy across multiple block devices based on required RAID levels. | LVM is a software tool to manage large pool of storage devices making them appear as a single manageable pool of storage resource. LVM can be used to manage a large pool of what we call Just-a-bunch-of-Disk (JBOD) presenting them as a single logical volume and thereby create various partitions for software RAID. |
5. | RAID is NOT any kind of Data backup solution. Its a solution to prevent one of the SPOFs (Single Point of Failure) i.e. DISK failure. By configuring RAID you are just providing an emergency substitute for the Primary disk. It NEVER means that you have configured DATA backup. | LVM is a disk management approach that allows us to create, extend, reduce, delete or resize the volume groups or logical volumes. |