Monday, 11 October 2010

How to increase size of an LVM inside a xen VM.

First increase the lv in the xen host
lvextend -L +5G /dev/VolGroup/fred 
Log into the VM and use 'parted to create a new disk - This part is only for the new Redhat 5.x servers.
parted (parted) mkpart primary 5363 10.7GB (parted) quit 
Next - This part is only for the new Redhat 5.x servers.
lvm> lvmdiskscan   /
dev/ramdisk        [       16.00 MB]  
/dev/root          [        2.50 GB]
/dev/ram           [       16.00 MB]    
/dev/hda1          [      101.94 MB]    
/dev/VolGroup00/LogVol01
[        2.38 GB] /dev/ram2            
[       16.00 MB]   /dev/hda2            
[        4.89 GB] LVM physical volume   /dev/ram3             
[       16.00 MB]   /dev/hda3             
[        5.00 GB]
lvm> pvcreate /dev/hda3   Physical volume "/dev/hda3" successfully created
lvm> vgextend VolGroup00 /dev/hda3
Volume group "VolGroup00" successfully extended
lvm> lvextend -L +5G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 7.50 GB
Logical volume LogVol00 successfully resized
lvm> exit 
Next
[root@rednfs01 ~]# resize2fs /dev/VolGroup00/LogVol00 resize2fs 1.39
(29-May-2006) Filesystem at /dev/VolGroup00/LogVol00 is mounted on /;
on-line resizing required Performing an on-line resize of
/dev/VolGroup00/LogVol00 to 1966080 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 1966080 blocks long.  
When you run 'resize2fs' is may come up with a message 'Please run 'e2fsck -f /dev/VolGroup00/dev2_root' first.' then please run the command as requested then rerun the resize2fs command.

Expanding DomU Logical Volumes
Get the Logical Volume name and path:
So you gave your Xen virtual machine a 10GB Logical Volume and not it's not enough eh? This is easy to fix.
We start by using the lvdisplay command to get the path to the Logical Volume
[ root@vs /srv/xen ] lvdisplay
--- Logical volume ---
LV Name /dev/vgsys/lvvirt
VG Name vgsys
LV UUID XMWzWW-oZih-A5uH-91Sa-7l1y-8cqf-18KcNB
LV Write Access read/write
LV Status available
# open 1
LV Size 60.00 GB
Current LE 1920
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

According to lvdisplay the path to our Logical Volume is /dev/vgsys/lvvirt.

Hot Resizing Logical Volume:

Resizing the Logical Volume is actually very easy, you'll be amazed.
lvresize --size +10G /dev/vgsys/lvvirt
This lvresize command specifies to add 10GB to /dev/vgsys/lvvirt. This will only take a second.
Hot Resizing the filesystem:
resize2fs /dev/mapper/vgsys-lvvirt
That's really it! You can only hot resize if the Filesystem is getting larger. If you need to shrink it then you'll have to take the Volume offline first. Isn't this easier than dealing with partitions that are too small?

No comments:

Post a Comment