[GLLUG] Does any virtualisation system provide good support for USB device forwarding?

Andy Smith andy at bitfolk.com
Tue Apr 8 16:20:16 UTC 2014


Hi John,

On Tue, Apr 08, 2014 at 05:02:36PM +0100, John Winters wrote:
> There are lots of HOWTOs on the net about how to migrate existing VMs
> from Xen to KVM, but they all run up against a fundamental difference
> in how the two do disk allocation.  Xen expects to have several
> devices - one for swap, and one for each mountable partition - whilst
> KVM expects to be passed a whole disk (albeit not a real one) which
> it then partitions for swap, boot etc.  Any kind of conversion will
> therefore be a messy compromise.

It's not a difficult conversion to make.

Xen works fine with being passed a whole disk, so if you have enough
disk space for an intermediate copy you can always go from something
like:

/dev/vg00/vm0_root  → /
/dev/vg00/vm0_swap  → swap
/dev/vg00/vm0_var   → /var

to:

/dev/vg00/vm0_xvda  → /dev/xvda

where /dev/vg00/vm0_xvda is then treated like a whole disk and
partitioned into three separate partitions, one for each of /, swap
and /var.

You may find that this is a hassle for later resizing of filesystems
so one trick I often use is to in fact use three separate disks each
with only a single partition on them.

/dev/vg00/vm0_xvda contains single partition xvda1 I will use as / in the VM.
/dev/vg00/vm0_xvdb contains single partition xvdb1 I will use as swap in the VM.
/dev/vg00/vm0_xvdc contains single partition xvdc1 I will use as /var in the VM.

and so on. Then if any of them later needs to be resized I can
resize the disk and partition without worrying about there being
other partitions in the way.

You can use fdisk on an LVM logical volume to treat it like a disk
and partition it from outside the VM if you like:

# fdisk -u /dev/vg00/vm0_xvda

Also "kpartx" can be very useful for manipulating partitions on a
disk image from the host machine¹ - despite the name this is neither
an X GUI app nor a KDE component.

# kpartx -va /dev/vg00/vm0_xvda
# mkfs.xfs /dev/mapper/vg00-vm0_xvda1
# kpartx -vd /dev/vg00/vm0_xvda

I've been using whole disks like this with Xen and KVM to ease
portability for some years now.

Cheers,
Andy

¹ Do be aware that manipulating untrusted filesystems can be
  hazardous; the kernel has not been tested so much against problems
  mounting, fscking etc filesystems and it's conceivable that
  someone could craft a filesystem that is broken in some way that
  crashes your host if you mounted it.

-- 
http://bitfolk.com/ -- No-nonsense VPS hosting




More information about the GLLUG mailing list