Skip to main content

Configuring Hyper-V Provider

1. Setting VM Name (hyperv.vmname)

Option Values Description
hyperv.vmname string Sets the name of the Hyper-V virtual machine. This is used to identify the VM in Hyper-V Manager and other tools.

Example: Setting VM Name

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hyperv|
    hyperv.vmname = "my-custom-vm"
  end
end

2. Configuring Memory (hyperv.memory)

Option Values Description
hyperv.memory 1024 Amount of memory (in MB) to allocate to the VM

Example: Setting Memory for Hyper-V VM

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hv|
    hv.memory = 2048
  end
end

3. Setting CPU Count (hyperv.cpus)

Option Values Description
hyperv.cpus 1 to 2048 Number of virtual CPUs to allocate to the VM. Defaults to 1.

Example: Setting CPU Count

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hyperv|
    hyperv.cpus = 4
  end
end

4. Enabling Dynamic Memory

Setting Description Default Value Notes
vm.memory Amount of memory allocated to the VM 512 MB Can be adjusted for performance needs
vm.dynamic_memory Enables or disables dynamic memory allocation false Set to true to enable dynamic memory

Example: Enabling Dynamic Memory in Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"

  # Enable dynamic memory
  config.vm.provider :hyperv do |hv|
    hv.memory = 1024
    hv.dynamic_memory = true
  end
end
Note: Dynamic memory requires Hyper-V to be installed and enabled on the host machine.
Warning: Enabling dynamic memory may impact performance if not configured properly.

5. Configuring MAC Address Spoofing

Option Values Description
config.hyperv.macaddress_spoofing true | false Enables or disables MAC address spoofing for the Hyper-V VM. Defaults to false.

Example: Enable MAC Address Spoofing

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hyperv|
    hyperv.macaddress_spoofing = true
  end
end
Note: Enabling MAC address spoofing can pose security risks in some environments. Only enable it if necessary for network configuration or testing.

6. Setting Differencing Disk

Option Values Notes
config.vm.synced_folder "source", "destination", type: "virtualbox" Specify the synced folder type for Hyper-V
config.vm.provider "hyperv" Set the provider to Hyper-V

Example: Configure Differencing Disk

Vagrant.configure("2") do |config|
  config.vm.provider "hyperv" do |hyperv|
    hyperv.differencing_disk = true
  end
end
Note: Differencing disks are supported in Hyper-V and can help reduce disk space usage by sharing a base disk.

7. Configuring VM Integration Services

Service Description Status Configuration
VM Integration Services Enables communication between host and guest OS NEW Enabled by default in Hyper-V
Time Synchronization Keeps guest time in sync with host NEW Enabled via vagrant-hyperv plugin
Guest Services Allows guest OS to report status and metrics DEPRECATED Removed in Vagrant 2.3.0+

Example: Enabling Integration Services

vagrant plugin install vagrant-hyperv
Note: Integration services must be enabled in Hyper-V Manager for Vagrant to function properly.
Warning: Disabling integration services may cause Vagrant to fail during provisioning.

8. Using External Virtual Switch (hyperv.vswitch)

Option Values Description
hyperv.vswitch string Name of the external virtual switch to use for networking

Example: Configuring External Virtual Switch

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hyperv|
    hyperv.vswitch = "External Switch"
  end
end
Note: The virtual switch must already exist in Hyper-V Manager.

9. Setting Automatic Checkpoints

Option Values Description
checkpoint true / false Enables or disables automatic checkpoints for Hyper-V VMs
checkpoint.interval 300 (seconds) Interval in seconds between automatic checkpoints

Example: Enable Automatic Checkpoints

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hyperv|
    hyperv.checkpoint = true
    hyperv.checkpoint_interval = 600
  end
end
Note: Automatic checkpoints are only available in Windows 10 Pro and Windows Server 2016 or later.

10. Configuring Secure Boot

Option Values Notes
config.hyperv.secure_boot true | false Enables or disables Secure Boot for the Hyper-V VM. Defaults to false.

Example: Enabling Secure Boot

Vagrant.configure("2") do |config|
  config.vm.provider :hyperv do |hyperv|
    hyperv.secure_boot = true
  end
end
Note: Secure Boot requires UEFI firmware support. Ensure the base box supports UEFI and has appropriate firmware installed.

Was this article helpful?