linux - Resizing Xen guests using LVM

24
2014-04
  • z0mbix

    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

  • Answers
  • Aleksandar Ivanisevic

    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

  • womble

    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.

  • Chris S

    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.


  • Related Question

    How can I resize a regular (non-LVM) partition?
  • Questioner

    Sorry for my poor English, I hope you will understand me.

    A month ago I set up a Ubuntu server with a 500GB HDD, while installing the system I created regular, non-LVM, partitions - here's their layout.

    root@skysquad:~# fdisk -l
    
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x000c9f61
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1       10942    87891583+  83  Linux
    /dev/sda2           10943       60801   400492417+   5  Extended
    /dev/sda5           12159       60801   390724866   83  Linux
    /dev/sda6           10943       12158     9767457   82  Linux swap / Solaris
    
    Partition table entries are not in disk order
    

    Basically it's;

    sda1 (90GB) for OS (ext4)
    sda5 (~370GB) for /home (I will explain later) (ext4)
    sda6 (10GB) for SWAP

    Later I realised that when sda5 (385GB for /home) will be full I would like to increase its size by adding a new HDD, so I made sda5 an LVM partition like so;

    root@skysquad:~# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda5
      VG Name               vg1
      PV Size               372.62 GB / not usable 3.25 MB
      Allocatable           yes (but full)
      PE Size (KByte)       4096
      Total PE              95391
      Free PE               0
      Allocated PE          95391
      PV UUID               lewQnp-NdvK-Ac0N-sCgE-NGOH-K2cX-WxJ2tL
    
    root@skysquad:~# vgdisplay
      --- Volume group ---
      VG Name               vg1
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               372.62 GB
      PE Size               4.00 MB
      Total PE              95391
      Alloc PE / Size       95391 / 372.62 GB
      Free  PE / Size       0 / 0
      VG UUID               yRkcP7-zvZ0-DjIR-xDWS-Ia6V-InSu-6Hwvpe
    
    root@skysquad:~# lvdisplay
      --- Logical volume ---
      LV Name                /dev/vg1/home
      VG Name                vg1
      LV UUID                jXCi37-iWmp-xVd7-9TsL-56pg-6x9m-73flLT
      LV Write Access        read/write
      LV Status              available
      # open                 1
      LV Size                372.62 GB
      Current LE             95391
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           252:0
    

    Now my sda5 (LVM) is full (see below), but my wallet is not, and I can't just buy another HDD.

    root@skysquad:~# df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/sda1             86511612   3829536  78287500   5% /
    tmpfs                  1677788         0   1677788   0% /lib/init/rw
    varrun                 1677788       520   1677268   1% /var/run
    varlock                1677788         0   1677788   0% /var/lock
    udev                   1677788       144   1677644   1% /dev
    tmpfs                  1677788        84   1677704   1% /dev/shm
    lrm                    1677788      2192   1675596   1% /lib/modules/2.6.28-15-generic/volatile
    /dev/mapper/vg1-home 384590900 332537772  32517052  92% /home
    

    As you can see I'm only using 5% of / (sda1) (I don't know what I had in mind when I was setting 90GB for /).

    So finally my question - is there any SAFE way to resize non-LVM partitions (i.e. decrease sda1 size by 60GB, from 90GB to 30GB, and increase sda5 with this 60GB from ~370GB to ~430GB) and then increase LVM at sda5 with those 60GB?

    Thank you,
    Lulaz


  • Related Answers
  • womble

    In theory, you could reduce the size of sda1, increase the size of the extended partition, shift the contents of the extended partition down, then increase the size of the PV on the extended partition and you'd have the extra room. However, the number of possible things that can go wrong there is just astronomical, so I'd recommend either buying a second hard drive (and possibly transferring everything onto it in a more sensible layout, then repartitioning your current drive better) or just making some bind mounts of various bits and pieces out of /home into / to free up a bit more space.

  • pboin

    Easy shortcut:

    If you're root on the box, and it seems like you are, build a directory on '/', which is sda1. For this example, let's call it '/data/overflow'. Then in your home directory, take some directory that's excessively large, move the data to /data/overflow, and use a symbolic link to point to it.

    Sample commands:

    # make directory on empty partition
    mkdir -p /data/overflow
    chown username /data/overflow
    
    # move data to empty disk
    cd /home/username
    mv bigdir /data/overflow
    
    # put the link in, so your old names match
    ln -s /data/overflow/bigdir bigdir
    
  • bmaupin

    GParted Live will let you resize non-LVM partitions, theoretically without losing data, but 1. you wouldn't be able to use your server during this time and 2. like womble said, it's highly likely something could go wrong.