Error building node module in a Vagrant box with NFS

I was trying, and failing, to install node-heapdump:

vagrant@debian7:/vagrant$ npm install heapdump
npm WARN package.json execSync@1.0.1-pre No repository field.
npm http GET
npm http 304

> heapdump@0.2.7 install /vagrant/node_modules/heapdump
> node-gyp rebuild

make: Entering directory `/vagrant/node_modules/heapdump/build'
  CXX(target) Release/
  CXX(target) Release/
  SOLINK_MODULE(target) Release/
flock: ./Release/linker.lock: No locks available
make: *** [Release/] Error 71
make: Leaving directory `/vagrant/node_modules/heapdump/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/vagrant/.nvm/v0.10.26/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.2.0-4-686-pae
gyp ERR! command "node" "/home/vagrant/.nvm/v0.10.26/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /vagrant/node_modules/heapdump
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm ERR! heapdump@0.2.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the heapdump@0.2.7 install script.
npm ERR! This is most likely a problem with the heapdump package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls heapdump
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-4-686-pae
npm ERR! command "/home/vagrant/.nvm/v0.10.26/bin/node" "/home/vagrant/.nvm/v0.10.26/bin/npm" "install" "heapdump"
npm ERR! cwd /vagrant
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /vagrant/npm-debug.log
npm ERR! not ok code 0

A github issue suggested that cloning the repo, and running node-gyp rebuild, might give a better error. But that succeeded. Searching for the error message: “flock: ./Release/linker.lock: No locks available”, pointed the finger at the share being mounted using NFS. Unfortunately, after much research and fiddling, the best solution I could come up with was to switch the vagrant share back to a VirtualBox one temporarily.

vagrant@debian7:/vagrant$ npm install heapdump
npm WARN package.json execSync@1.0.1-pre No repository field.
npm http GET
npm http 304

> heapdump@0.2.7 install /vagrant/node_modules/heapdump
> node-gyp rebuild

make: Entering directory `/vagrant/node_modules/heapdump/build'
  CXX(target) Release/
  CXX(target) Release/
  SOLINK_MODULE(target) Release/
  SOLINK_MODULE(target) Release/ Finished
  COPY Release/heapdump.node
make: Leaving directory `/vagrant/node_modules/heapdump/build'
heapdump@0.2.7 node_modules/heapdump


Running Meteor in a Vagrant (virtual)box

If you’re trying to run Meteor in a Vagrant VirtualBox, and getting an error like this when starting the local server:

vagrant@precise32:/vagrant$ meteor 
[[[[[ /vagrant ]]]]]

Unexpected mongo exit code 100. Restarting.
Unexpected mongo exit code 100. Restarting.
Unexpected mongo exit code 100. Restarting.
Can't start mongod

MongoDB had an unspecified uncaught exception.
This can be caused by MongoDB being unable to write to a local database.
Check that you have permissions to write to .meteor/local. MongoDB does
not support filesystems like NFS that do not allow file locking.

As the error message suggests, the problem is caused by the way Vagrant is sharing the src folder with the VM. The easiest solution (suggested here) is to move the Mongo DB data folder to somewhere on the VM, with a symlink in the Meteor folder:

vagrant@precise32:/vagrant/.meteor/local$ ln -s ~/db/                  
vagrant@precise32:/vagrant/.meteor/local$ ls -la
total 12
drwxr-xr-x 1 vagrant vagrant 4096 Jun 17  2013 .
drwxr-xr-x 1 vagrant vagrant 4096 Jun 17 21:47 ..
lrwxrwxrwx 1 vagrant vagrant   17 Jun 17  2013 db -> /home/vagrant/db/

And you should be back in business!

vagrant@precise32:/vagrant$ meteor 
[[[[[ /vagrant ]]]]]

=> Meteor server running on: http://localhost:3000/

UPDATE: this won’t work on a Windows host, apparently; due to the lack of support for symlinks. Sorry!

Manually installing VirtualBox guest additions

I mainly run Windows VMs on a Linux host. When you update to the latest version of VirtualBox, it’s best to update (or install) the guest additions.

Normally, you can run the installer by selecting Devices->Install Guest Additions from the VirtualBox menu. This doesn’t always seem to work though, so it’s necessary to run the installer manually.

On a Linux host, the guest additions can be found in /usr/share/virtualbox/VBoxGuestAdditions.iso. If you share this folder with the guest, you can mount the ISO directly using various free tools. However I find it easier to just copy it to the guest, use 7-zip to extract everything, and run VBoxWindowsAdditions.exe.

Activation woes with Windows 7 & VirtualBox

I run Windows 7 in a VirtualBox (on top of Linux Mint). The idea being that when you’ve broken one VM, you can trash it and move onto a new one :)

To that end, I keep a clean baseline image with only Windows installed. When the time has come to pave my dev environment, I clone this VM and start re-installing (thanks Chocolatey!).

However, rather inconveniently, I found that even though the baseline copy of Windows had been activated, the cloned VMs somehow knew that something had changed and needed re-activation.

Normally the trigger for this is a change of MAC address, but VBox allows you to keep that the same (the VMs are never running at the same time, so having the same MAC address is not a problem).

Eventually, this got annoying enough that I did what I should have done in the first place, to the internet!

Apparently, the secret is to set an extra property called the hardwareuuid:

VBoxManage modifyvm  --hardwareuuid 

Once this is set, any cloned VMs will inherit it. No more activation!

(Piracy is bad, m’kay. But I paid for Windows, and I want to use it as I wish).

Installing VBox 4.1.2 Windows Guest Additions on Ubuntu 11.10

I’ve been having some trouble copying files from my host fileshare (\\vboxsvr), and the internets recommended re-installing the guest additions. Unfortunately, trying to download the guest additions iso resulted in the error below:

Error downloading VBox Guest Additions iso

Some frantic searching of the VBox forums offered a solution: download the guest additions for the previous version (4.1.0), and put them in the location VBox expects to find them (either /usr/share/virtualbox/VBoxGuestAdditions.iso or /usr/lib/virtualbox/additions/VBoxGuestAdditions.iso).

sudo mv VBoxGuestAdditions_4.1.0.iso /usr/share/virtualbox/VBoxGuestAdditions.iso

And now I can copy files without any problems, hurray!

Copying VirtualBox hard disks

If you take a copy of a VirtualBox hard disk (.vdi file), in the hope of attaching it as another VM, you may receive an error similar to this:

Failed to open the hard disk /home/blah/blah/blah.vdi.

Cannot register the hard disk 'home/blah/blah/blah.vdi' {some-guid} because a 
hard disk 'home/blah/blah/foo.vdi' with UUID {some-other-guid} already exists.

Result Code: NS_ERROR_INVALID_ARG (0x80070057)
Component: VirtualBox
Interface: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}

Thankfully the internets soon provided an answer, although the syntax has changed slightly:

VBoxManage internalcommands sethduuid blah.vdi

(Although the correct solution, of course, is to use VBoxManage clonehd in the first place!)

Sharing files between Ubuntu and a Windows VirtualBox

I’m currently running Ubuntu (11.04) with Windows in a VirtualBox, both at work and at home.

Every once in a while I have a need to share a file in one direction, or the other. So here are my notes on how to do it, for future reference!

Mounting a Windows share from Ubuntu is pretty easy:

  1. Share the folder, if you haven’t already
  2. Open your Home Folder, and go to File -> Connect To Server…
  3. Select “Service Type”: Windows Share
  4. Enter the server name, and logon credentials
  5. Job’s a good ‘un

Going the other way is a little more involved, and I think you need the Guest Additions installed:

  1. In the vbox instance menu, select Devices -> Shared folders
  2. Either right click and “Add Shared Folder”, or press Ins
  3. Select “Other” from the folder path drop down, and choose the host folder you want to access (tick “Make Permanent” if you’re going to need it in future)
  4. Back in Windows land, open Explorer and go to Tools -> Map Network Drive
  5. Your share will be called \\vboxsvr\<SHARE_NAME> (you should be able to browse to it if you’re not sure what it’s called)
  6. Done