Sunday, January 16, 2011

Resizing Xen guests using LVM

I have a RHEL 5.4 server running as a Xen Dom0, and wish to install several RHEL 5.4 DomU guests using LVM as the guest disks. I have created the following two LVs:

xen-test02-root  VM-VG -wi-a-   6.00G
xen-test02-swap  VM-VG -wi-a- 512.00M

I used the custom partitioning option when installing the guest so no LVM is used in the guest, only 2 disks. One for / (xvda) and one for swap (xvdb).

This all works fine, but now I wish to test extending the root partition. So far, I have tried using lvextend from the Dom0. This works:

# lvextend -L +4GB /dev/VM-VG/xen-test02-root
  Extending logical volume xen-test02-root to 10.00 GB
  Logical volume xen-test02-root successfully resized

fdisk shows that the disk is now 10.7GB:

# fdisk -l /dev/VM-VG/xen-test02-root

Disk /dev/VM-VG/xen-test02-root: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

                     Device Boot      Start         End      Blocks   Id  System
/dev/VM-VG/xen-test02-root1   *           1         783     6289416   83  Linux

I now wish to extend the partition on that disk with parted:

(parted) print

Model: Linux device-mapper (dm)
Disk /dev/mapper/VM--VG-xen--test02--root: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  6440MB  6440MB  primary  ext3         boot

(parted) resize 1 32.3kB 10.7GB
Error: File system has an incompatible feature enabled.
(parted)

Any clues as to what I'm doing wrong? Is parted the best tool to resize partitons? Should I be using LVM differently for Xen guests?

Many thanks, z0mbix

  • Why are you partitioning the LV, instead of just using it directly? Also, if you are going to be manipulating the partition table, it's best to do it in the guest. Worst, it looks like you might be trying to fiddle with the partition table in the dom0 while the domU is still running... dangerous.

    My simple recipe for resizing a domU disk, which I've done probably in excess of a hundred times by now, is to have the domUs with the LV as the full root partition (xvda1) and then running:

    lvextend -L+NG -n domu-root vg
    xm shutdown -w domu
    xm create domu
    ssh domu resize2fs /dev/xvda1
    

    And voila, all done. For non-root filesystems, you can just detach/reattach (useful for swap, in particular), but root needs the reboot.

    z0mbix : Thanks, I would like to use the LV directly, but the RHEL installer requires that I partition /dev/xvda to create /dev/xvda1 for the / partition. Is there a way around this? I'm not editing the partition table when the domU is running.
    womble : I avoid RHEL like the plague, so I'd just use xen-tools to create the domU and avoid the RHEL installer altogether.
    From womble
  • Your problem here is that you can't resize ext3 partition with parted. you have to remove the journal (turning ext3 into ext2) and then resize.

    see this for more info

    http://www.hermann-uwe.de/blog/resizing-ext3-partitions-with-parted

  • In your XEN config, don't attach the LV to xvda, attach it to something like xvda1 etc. The xvda device in your domU won't exist, but your domU will still see /dev/xvda1 as a valid partition.

  • # lvextend -L +50GB /dev/VolGroup01/fileserver.home 
      Extending logical volume fileserver.home to 300.00 GB
      Logical volume fileserver.home successfully resized
    
    # e2fsck -f /dev/VolGroup01/fileserver.home
    e2fsck 1.39 (29-May-2006)
    /dev/VolGroup01/fileserver.home: recovering journal
    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
    
    
    # resize2fs /dev/VolGroup01/fileserver.home 300G
    resize2fs 1.39 (29-May-2006)
    Resizing the filesystem on /dev/VolGroup01/fileserver.home to 78643200 (4k) blocks.
    The filesystem on /dev/VolGroup01/fileserver.home is now 78643200 blocks long.
    

    done!

    Chris S : Welcome to Server Fault. Please don't post "me too" or "thank you" type message on Server Fault. This site is for Questions and the associated Answers. If you have any new questions please use the Ask Question button in the upper right corner of every page.
    From Paul C

0 comments:

Post a Comment