Here is how I did it manually for servers in production. Be aware that
while it should work, there is no guaranty and you must make you own
tests.
I have in mind to write something for the official docs but I still have
to get support from my managers. I assume DRBD target disk in Ganeti but
you can do something somewhat similar for LVM.
Conversion from raw disk (libvirt or physical disk) to DRBD in Ganeti
=====================================================================
This method is POTENTIALLY VERY HARMFUL. Make sure to understand the
whole documentation before proceeding.
First, install whatever driver in the VM you might need due to the
conversion (refer to the Ganeti doc to know what kvm/xen drivers are
necessary).
Then, convert your libvirt (created with virt-manager) disk images to
raw format:
# qemu-img convert disk-libvirt.img -O raw disk-libvirt.raw
Then, get the virtual size of the disk in bytes:
# qemu-img info disk-libvirt.raw
image: disk.img
file format: qcow2
virtual size: 29G (31457280000 bytes)
disk size: 5.9G
cluster_size: 65536
#
Here is a disk of 31457280000 bytes. You can check the value with fdisk
# fdisk- l disk.raw
Disk disk.raw: 31.5 GB, 31457280000 bytes
255 heads, 63 sectors/track, 3824 cylinders, total 61440000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007053b
Device Boot Start End Blocks Id System
disk.raw1 * 2048 61437951 30717952 83 Linux
#
reporting the same 31457280000 bytes.
Next, you create the Ganeti VM. The disk size must exactly match.
Convert the bytes into mebibytes. In this case:
31457280000 bytes / 1024 / 1024 = 30000 mebibyte (which is NOT 30 Giga Bytes)
So, when creating the Ganeti instance, give this calculated value to the
disk option size:
--disk 0:size=30000m
Wait until the VM is fully created (DRBD is synchronized). Get the DRBD
file device name with:
# gnt-instance info my.inst
<...>
Disk template: drbd
Disks:
- disk/0: drbd8, size 29.3G
access mode: rw
nodeA: radium.piing.lan, minor=6
nodeB: hafnium.piing.lan, minor=6
port: 11011
auth key: 37228a75a8579acaefee5586f4ca10eba95a13ef
on primary: /dev/drbd6 (147:6) in sync, status ok
on secondary: /dev/drbd6 (147:6) in sync, status ok
<...>
Here, we want /dev/drbd6. BE CARE this is the correct instance and
correct file device to not erase other data.
Active the disks:
# gnt-instance activate-disks my.inst
Check the target has the exact same size as the source:
# fdisk -l /dev/drbd6
Disk /dev/drbd6: 31.5 GB, 31457280000 bytes
255 heads, 63 sectors/track, 3824 cylinders, total 61440000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/drbd6 doesn't contain a valid partition table
#
In this sample, the 31457280000 bytes is what we expect.
Copy the disk with dd
# dd if=disk-libvirt.raw of=/dev/drbd6
Finally, deactivate the disks of the ganeti instance
# gnt-instance deactivate-disks my.inst
You should be able to start and use the Ganeti VM. If not, please report
it here to give me a chance to improve this "mini how-to".
--
Nicolas Sebrecht