How do I package an existing VM that was not creat

2019-03-08 01:41发布

I installed a VirtualBox and then installed a Ubuntu 12.10 Server Base OS in it. I have installed all kinds of php packages and other packages in it. My friends recommended me to use Vagrant so I can share my setup with my team mates easily.

Because my current VirtualBox VM was not created using vagrant up, I am not sure how to package it. The documentation over at Vagrant talks about packaging but starts by saying:

Before working through the rest of this page, make sure the virtual environment is built by running vagrant up.

In my case, my existing VM was NOT created initially using vagrant up.

How do I package my existing VM?

9条回答
萌系小妹纸
2楼-- · 2019-03-08 02:38

While not a complete answer, I think you can get what you need from the documentation, which is quite extensive. I believe that vagrant up is merely a convenient means to setting up a Vagrant "box". There are a number of requirements for a box to be Vagrant compliant. They are described here...

Documentation: Vagrant - Base Boxes

The bare bones needed for a box are as follows...

  • VirtualBox Guest Additions for shared folders, port forwarding, etc.
  • SSH with key-based auth support for the vagrant user
  • Ruby & RubyGems to install Chef and Puppet
  • Chef and Puppet for provisioning support

Once a box is compliant with these requirements, it should simply be a matter of using the vagrant package command to create a portable installation...

More documentation: Vagrant - Boxes

So, while I don't have a complete answer, having never done it this way, I think it's possible to get your installation into a state that will allow you to package and distribute it.

查看更多
劫难
3楼-- · 2019-03-08 02:42

vagrant package --output box_name.box --base "vm machine name" --vagrantfile Vagrantfile

Make sure that port forwarding and SSH keys are setup properly.

This may be a good example: https://github.com/okfn/ckan/wiki/How-to-Create-a-CentOS-Vagrant-Base-Box

查看更多
虎瘦雄心在
4楼-- · 2019-03-08 02:44

Personally, the illusive aspect of the packaging process was the --base switch. I suspect that might be the case with a lot of people. Check out vagrant package --help for the description. The documentation does not seem to make mention of it either.

I found these two great, in-depth, step-by-step guides to create Vagrant boxes from machines that were originally VirtualBox machines:

  1. How to Create a CentOS Vagrant Base Box
  2. Creating base box from scratch for Vagrant
查看更多
登录 后发表回答