vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

hyperv: Primary disk gets removed after restart

Open xrow opened this issue 1 year ago • 2 comments

Debug output

https://gist.github.com/xrow/bafbd159bb33a1b1c7d3a0984fc665ca

Expected behavior

Disk will not get removed, after restart.

Actual behavior

After a restart (vagrant up; vagrant halt; vagrant up;) the hyperv disk gets removed from the vm spec and the vhd this remove dfrom the directory (.vagrant\machines\centos\hyperv\Virtual Hard Disks).

Reproduction information

vagrant up; vagrant halt; vagrant up;

Vagrant version

PS C:\scm\vagrant> vagrant -v Vagrant 2.4.1

Host operating system

Windows 11

Guest operating system

Centos Stream 9

Steps to reproduce

  1. vagrant up
  2. vagrant halt
  3. vagrant up

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 2.4.1", "<=3.0"

Vagrant.configure("2") do |config|
    config.vm.provider :hyperv
    config.vm.synced_folder ".", "/vagrant", disabled: false, type: "rsync"
    config.vm.box_check_update = true

    config.ssh.insert_key = false
    # config.ssh.username = "vagrant"
    # config.ssh.password = "vagrant"

    config.vm.network :forwarded_port, guest: 3389, host: 3389, auto_correct: true
    config.vm.provider "hyperv" do |h|
      h.auto_start_action = 'Start'
      h.vmname = 'centos'
      h.memory = 6000
      h.maxmemory = 10000
      h.enable_virtualization_extensions = true
      h.enable_enhanced_session_mode = true
      h.vm_integration_services = {
        guest_service_interface: true,
        time_synchronization: true,
        CustomVMSRV: true
      }
    end
    config.vm.define "centos", primary: true do |centos|
        centos.vm.box = "generic/centos9s"
        centos.vm.network :private_network, ip: "192.168.222.2", bridge: "Default Switch"
        centos.vm.disk :disk, size: "150GB", primary: true
        
        centos.vm.network :forwarded_port, guest: 22, host: 2200, id: "ssh"
        if not ENV['USERPROFILE'].to_s.empty?
          centos.vm.provision "file", source: "#{ENV['USERPROFILE']}\\.kube\\config", destination: "/tmp/config"
          centos.vm.provision "file", source: "#{ENV['USERPROFILE']}\\.ssh\\id_ed25519", destination: "/tmp/id_ed25519"
        end
        centos.vm.provision :shell, :inline =>  "/vagrant/provision/install.sh", env: {"FULLNAME" => ENV['FULLNAME'], "EMAIL" => ENV['EMAIL']}
    end

    config.vm.define "rhel", autostart: false do |rhel|
        rhel.vm.box = "generic/rhel9"
        rhel.vm.network :private_network, ip: "192.168.222.3", bridge: "Default Switch"
        rhel.vm.disk :disk, size: "150GB", primary: true
        rhel.vm.network :forwarded_port, guest: 22, host: 2300, id: "ssh"
        if not ENV['USERPROFILE'].to_s.empty?
          rhel.vm.provision "file", source: "#{ENV['USERPROFILE']}\\.kube\\config", destination: "/tmp/config"
          rhel.vm.provision "file", source: "#{ENV['USERPROFILE']}\\.ssh\\id_ed25519", destination: "/tmp/id_ed25519"
        end
        rhel.vm.provision :shell, :inline =>  "/vagrant/provision/install.sh", env: {"FULLNAME" => ENV['FULLNAME'], "EMAIL" => ENV['EMAIL']}
    end
    config.vm.boot_timeout = 1000
end

xrow avatar Jan 24 '24 08:01 xrow

Important:

If I comment out

# centos.vm.disk :disk, size: "150GB", primary: true

the problem doesn`t occur.

xrow avatar Jan 24 '24 08:01 xrow

I've encountered the same problem. It only seems to happen with redhat distributions. Ubuntu works fine.

Qwarctick avatar Jun 07 '24 13:06 Qwarctick