Many have probably heard about the utility to automate the creation of
vagrant virtual machines.
Following the instructions from off.sayta you can get a working virtual machine by executing only 3 commands.
vagrant box add lucid32 http://files.vagrantup.com/lucid32.box vagrant init lucid32 vagrant up
')
In this case, vagrant will download the box from the site and create a virtual machine based on it. Box is a tar archive with a virtual machine and additional configuration. Also, on the site
www.vagrantbox.es there are a bunch of pre-installed boxes.
But there may be situations when you need to create your box, and create virtuals based on it. The vagrant website
describes the process of creating a box. In this article, I would like to show how to automate this part using the
veewee utility.
I’ll just say that I’m not familiar with ruby, so if you think that there is an easier way to set up a ruby environment, I’ll be glad to have constructive suggestions in the comments.
For example, let's take Ubuntu 12.04 as a working OS, and select CentOS 6 for the virtual environment.
The settings for vagrant will be stored in the vagrant, veewee directory, respectively, in the veewee directory.
The first problem I encountered was: veewee refused to work with the version of ruby, which was installed from the Ubuntu repository.
I had to remove ruby-rvm from the OS, and install a more recent version, in more detail
here in English:
sudo apt-get --purge remove ruby-rvm sudo rm -rf /usr/share/ruby-rvm /etc/rvmrc /etc/profile.d/rvm.sh curl -L https://get.rvm.io | bash -s stable --ruby --autolibs=enable --auto-dotfiles
Next, install ruby, and several dependencies:
source ~/.rvm/scripts/rvm sudo apt-get install libxslt-dev libxml2-dev rvm install ruby-1.9.2-p320
When installing ruby, rvm tried to download the distribution kit at:
ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p320.tar.bz2 and received 404 in response. If you have the same problem, open the file ~ / .rvm / config / db, find the line ruby_1.9_url and replace http: // with ftp: //, then try installing ruby again.
Now go directly to the creation of the box. Create the necessary directories:
mkdir {vagrant,veewee}
Download the current version of veewee:
cd veewee git clone https://github.com/jedi4ever/veewee . bundle install
veewee contains templates for most popular OS versions, including Windows:
bundle exec veewee vbox templates | grep -i centos-6.4
Create an OS configuration file based on the selected template. Let's call our OS 'centos6-x86_64-minimal'. Accordingly, the veewee template for CentOS 6 is set to 'CentOS-6.4-x86_64-minimal':
bundle exec veewee vbox define 'centos6-x86_64-minimal' 'CentOS-6.4-x86_64-minimal'
In the 'definitions / centos6-x86_64-minimal / definition.rb' file, you can specify various settings for the virtual machine, for example, memory size, disk size, etc.
Create a virtual machine for Virtual Box:
bundle exec veewee vbox build 'centos6-x86_64-minimal' --workdir=.
If you have a CentOS-6.4-x86_64-minimal.iso pre-downloaded distribution, you can copy it to the iso directory in the current directory. You can also copy VBoxGuestAdditions.iso for your version of VirtualBox. If veewee does not find the iso image of the installed OC, the utility will offer to download it during the creation of the virtual machine.
Veewee will create a virtual machine, which will also be available through the Virtual Box GUI. If desired, you can install the necessary software, configure the OS, and so on, before creating a vagrant box based on it. This can be done manually or automated. Veewee supports post installation scripts - a set of commands that will be executed in a virtual machine immediately after its installation.
Also, veewee will create port 22 redirection in the virtual machine to port 7222 in the main OS.
Now you can create a vagrant box:
bundle exec bundle exec veewee vbox export 'centos6-x86_64-minimal'
The file 'centos6-x86_64-minimal.box' will be created in the current directory.
Add a new box to vagrant:
vagrant box add 'centos6-x86_64-minimal' centos6-x86_64-minimal.box
We can remove the 'centos6-x86_64-minimal.box' from the current directory.
Now we can create virtual machines based on the newly created box:
cd ../vagrant mkdir centos6-x86_64-minimal cd centos6-x86_64-minimal vagrant init 'centos6-x86_64-minimal' vagrant up vagrant ssh
If you need to change the settings of the box, there is nothing easier than deleting the current box, setting up a virtual machine and rebuilding the box using veewee.
Example Vagrantfile for virtual OS.
I intentionally specified vm1 in the config. Thus, it is possible to start several virtual machines with different parameters from the same box. This is called multivm and is described
here .
Thanks for attention.