0

I'm building a Vagrant Windows 10 box (using libvirt, based on the workflow documented at here: https://fishilico.github.io/generic-config/windows/vagrant.html). After the VM is ready, I run:

vagrant package default --output win10-libvirt.box

and then I take the "box" file to another machine and import it using vagrant add.

The thing is, as part of the setup I add a key to the user's ~/.ssh/authorized_keys file, but when I start the new box on the second machine - that file is gone. I also tried to add a key to the "administrators' keys" file supported on Microsoft Windows OpenSSH port at C:\ProgramData\ssh\administrators_authorized_keys - but that is also gone when I start the new box - actually the entire C:\ProgramData\ssh folder is gone.

Does vagrant package cleans the machine configuration folders, and if so - can this be disabled somehow? I couldn't find documentation about this.

Guss
  • 2,670
  • 5
  • 34
  • 59

1 Answers1

0

The issue was fixed for me after I added a call to Sysprep followed by shutdown at the end of the provisioning script. I'm not sure if the Sysprep is what was needed or the shutdown - the libvirt shutdown process should be safe enough and watching the libvirt viewer I can see that the VM performs the Windows shutdown process.

I used this command in my Vagrantfile:

Vagrant.configure("2") do |config|
  # ...

    config.vm.provision "shell", inline: <<-'SCRIPT'
& ./run-some-provisioning.ps1
& C:/Windows/System32/sysprep/sysprep.exe /generalize /mode:vm /shutdown
SCRIPT

  # ...
end
Guss
  • 2,670
  • 5
  • 34
  • 59