Thursday, February 18, 2016

Upgrading to Go 1.6 on a Raspberry Pi

I had written previously about upgrading from Golang 1.4 to 1.5; the steps were largely the same, but I did run into a few extra snags.

The quick version of the instructions:
Go is installed in my home directory on the Pi.

mv ./go ./go1.4
git clone https://go.googlesource.com/go
git checkout go1.6
cd src
./all.bash

Note: I renamed my installed version go1.5. In the instructions above I named it go1.4. That's because go1.6 looked for the previous compiler in ~/go1.4; it prompted me to change an environment variable to make it work, which took the form of:

export GOROOT_BOOTSTRAP=/home/pi/go1.5

...or you can use go1.4 and it might find it automatically. At least, that's what the error implied.

It tried to complete, but I hit some issues due to resource scarcity on the Pi. It looks like the compiler compiled but tests would fail spectacularly. I needed to make a couple of tweaks, as per Dave Cheney.

First I changed a ulimit size because otherwise the tests will exhaust the 32 bit address space.

ulimit -s 1024

Second, I needed some swap. Otherwise it will exhaust available memory and poof everything dies.

The default way Raspberry Pi's configure swap is using dphys-swapfile. The configuration is contained in /etc/dphys-swapfile.

The default is a 100 MB file called /var/swap. It'll need to be enlarged, and if you have an external drive connected, it might be a good idea to put it there. It's slower but placing it on a physical platter drive will save wear on the SD card.

On my system I changed the lines:

CONF_SWAPSIZE=512
CONF_SWAPFILE=/mnt/mydrive/swap/swapfile

(Of course I had to create a directory called swap on the mount point with appropriate permissions first...)

Then I ran

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init./dphys-swapfile start

...to rebuild the swapfile.

Last step I needed to do was execute the ./all.bash script with a variable to change the scaling factor, which apparently works well on 64 bit machines but not little underpowered Pi's. Instead of ./all.bash, I ran:

env GO_TEST_TIMEOUT_SCALE=10 ./all.bash

All these small changes allowed Go 1.6 to not only compile, but pass the tests on my RasPi 2!

2 comments:

  1. Great information! Thanks. I was able to build 1.6 on a Raspberry Pi 3.

    ReplyDelete
  2. Just built it on model b+ thanks

    ReplyDelete