Creating a new virtual machine in one minute or “vagrant up!”

    Vagrant
    Those who have previously encountered the creation of virtual machines imagine the process and can evaluate it in time. You need to create the virtual machine itself, specify the necessary parameters for it (size and type of disk, amount of RAM), then connect the installation disk with the operating system (be it a real optical drive or an ISO image), wait for the boot, start the installation, wait for it to complete , disconnect the installation disk and reboot. All this can take about 20 minutes - in some cases less, in some more, but still it's a lot of time. And if for some reason the virtual machine is deleted, then all this will have to be done again.

    Vagrant- a way to greatly simplify and speed up the creation of new virtual machines. Instead of the installation disc, a special box-file is used, which is automatically deployed to a new virtual environment. After that, ports can be redirected from the network interface of the virtual machine, the IP address can be allocated, the necessary software can be installed and configured. All this is indicated by the Vagrant settings, which are described in detail in the documentation .

    Vagrant runs on Linux, Mac OS X, Solaris, and Windows.


    To install Vagrant, you need the RubyGems package manager .

    You can install RubyGems like this.

    wget -c http://production.cf.rubygems.org/rubygems/rubygems-1.5.0.tgz
    tar xvzf rubygems-1.5.0.tgz
    cd rubygems-1.5.0
    sudo ruby ​​setup.rb
    sudo ln -s /usr/bin/gem1.8 / usr / bin / gem

    Update RubyGems. It is worth doing both after a fresh installation, and in case it has already been installed.

    sudo gem update --system

    Now install Vagrant. Here you should warn about the features of different versions . The fact is that branch 0.6 only supports VirtualBox 3.2, and the new branch 0.7 only supports VirtualBox 4.0, without backward compatibility.

    So, if you have VirtualBox 3.2:
    gem install --version '= 0.6.9' vagrant

    And if you have a new VirtualBox, then just put the latest version:
    gem install vagrant

    Now you need to download the box-file. Download Ubuntu 10.04 Lucid Lynx - 32 bits ,64 bits .

    And add this box file.

    vagrant box add lucid64 lucid64.box

    In principle, this command can accept a link to it instead of the path to the file, but I think it is safer to keep the box file at home.

    Now create a new directory for the Vagrant virtual environment and create the Vagrantfile settings file there.

    mkdir my_virtual_env
    cd my_virtual_env
    vagrant init

    Edit the Vagrantfile, replacing it
    config.vm.box = "base"
    with
    config.vm.box = "lucid64"

    By the way, if you plan to use only one box-file, you can simply add base (vagrant box add base lucid64.box) as its name. In this case, such editing of Vagrantfile is not required at all.

    Now run the virtual machine.

    vagrant up

    The first time it takes a little longer, since the virtual environment is deployed, and then it takes less time, because you just need to load the virtual machine.

    Now we can connect to the virtual machine.

    vagrant ssh

    If you need to execute commands on behalf of the superuser, sudo su is enough (no password is required).

    The status of virtual machines can be viewed using the vagrant status command.

    The virtual machine can be put on standby. In this case, the resumption of work occurs very quickly. To do this, use the vagrant suspend command (resume work - vagrant up).

    You can turn off the virtual machine using vagrant halt. And if the virtual machine is no longer required, then you can delete it (along with the disk) with the vagrant destroy command.

    This is enough to create new virtual machines and use them. Of course, there are many more possibilities, including the creation of your own box-files, as well as the automatic installation and configuration of software - and you can read about this in the project documentation.

    It's great that many things can be done faster and easier than before. And it’s great that you can do them in the way that is convenient and most like.

    Also popular now: