Create Vagrant box for libvirt provider

665 views
Skip to first unread message

Beckett

unread,
Apr 30, 2015, 8:58:14 AM4/30/15
to vagra...@googlegroups.com
Greetings everyone. Could someone explain me how can I package running VM managed by libvirt with KVM driver into a box so anyone who gets it won't have to create & provision it from scratch? The question of packaging a box for virtualbox provider is well covered in the documentation, but libvirt makes it quite tricky. Thank you in advance.

Alvaro Miranda Aguilera

unread,
May 1, 2015, 3:48:51 AM5/1/15
to vagra...@googlegroups.com
Hello

I would suggest to add this box and try it

if works, then see that's in the box:

https://atlas.hashicorp.com/detain/boxes/ubuntu-14.04-x86_64
> --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Алексей Усов

unread,
May 1, 2015, 7:31:18 AM5/1/15
to vagra...@googlegroups.com
Thanks for the reply.

That's the thing - I use libvirt for managing KVM VM. Is there no difference?

You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/6ig02OJnhLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
С уважением, Усов А.Е..
Best Regards, Usov A.Y..

Alvaro Miranda Aguilera

unread,
May 1, 2015, 4:46:43 PM5/1/15
to vagra...@googlegroups.com
Hello,

That box is KVM so I think it use libvirt?

Ok, the other link seems was bad..

so there is this box

https://vagrant-kvm-boxes-si.s3.amazonaws.com/trusty64-kvm-20140418.box

So, I downloaded and then extracted

x ./box.xml
x ./Vagrantfile
x ./metadata.json
x ./box-disk1.img


cat metadata.json

{"provider":"kvm"}


cat Vagrantfile

Vagrant.configure("2") do |config|
config.vm.base_mac = '080027A24479'
end


cat box.xml | gist

https://gist.github.com/a190193a9b2f3b4db64f


Alvaro

Алексей Усов

unread,
May 1, 2015, 5:22:27 PM5/1/15
to vagra...@googlegroups.com
Well, I'll give it a try, but VMs managed by libvirt use libvirt provider, not kvm.

Алексей Усов

unread,
May 1, 2015, 5:36:41 PM5/1/15
to vagra...@googlegroups.com
Also, my question is more about how to pack an existing VM into a box, rather than finding a base box to begin with. I'd much rather not to rely on boxes packed by other people - seems insecure to me. To start with, I can download virtualbox box and then use Vagrant mutate plugin to convert it into kvm box with libvirt provider. Once it's done, I can provision that box with all software I need, but I can't package that VM into a new kvm box with the same libvirt provider. I tried tar'ing .img file from /var/lib/libvirt/images, metadata.json, and my Vagrantfile into a new .box file, but when I try to add it to Vagrant to check if it contains everything I installed into it, it says that metadata may be corrupted. Official Vagrant docs say that I have to create box manually for any provider other than virtual box, but I couldn't find any info on how to do it properly.

Алексей Усов

unread,
May 6, 2015, 8:35:24 AM5/6/15
to vagra...@googlegroups.com
In case anyone is interested, that is how it's done:

virt-sparsify --machine-readable input.img --convert qcow2 box.img

or

qemu-img convert -O qcow2 imput.img box.img

Then you're going to have to create minimal metadata.json and Vagrantfile, containing following:

Vagrant.configure(2) do |config|
config.vm.provider :libvirt do |libvirt|
end
end

Finally, put these 3 files into tarball:

tar cvf <box_name.box> Vagrantfile box.img metadata.json

Resulting box is ready to be added to vagrant and used to bring the VM up:

vagrant
vagrant box add <arbitrary_box_name> <box_name.box>
vagrant init --minimal arbitrary_box_name
vagrant up

Source

Reply all
Reply to author
Forward
0 new messages