Friday, November 1, 2013

Expand a Xen virtual disk using LVM

http://www.craigdunn.org/2010/06/howto-expand-a-xen-virtual-disk-using-lvm/

HOWTO: Expand a Xen virtual disk using LVM

So you have a Citrix Xen VM with a Linux filesystem partitioned using LVM and need to expand the size of the root partition? – This is a quick how to that is fairly well tested.
Firstly, I recommend that you backup your data!
In this example, we’ll be adding another 5G to a current 6G logical partition, giving us 11G in total. In this example, our set ups include an extra 2G logical partition so the disk size in total will be 13G.


1 ) Shut down the VM


2 ) Identify the VM and the disk VDI


xenhost# xe vm-disk-list vm="vmhost"
Disk 0 VBD:
uuid ( RO)             : 941baebf-ca8d-0626-f088-30d314433287
    vm-name-label ( RO): vmhost
       userdevice ( RW): 0
 
Disk 0 VDI:
uuid ( RO)             : 03218b6d-dbb1-4181-aa67-5273938af532
       name-label ( RW): 0
    sr-name-label ( RO): TEMPORARY
     virtual-size ( RO): 8589934592
Now resize the VDI from the Xen Center command line:
xenhost# xe vdi-resize uuid=03218b6d-dbb1-4181-aa67-5273938af532 disk-size=13GiB

3 ) Start the VM, login and become root


4 ) Run fdisk and re-create the partition


You will need to identify the root LVM partition in fdisk, remove it, and create it using the largest block size available.
In this example, our LVM partition is the second one (xvda2) – so we select d to delete, 2 to specify the partition, then n to create a new second partition using up to the last cylinder.
vmhost# fdisk /dev/xvda
 
The number of cylinders for this disk is set to 1697.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): p
 
Disk /dev/xvda: 13.9 GB, 13958643712 bytes
255 heads, 63 sectors/track, 1697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      104391   83  Linux
/dev/xvda2              14        1044     8281507+  8e  Linux LVM
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-1697, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-1697, default 1697):
Using default value 1697
 
Command (m for help): wq
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
vmhost#
This WARNING error can safely be ignored.

5 ) Reboot the VM


6 ) Resize the LVM physical volume


You can use pvdisplay to see the current size of the volume:
vmhost# pvdisplay
  --- Physical volume ---
  PV Name               /dev/xvda2
  VG Name               VolGroup00
  PV Size               7.90 GB / not usable 23.41 MB
...snip...
Now run pvresize to grow the physical volume to cover the whole partition…
vmhost# pvresize /dev/xvda2
Now re-run pvdisplay and you should see a bigger volume
vmhost# pvdisplay
  --- Physical volume ---
  PV Name               /dev/xvda2
  VG Name               VolGroup00
  PV Size               12.90 GB / not usable 25.51 MB
...snip...

7 ) Resize the LVM logical volume


vmhost# lvresize /dev/VolGroup00/LogVol00 -L +5G
  Extending logical volume LogVol00 to 10.94 GB
  Logical volume LogVol00 successfully resized

8 ) Grow the file system


This example assumes you are running an ext3 filesystem, other filesystem types may vary – run resize2fs over the volume.
vmhost# 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 2867200 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2867200 blocks long.

Tada!

And that’s it, you should now see an extra 5G available in your root partition
vmhost# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       <strong>11G</strong>  3.8G  6.3G  38% /

No comments:

Post a Comment