How Ignoring Vagrant Errors Hurt Me
Ignoring errors on systems managed by vagrant can be ok in the short term, can cause pain in the long term, especially when you are storing valuable information not on the shared folder!
I walk through a recent situation where I ignored errors on vagrant boot up because they didn’t affect my day-to-day use. When I had to extract documents from a location that was not on the shared folder, those earlier errors were blocking me from my goal.
I describe my situation, the error encountered, list solutions
considered, and give my solution:
This article will take you less than four minutes to read.
As I’m transitioning to a new computer, I have to migrate files off the old one.
Part of my workflow involves working with VirtualBoxes managed by Vagrant.
I love using vagrant to manage VirtualBoxes as vagrant handles all the necessary tasks to make a system work, such as:
- ssh key management
- connecting a shared directory between host (the computer running VirtualBox) and guest (the computer created in VirtualBox)
I’ve scripted vagrant so much, that whenever I encounter an error with a VirtualBox managed by vagrant, I would just run:
Ta-da. Problem solved!
Blogging in Vagrant
I like this approach so much, that I even write my blog articles within a VirtualBox managed by vagrant. I can migrate to a new computer easily.
Normally, software running in VirtualBox would be exactly the same as if the software was running on the host computer.
One Small Issue
When previewing new articles, article changes were not reflected unless I restarted the whole web server.
I believe the root cause was file changes my editor writes do not trigger guest OS level file IO changes since the host manages writes to the shared folder.
I worked around this by having all the files within the VirtualBox within the host system, not on the shared folder.
This fix allow previewing of articles when the editor changed them without restarting the web server.
Now Blocking Issue!
The work around was fine, until I had to migrate computers, essentailly, off the VirtualBox. Which I would not even do anything.
In this case, I wanted to copy draft articles and internal scripts.
The shared folder stopped working for reasons unknown
Realizing I had a problem, I paid attention to errors vagrant presented.
One thing that I noticed when I was starting my VirtualBox with vagrant:
and later on in the boot sequence:
This error did not affect before, I was using storage within the VirtualBox, not the shared folder.
This is a big problem now as my main approach to migrating the files off this VirtualBox was to use the shared folder, and now it’s not working!
Effectively, this trapped my files inside the VirtualBox!
As I was able to login and run programs, I did have these options:
- mailing files out as an attachment
- copying them to an external server
- connecting a file sharing system like Google Drive or Dropbox
- putting the files on git
All of these are viable options to get files out of a VirtualBox that you still have access to and internet connected.
I did not want any of these options as I wanted to transfer out private SSH keys and did not want them somewhere forever.
What are my options?
What are options to keep data local, especially since the VirtualBox is in the computer I’m running it on?
Seems silly to go the long way around the world to ask for something next door.
I can migrate the whole system image - except the files I want are only KB in size and the system image is GB in size - it’s like killing a fly with a bazooka.
Also, I would still have the same problem if I wanted the files out for any other reason.
One option I explored: connecting a USB memory stick to the Virtual Box. The VirtualBox is still a computer.
I could not get this going within 25min of effort and did not feel I was making headway. The VirtualBox did show the USB device, the guest system didn’t.
Another option: scp - if I can
ssh into the VirtualBox,
work too, right?!
Well, out of the box, vagrant, the system I use to manage my VirtualBox did not support this. I did not know the SSH key (I could dig around) nor the IP address, nor the port.
vagrant plugin to the Rescue!
Vagrant has a plugin system (which another plugin got me into this
mess the first place!) and there is a plugin for…
scp with vagrant, this is the syntax to copy something OUT of
the vagrant/VirtualBox system and into your local system:
So, I had
files.tar.gz in the home directory in the VirtualBox (
=> /home/vagrant) to copy that out to the current directory with the
same name, I ran command:
Yes! Files out, now run:
vagrant destroy!!! :-)
Well, not yet, soon!
Ignoring error messages may not have caused me issues at the time, letting them linger caused big headaches for me down the road!
As tempting it is to treat vagrant systems as ephemerial, if I have files in the system, I do not have the same freedom. I must treat errors just as if I had errors on my own system.
Luckily, there are options available in my situation because I could
still connect to the VirtualBox through vagrant and there were plugins
available. Thank goodness for