Pages

Saturday, December 26, 2015

Vagrant – Custom Box

In the previous article we have seen how we can download a base Box from the internet and use that to configure new Virtuals but there will be cases where we need to clone a existing box and create new ones out of them. Vagrant provides options for closing a existing box for creating a new one.

1) Creating a new box from the existing one using ,

[root@vx111a CentOsVagrant]# vagrant package --base barhost --output centnew.box
==> barhost: Attempting graceful shutdown of VM...
    barhost: Guest communication could not be established! This is usually because
    barhost: SSH is not running, the authentication information was changed,
    barhost: or some other networking issue. Vagrant will force halt, if
    barhost: capable.
==> barhost: Forcing shutdown of VM...
==> barhost: Clearing any previously set forwarded ports...
==> barhost: Exporting VM...
==> barhost: Compressing package to: /work/CentOsVagrant/centnew.box

2) Once the new box is created with the name centnew.box, Copy this file to a new directory and add the box with name CentiOS

[root@vx111a vagrantTest]# vagrant box add CentiOS centnew.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'CentiOS' (v0) for provider:
    box: Unpacking necessary files from: file:///work/vagrantTest/centnew.box
==> box: Successfully added box 'CentiOS' (v0) for 'virtualbox'!

3) Once the box is added ,we can check that using the “vagrant box list” command
[root@vx111a vagrantTest]# vagrant box list
CentOS    (virtualbox, 0)
CentiOS   (virtualbox, 0)
mynewBox  (virtualbox, 0)
precise32 (virtualbox, 0)

4) Once the box is added successfully , use the “vagrant init” command and then make the necessary changes to the file for the new virtual to be configured.

[root@vx111a vagrantTest]# cat Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.box = "CentiOS"
  config.vm.host_name = "dev1.puppetlabs.vm"
config.vm.provider :virtualbox do |vb|
     vb.name = "foohost"
     vb.cpus = 2
end
end


5) From the same location, run the “vagrant up” for starting the virtual with the new box. Once started we can see the virtual available in the Oracle Virtual Box


No comments :

Post a Comment