[CentOS-virt] kvm guest from zfs dataset

Thu Jan 22 16:02:14 UTC 2015
Bill McGonigle <bill at bfccomputing.com>

On 01/15/2015 07:47 PM, aurfalien wrote:
> 
> I’m trying to run a KVM based guest OS off of a mirrored ZFS dataset.
> 
> It won’t run with errors "invalid argument..", but will run when on the
> root volume, or when that ZFS dataset has been removed in favor of an
> EXT4 volumes.

KVM works fine on ZFS block devices.  I haven't tried running an image
file off of one (zvols are more appropriate to task).

Try (approximately, from memory):

 zfs create pool/machine
 zfs create -V 2G pool/machine/boot
 zfs create -V 64G pool/machine/root
 etc.

and in KVM, define the disks as physical devices:
 /dev/zvol/pool/machine/boot
and
 /dev/zvol/pool/machine/root
 (etc.)

I usually partition each 'disk' from within the VM, but you could
pre-partition from the host.  I like boot-part1 as ext3, for ultimate
portability back to older virtualization software (and it's just
'/boot', so who cares) on the off chance I have to move the VM at some
point.

If you're going to compress, do
  zfs set compress=lz4 pool/machine

for better performance (need a new-ish ZoL with feature-flags for this).

Setup zfs-auto-snapshot with --fast in the cron jobs for best performance.

If you're using whole-disk encryption, do those on the disks _before_
they're added to the pool.  I've been bitten by trying to encrypt on top
of the ZFS mirror before.  Put them in crypttab and you'll be all set at
boot time.  On newer Fedora-derived OS'es you'll need to 'systemctl
enable zfs.target' to get the ordering right.

-Bill

-- 
Bill McGonigle, Owner
BFC Computing, LLC
http://bfccomputing.com/
Telephone: +1.855.SW.LIBRE
Email, IM, VOIP: bill at bfccomputing.com
VCard: http://bfccomputing.com/vcard/bill.vcf
Social networks: bill_mcgonigle/bill.mcgonigle