Ganeti Import from VMDK

 

1 Importing a VMDK

Using Monitor as the VM in ESXi

Stop the Monitor Virtual Machine from the VMWare ESXi Interface

Login to the the VMWare ESXi server via SSH (Assumes it allows SSH connections)

Locate the directory where the Image files reside, normally under /vmfs/volumes/datastore1/Monitor/

Copy the .vmdk file from ESXi to the Ganeti Server

Ganeti# mkdir Monitor

Ganeti# cd Monitor

Ganeti# scp -r root@ESXi:/vmfs/volumes/datastore1/Monitor/* .

1.1 Examine the file

Have a look at the file you’re going to use:

Ganeti# ls -l Monitor-flat.vmdk
-rw------- 1 root root 53687091200 Mar 18 11:38 Monitor-flat.vmdk

That doesn’t tell us much, because a VMDK file is an image which grows as it is used. What you need to know is the size of the disk drive which is being emulated, and you can find this out using qemu-img info

Ganeti# qemu-img info Monitor-flat.vmdkimage: Monitor-flat.vmdk
file format: raw
virtual size: 50G (53687091200 bytes)
disk size: 50G
(Note that this is using Gibibytes, where 1GiB = 1024^3 bytes)

Let’s just check this is exactly 1GiB, using a calculator program bc:

Ganeti# bc
50*1024*1024*1024
53687091200
(ctrl-D to exit)

Yes, that matches exactly.

1.2 Create Logical Volume

Now create a logical volume of exactly that size.

Ganeti# lvcreate --size 50G --name mon xenvg

Type lvs to see that your logical volume is present. Also check that a new block device has been created under /dev/xenvg

Ganeti# ls -l /dev/xenvg/mon
lrwxrwxrwx 1 root root 8 Mar 18 10:50 /dev/xenvg/mon -> ../dm-16

1.3 Convert the image

Now unpack the VMDK and write it to this volume:

Ganeti# qemu-img convert -O raw Monitor-flat.vmdk /dev/xenvg/mon
  • -O raw says the format you want the output to be written in (just a raw stream of blocks)
  • The next parameter is the input you are reading
  • The final parameter is where you want to write the output

This will take a few minutes.

2 Create VM

Now login to the cluster MASTER node.

You will create an instance and tell Ganeti to adopt the logical volume you have created.

Mstr# gnt-instance add -t plain -o image+default\
   -n quin1.renu.ac.ug --disk 0:adopt=mon\
   -B memory=2048M --no-name-check --no-ip-check\
    --no-start -H kvm:vnc_bind_address=0.0.0.0\
mon.renu.ac.ug\

The -n flag gives the node where you created the logical volume.

This will take over the given logical volume and rename it to the Ganeti standard (UUID-based), without running any OS installation.

2.1 Start the VM

The server can now be attached to the internal network on the br-svc bridge.

Mstr# gnt-instance modify --net 0:modify,link=br-svc mon.renu.ac.ug

Once this is done, you can start the VM as normal.

Mstr# gnt-instance start mon.renu.ac.ug

The network settings may change based on the addition of the new NIC hardware.

You can login using either the VNC console or the serial console – by now you should know how to do this.

VM# rm -rf /etc/udev/rules.d/70-persistent-net.rules && reboot #(CentOS only)

Configure the new interface (normally eth0) with the correct IP details. The MAC address and the interface  can be picked from the updated /etc/udev/rules.d/70-persistent-net.rules file

3.1 Conversion to DRBD

Once you have created a “plain” disk image, it’s straightforward to convert it to “drbd” so that you have a resilient service and can live-migrate it back and forth. Shut it down, and then do:

Mstr# gnt-instance modify -t drbd -n Secondary-Ganeti mon.renu.ac.ug

Check which are the primary and secondary nodes using:

Mstr# gnt-instance list -o name,pnode,snodes,network_port mon.renu.ac.ug

Then you can start it again. When it’s running, live-migrate it using

Mstr# gnt-instance migrate mon.renu.ac.ug

You should then find that the primary and secondary nodes have swapped.

Reference

https://nsrc.org/workshops/2015/sanog25-virtualization/raw-attachment/wiki/Track2Agenda/ex-ganeti-instance-vmdk.htm

https://nsrc.org/workshops/2014/bdnog1/raw-attachment/wiki/Track3Agenda/ex-ganeti-instance-vmdk.htm

http://www.area536.com/projects/freebsd-as-a-kvm-guest-using-virtio/

http://www.cyberciti.biz/tips/freebsd-how-to-start-restart-stop-network-service.html