How to: Make SuseStudio Xen Appliance to use Dom0 LVM

Hi,

Requirement:
To convert Xen Appliance build by SuseStudio to use Dom 0 LVM (in order to have a flexible disk)

Solution:

  1. Create a Xen base JeOS appliance with SuseStudio.(Give about 2GB Disk)
  2. Download and extract
  3. Prepare the loop back and mount the partition (If you go for JeOS with minimal, you will have only one disk file (.raw) which is corresponding to /dev/xvda and have one partition where the root (/) is mounted on i.e. /dev/xvda1 → / (ext3) )
losetup -a

losetup -a  will show all the used loop back devices, 
so pick something that is not in use. 
i.e. check ls -l /dev/loop* --> e.g /dev/loop3

losetup /dev/loop3 /path/to/VMFilename.raw 

Use kpartx to map the partitions

kpartx -l /dev/loop3
This will show the partition mapping to be added by -a option

kpartx -a /dev/loop3
You can also put -v so that it'll display the map

Lets mount the partition now (assume the map is loop3p1 → /dev/mapper/loop3p1)


mkdir /mnt/old_root
mount /dev/mapper/loop3p1 /mnt/old_root

  1. Prepare the LVM and mount
    Lets assume this
    PV → sda (100GB)

VG → VolGroupVM ← for VM
using sda (100GB)

LV → LogVolMyXen00 (2GB) on VolGroupVM

Some of the code may not apply for everyone, pick what you need,


pvcreate /dev/sda
vgcreate VolGroupVM /dev/sda
lvcreate --size 2G --name LogVolMyXen00 VolGroupVM

now, format 
mke2fs -j /dev/VolGroupVM/LogVolMyXen00

and mount,
mkdir /mnt/new_root
mount /dev/VolGroupVM/LogVolMyXen00 /mnt/new_root

  1. Copy the files from old to new

rsync -ax /mnt/old_root/* /mnt/new_root/.

and then unmount 
umount /mnt/old_root
umount /mnt/new_root

add -v if you like a nice text screensaver lol!

  1. Edit the JeOSName.xenconfig file
    change

disk= "tap:aio:JeOSName.raw,xvda,w" ]

to


disk= "phy:/dev/VolGroupVM/LogVolMyXen00,xvda1,w" ]

NOTE:

  • The tap:aio to phy

  • xvda to xvda1 (no more whole device will be using the partition directly)

  1. Resize LVM

lvextend --size +1G /dev/VolGroupVM/LogVolMyXen00

  1. Only downside is you still see as 2G in side VM not as 3G, so you have to restart the VM
  2. Once it’s VM is restarted you can resize by (log to VM first)

resize2fs /dev/xvda1

NOTE:

  1. Don’t forget to clean up

kpartx -d /dev/loop3
losetup -d /dev/loop3

I'm happy to contribute to opensuse community in anyway I can. I'm very new to opensuse and this is my first post, appreciate your help to improve this. :)

Thanks,
With Best Regards,
Janaka