QR Code Business Card
Apr 24 2014

Vagrant shell script

Working with several Vagrant boxes in parallel can be tricky. So today I wrote a small shell script to help me here. It will

  • start the VM (if not already running),
  • Login into the VM via SSH,
  • suspend the VM after exiting the VM (if you want)

Shell script:
#/bin/bash
if [ -f ./Vagrantfile ]
then
if vagrant status | grep -q "running ("
then
echo Box is already running
else
echo Starting box ...
vagrant up
fi
echo Login in ...
vagrant ssh
read -n1 -p "Suspend box ? [y,N]" doit
case $doit in
y|Y) vagrant suspend ;;
n|N) echo OK ;;
*) echo OK ;;
esac
else
echo No Vagrantfile found!
fi


Jan 15 2014

Your VM has become “inaccessible.”

After some time a restarted playing around with my private vagrant setup when i came across this message, after trying to “up” my machines:

Your VM has become “inaccessible.”

So my setup is broken and I had to repair the machines. Luckily this is very easy:

$ vboxmanage list vms
"<inaccessible>" {652819f9-a4c4-4b18-b7e0-ea8e8bcec828}

There you can see the inaccessible vm and its id. Just unregister it and vagrant will be able to bring up your system from scratch.

$ vboxmanage unregistervm 652819f9-a4c4-4b18-b7e0-ea8e8bcec828
$ vagrant up
Bringing machine 'centos' up with 'virtualbox' provider...
[centos] Importing base box 'centos'...