Saturday, November 17, 2012

VirtualBox "Kernel driver not installed (rc=-1908)" on Mac OSX

I have a Windows virtual machine that I use, and I tried to start it today and received the following error:

After a bit of searching I found a pastebin with the answer, to load the kernel driver run:

sudo kextload /Library/Extensions/VBoxDrv.kext/

Attempting to start the virtual machine progressed a little further, but I was now greeted with:

Not sure what the issue here is… When I try to edit settings I'm greeted with:

Clicking OK allowed me enter the settings, but I couldn't change anything. The solution for me was to discard the saved state for the VM, go into the settings and disable the host-only adapter (not sure if this step was necessary), then boot the VM.

Tuesday, September 18, 2012

Adding space to Ubuntu VM without reboot.

Using LVM allows you to add space to a virtual machine without rebooting it. However you need to be using it already if you want to grow existing file systems. This post only covers increasing the size, as shrinking is more risky and I generally avoid it.

Increasing the size of a filesystem where LVM is used directly on the disk:
  1. If you're using LVM on the storage device (not partition) directly, it's trivial to add more space.
  2. Increase the size of the virtual machine's storage device.
  3. Run `dmesg` and find the appropriate SCSI device (e.g. 2:0:0:0)
  4. Tell the kernel to rescan that device:
    $ echo 1 | sudo tee /sys/class/scsi_device/2\:0\:0\:0/device/rescan
    $ sudo dmesg
    [151064.769416] sda: detected capacity change from 5368709120 to 6442450944
  1. Use `pvresize` to increase the size of the physical volume:
    $ sudo pvresize /dev/sda
    $ sudo lvextend -l+100%FREE /dev/VolGroupName/root
    $ sudo resize2fs /dev/VolGroupName/root

This is only possible when the drive isn't partitioned. If the drive is partition, the easiest solution is to add a new storage device to the VM, use LVM directly on that, and add it to the existing volume group:

  1. Add new storage device and detect it in the guest using scsitools:
    sudo apt-get install scsitools
  1. Do something along the lines of:
    $ sudo pvcreate /dev/sdb
    $ sudo vgextend VolGroupName /dev/sdb
    $ sudo lvextend -l+100%FREE /dev/VolGroupName/root
    $ sudo resize2fs /dev/VolGroupName/root

Sunday, August 5, 2012

Disabling OSX's PostgreSQL to use Heroku's

If you want to use, you'll probably want to turn off any existing PostgreSQL servers you have run to free up port 5432. Typically these are configured to run via launchd, so you'll need to use launchctl to disable them, e.g.:

sudo launchctl remove /Library/LaunchDaemons/com.edb.launchd.postgresql-9.0.plist

As you can see you need to pass the path to a .plist file. There's a couple of places these can exist, so you can use grep to find them:

grep -ri postgres /Library/LaunchDaemons /System/Library/LaunchDaemons ~/Library/LaunchAgents

Sunday, July 15, 2012

Installing Solr 3.6.0 on Ubuntu from source

1. Make a solr user

    useradd -d /opt/solr solr

2. Download a tarball of Solr 3.6.0 and install to /opt/solr

    tar -zxf apache-solr-3.6.0.tgz
    mv apache-solr-3.6.0 /opt/solr
    chown -R solr /opt/solr

4. Make log directory

    mkdir /var/log/solr
    chown solr /var/log/solr

5. Create Upstart job at /etc/init/solr.conf:

    description "Solr"

    start on runlevel [2345]
    stop on runlevel [016]

    exec su solr -l -c "cd /opt/solr/example && java -Dsolr.solr.home=/etc/solr -Djetty.port=8080 -Djetty.logs=/var/log/solr -jar start.jar > /var/log/solr/stdouterr.log 2>&1"

6. Create the base data directory for cores:

    mkdir /var/lib/solr
    chown solr /var/lib/solr

7. Make /etc/solr/solr.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <solr persistent="false">
      <cores adminPath="/admin/cores">
        <core name="" instanceDir="/etc/solr/">
          <property name="dataDir" value="/var/lib/solr/" />

8. Make core conf in /etc/solr/{schema.xml,solrconfig.xml}

Thursday, June 21, 2012

Disable Apache on OSX Server

I seem to have lost the OSX Server configuration app, which made trying to turn off Apache a little tricky. The solution is to use launchctl:

sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist

See man launchctl for details.

Sunday, May 6, 2012

Turn Python warnings into errors

It's generally good practice to run unit tests with warnings turned into errors to ensure deprecation warnings are honoured in a timely manner. Despite often coming across people saying that this can be done with a command line flag, after a bit of searching around I couldn't find a simple example of how to do this.

After a bit of trial and error it turns out to be very simple:

python -W error

The above flag will turn all warnings into errors.

For more complex usage Doug Hellman has a good write up:

Thursday, April 26, 2012

Enabling Upstart user jobs to start at boot.

I've come across an issue with Upstart – user jobs' start on stanzas aren't honored at boot time.

The real issue is more general: user jobs aren't loaded into Upstart until the user creates an Upstart session. If a job isn't loaded into Upstart, it's basically invisible and hence its start on stanzas won't be honored.

Loading user jobs into Upstart is simple. It happens automatically when a user creates an Upstart session by connecting via D-Bus using initctl or one of the shortcuts (e.g. start or status). Until user jobs are loaded into Upstart, they're completely disabled.

So the problem at boot time is that user's don't have the opportunity to create an Upstart session prior to the rc-sysinit job emitting runlevel, this makes it impossible for user jobs with start on runlevel [2345] to be honored.

Perhaps this is by design – I'm not sure – but I wrote the following job to get around the issue by blocking rc-sysinit and creating an Upstart session for each user with an .init/ directory in their home:

The following job should be installed into /etc/init/load-user-jobs.conf:

Tuesday, April 10, 2012

Can't exec "dpkg-architecture" … on Ubuntu 11.10

Ran into a puzzling problem today setting up PostgreSQL 9.1. After creating a user and logging in, I was greeted with:

$ psql postgres brad
Can't exec "dpkg-architecture": No such file or directory at /usr/bin/psql line 103.
Use of uninitialized value $multiarch in scalar chomp at /usr/bin/psql line 104.
psql (9.1.3)
Type "help" for help.


It seems the package dpkg-dev wasn't installed for some reason…

Easy fix:

sudo apt-get install dpkg-dev

Monday, April 9, 2012

Compiling Python on OSX 10.8

Python 2.6 – OSX Lion

make install

Tuesday, March 6, 2012

py.test paremeterized test fails with "LookupError: no factory found for function argument …"

I have a trivial test:
import pytest
@pytest.mark.parameterize(("input", "expected"), [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
def test_eval(input, expected):
    assert eval(input) == expected
It fails saying:
LookupError: no factory found for function argument 'input'
available funcargs: pytestconfig, capsys, capfd, tmpdir, monkeypatch, recwarn
use 'py.test --funcargs [testpath]' for help on them.
What's going on here? It's spelt parametrize – not parameterize.

But why didn't I get a NameError?

pytest.mark allows arbitrary marks to be added to a function. Due to the
dynamic nature of py.test, pytest.mark.<any name here> can be used to mark a
test. Since pytest.mark.parameterize isn't recognised by any of the pytest
plugins, it's essentially a no-op.

Monday, March 5, 2012

Problem cloning local git repository using `git clone file:///…`

So I was trying to clone a local git repository using:
$ git clone file:///home/git/repositories/bar.git
And I would get output like this:
$ git clone file:///home/git/repositories/bar.git/ bar
Initialized empty Git repository in /home/brad/bar/.git
remote: Counting objects: 1317, done.
remote: Compressing objects: 100% (1179/1179), done.
remote: Total 1317 (delta 601), reused 406 (delta 57)
Receiving objects: 100% (1317/1317), 5.37 MiB | 683 KiB/s, done.
Resolving deltas: 100% (601/601), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.
The issue was that although I had added myself to the git group, the permissions on the heads refs did not permit group read:
$ ls -lha /home/git/repositories/bar.git/refs/heads
total 12K
drwx------ 2 git git 4.0K 2012-03-05 15:42 .
drwx------ 4 git git 4.0K 2012-02-28 14:21 ..
-rw------- 1 git git   41 2012-03-05 15:45 development
-rw------- 1 git git   41 2012-03-05 15:42 master
Simple fix:
$ chmod g+r /home/git/repositories/bar.git/refs/heads/*
So why was this suddenly a problem?

It just so happens I recently upgraded from gitosis to gitolite, and gitolite uses a different umask (0077) to gitosis. This means that every new file created was created with only user permissions.

I want g+rx, so I edited /home/git/.gitolite.rc and changed $REPO_UMASK to 0027.

Saturday, February 18, 2012

Remove items from print spool/queue in Windows 7

I've recently had some trouble deleting/removing a print job/item from the printer spool/queue on Windows 7. The print job just wouldn't delete despite rebooting and instructing Windows to delete it many times. After a bit of googling I found a solution:

  1. Open a command window (Click Start; Type command and press enter)
  2. Right click the title bar and select "Run as Administrator"
  3. Type net stop spooler and press enter.
  4. Type del %systemroot%\System32\spool\printers\* /Q and press enter.
  5. Type net start spooler and press enter.

Sunday, January 22, 2012

Install Upstart 1.3 on Ubuntu 10.04

I wanted to upgrade Upstart on Ubuntu 10.04 to make use of the new user jobs feature.  I cherry picked packages from Ubuntu 11.10 via . Here's what I came up with: (Run each command separately, some require user input) I found that dbus wasn't installed, and as such running start foo would fail:

$ start foo
start: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory

Fixed via sudo apt-get install dbus