Thursday, August 23, 2012

Managing LVM part 2

scan utilities


for showing up the physical volumes,suppose pvcreate didn't work,in that case pvscan can show you the physical volumes


for showing up the volume groups

lvscan for searching the logical volumes

lvrename volumegroup001 lvol0 logvol0(new name)

is for renaming logical groups

to add another partition from a different hard disk 

say /dev/sdb

create a partition there by fdisk /dev/sdb

n and then specify it's size,type to t to set it LVM(code is 8e)

if there is an error in writing the partition table try rebooting,if still there is an error try pvcreate the partition and then write the partition table

now to add this partition to the existing volume group

we have to use the vgextend command

vgextend volumegroup001 /dev/sdb2

now as we added another partition from another hard drive the logical volume size should be increased to utilize the extra space that we added,previuosly we set the logical volume as 2.5 GB usable,to extend it we have to use the lvextend command

lvextend /dev/volumegroup001/logvol0 -L +1G(we want to increase by say 1 GB)

but df -h or df -h lvm1/ will show as 2.5 GB

if we unmount the logical volume from lvm1 and then mount again it will still ahow as 2.5 GB

so it basically means although we resized the logical volume at the filesystem the mount point is not increased so we have to use an utility resize

To resize the logical volume so that we can use the extra space

resize2fs resize ext2 and ext3 filesystem

resize2fs /dev/volumegroup001/logvol0 3G(will resize the filesystem to 3GB from 3.5 GB,but it supports only ext3 and not ext2)

now df -h will show lvm1 as 3.0 GB

wow resize2fs really helped me in online resizing

what a relief isn't it,haha.

now resize2fs only support online(that is when mounted) increment,it doesn't support online decrement,so we can not make the size of lvm1 from 3GB to 2.8G,it does not support values like 3.1G,we have to use 3100MB to make it work

so to shrink it we have to unmount first,that is called offline

umount lvm1/

now if I put command as 

resize2fs /dev/volumegroup001/logvol0 2800M

it will instruct me to first run 

e2fsck -f /dev/volumegroup001/logvol0 to prevent data loss,as we are shrinking,not extending,shrinking has the possibility of losing data

so we have to first run

e2fsck -f /dev/volumegroup001/logvol0

then we have to run

resize2fs /dev/volumegroup001/logvol0 2800M

then mount by

mount /dev/volumegroup001/logvol0 lvm1/

now df -h will show it as 2.8GB 

No comments:

Post a Comment