I’ve been using Vagrant a lot at work. These days we were facing some problems when our VMs were booting and a friend, jbochi, came up with an idea to take a screenshot from a running VM.

He found this command on VBoxManage:

$ VBoxManage controlvm [vm-uuid] screenshotpng [output-filename]

And it helped a lot! That’s when we had the idea to wrap this command in a script to keep using. Initially I’ve created a small python script, but then reading about vagrant plugins (hltbra’s suggestion) I’ve decided to create one.

The vagrant-screenshot plugin is very simple. You just need to install the gem and use:

$ gem install vagrant-screenshot

Here is an usage example:

$ vagrant screenshot -o
[vagrant] Taking screenshot for default
[vagrant] Screenshot saved on screenshot-default.png

By default it takes screenshots for all active VMs. The -o (--open) option opens the images when done (only works on OS X for now)

See the help for more details

$ vagrant screenshot --help

PS.: The problem I’ve mentioned we were facing ended up in a pull request to vagrant, but unfortunately it wasn’t accepted :o)