Open Source and Linux Lab

Главная » Uncategorized » Quick way to create Vagrant libvirt box from existing one

Quick way to create Vagrant libvirt box from existing one


This article is aimed to describe very fast approach of creating Vagrant Libvirt boxes using existing ones as a base. The described solution is applicable for following use-cases:

  • you need box with slightly different software dependencies (different packages/versions);
  • you need different configuration of existing software;
  • you need add some files to box.

Due to described process simplicity it has one big limitation — ssh password of vagrant use is hard-coded. This means that every box user will need to set it explicitly in Vagrantfile. Such solution may be inflexible for a number of use-cases and obviously contain security vulnerability.

Described approach target is only to modify existing box quickly and it does not cover deep libvirt configuration issues. For more complex boxes it is better to use


  1. Clone .
  2. Ensure that you have enough free space on the host machine, you may need atleast three or a four times more space that <needed_box_name> file takes.
  3. Do vagrant box add <needed_box_name>.

Creating box

Write Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config| = "<needed_box_name>"
  config.vm.synced_folder "./", "/vagrant", type: "rsync", rsync__auto: true
  config.vm.provider "libvirt" do |libvirt|
     libvirt.driver = "qemu"
 config.vm.provision "shell", inline: <<-EOC
    # Important part - hardcoding vagrant password which will allow us to connect to new   box without messing with keys
    echo "vagrant\nvagrant"| passwd vagrant
    # Do needed environment settings
    sudo aptitude install ruby gcc make 

Start VM

  1. Call vagrant up —provider=libvirt .
  2. Wait for virtual machine to complete provision.
  3. Copy any files to machine or do any other manual actions which should persist in new box.

Package box


cd <vagrant_libvirt_dir>
sudo tools/ /var/lib/libvirt/images/<needed_box_name>.img

(If you have troubles finding .img file, corresponding to running VM use virsh -q vol-list —pool default command to list all libvirt images. )

After successful ending of the last command the box file will appear at ./<needed_box_name>.box. This file can be added localy to vagrant by running:

vagrant box add ./ --name <name_of_new_box>

or can be uploaded to Atlas(



Добавить комментарий

Заполните поля или щелкните по значку, чтобы оставить свой комментарий:


Для комментария используется ваша учётная запись Выход /  Изменить )

Фотография Twitter

Для комментария используется ваша учётная запись Twitter. Выход /  Изменить )

Фотография Facebook

Для комментария используется ваша учётная запись Facebook. Выход /  Изменить )

Connecting to %s

%d такие блоггеры, как: