I have a VirtualBox VM, created "by hand" (i.e., without using vagrant at all), which runs Debian.

What is the simplest way to generate a vagrant file that would replicate this box? Is there an automated way to do this?

  • What do you mean by "replicate"? If you mean recreating from bare Debian and installing all packages, then you have to do that yourself.
    – harrymc
    Mar 30 '19 at 12:48
  • Did you already tried what suggested here? In this way you can Convert a VirtualBox .ova VM into a Vagrant box then from there you can duplicate/clone... If that was you goal let me know that I will write one answer with some words more...
    – Hastur
    Apr 1 '19 at 11:52
  • The automated way/procedures (eventually existent) may depend on the host OS. Which is yours?
    – Hastur
    Apr 4 '19 at 12:24
  • @Hastur: my host is also Debian.
    – kjo
    Apr 4 '19 at 15:17
  • @kjo thx. BTW I found vagrantmanager but unfortunately is not for Linux...
    – Hastur
    Apr 5 '19 at 10:00

You can try following the steps reported in the github page "Convert a VirtualBox .ova VM into a Vagrant box #7", skipping the first one because you already have your VM (and you are not starting from an ova file)...

  1. Individuate the internal name, ID, reading it from the GUI or by commandline with the VBoxManage command:

    VBoxManage list vms
    "UCS 4.1" {acef4c0a-35be-4640-a214-be135417f011}

    You are interested in acef4c0a-35be-4640-a214-be135417f011, that on your computer will be different (instead of UCS 4.1 you have to select the VM name you given to your debian system).

  2. Package that VM as a Vagrant box

    vagrant package --base acef4c0a-35be-4640-a214-be135417f011 --output UCS.box

    Take the unique ID found before and write instead of acef4c0a-35be-4640-a214-be135417f011 in the above command line. Note that you can change the output filename as you want (instead of UCS.box you can use whatever.box), but you will need to use the same name in the next command.

  3. Add to the list of your local Vagrant boxes

    vagrant box add UCS.box --name UCS

    With the file name chosen before you can add the box to vagrant, choosing even the human readable name (in the above case UCS). The name has to be reported in the next file.

  4. Create a Vagrantfile to use this box, or modify one you already have:

    Vagrant.configure("2") do |config|
    config.vm.box = "UCS"
    # ...

  5. vagrant up

  • Thanks, but I don't see any *.ova files in my vms directory, so I think this may not work for me.
    – kjo
    Apr 3 '19 at 21:13
  • You're welcome. You have not to see any ova file (it's the analogous of a zip file or cab...). Enter in a shell (DOS prompt or Linux Bash Shell if you are under windows 10) and write the command in the point 1 VBoxManage list vms. It will answer with the list of the already present VM. Take the strange number (acef4c0a...) associated with the "human readable" one (it will be different on your computer... then continue to use the other commands... You can change the names but you have to change even in the next step (see the bold part to understand better).
    – Hastur
    Apr 4 '19 at 10:10
  • Add config.ssh.insert_key = false and follow this answer to remove ssh problems: "Warning: Authentication failure. Retrying... " after packaging box Nov 19 '20 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.