Essays.club - Get Free Essays and Term Papers
Search

Building Vagrant for Hyper-V

Autor:   •  November 21, 2018  •  1,265 Words (6 Pages)  •  438 Views

Page 1 of 6

...

Save the changes and now we restart the OPENSSH Server with the following

Sudo systemctl restart ssh

Which restarts our service for us.

Creating the BOX file

Now we have our base image we need to package it up for windows but before we do that we need to “zero out” the drivw, which fixes fragmentation issues with the underlying disk, which helps when our box is compressed.

Creating the package

We now need to shutdown the image so we can first export it from Hyper V and then compress it for packaging

Go ahead and shutdown the server with the following

Sudo shutdown now

In the Hyper-V Manager, select the base image and from the context menu select “Export” and pick a location for the image.

This will create a folder with the following folders

[pic 1]

In this folder create a “metadata.json” file and remove the Snapshots folder.

The “metadata.json” file should contain at the very least the following

{

"provider": "hyperv"

}

You should now have a folder with the following

[pic 2]

I have used PeaZip to help with this bit, select the folders and the metadata.json file and then create a tar.gz file.

Once this has completed, rename the tar.gz file to a .box file by changing the file extension

Important!: the file and folders need to be top level as Vagrant will fail if they are in a sub folder.

Testing the BOX file

Now we have created the image, configured the server and now packaged it all up, we can now test our image has worked.

We need to add our box to the current list of boxes available in our Vagrant BOXES repo, we do that with the following command

vagrant box add hyperv-ubuntu64.box –name hyperv-ubuntu64

We can now test our vagrant image. First create a test folder change into that folder and then and Vagrant Initialise it using the following command

vagrant init

This will create a file called Vagrantffile that you will need to be edited so we can use it with Hyper-V. Open the Vagrantfile file and locate the following lines

config.vm.box = “base”

Replace “base” with name you gave your box when you added it to vagrant, in our case using the -name above we have

config.vm.box = “hyperv-ubuntu64”

Locate the following

# config.vm.provider "virtualbox" do |vb|

Replace it with the following

config.vm.provider "hyperv" do |hyp|

hyp.vmname =

hyp.memory =

hyp.maxmemory =

end

And now we are fit to test using Vagrant with the following

Vagrant up

During this provisioning stage Vagrant does not know how to create and configure new networks for HyperV so Vagrant will prompt you to select the network you wish to use.

[pic 3]

You will also be prompted to enter a Windows User name and password that will be used to set up an SMB share within the Vagrant box.

[pic 4]

If you open HyperV you should now see your image, if you select it and go to the Networking tab you should be able to see the IP address of the Instance and assuming everything has worked you should now be able to connect with your favourite ssh client.

...

Download:   txt (8.1 Kb)   pdf (55.4 Kb)   docx (16.8 Kb)  
Continue for 5 more pages »
Only available on Essays.club