Skip to content

Instantly share code, notes, and snippets.

@ajstarks
Last active December 17, 2015 12:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ajstarks/093581ac1fbc355f8402 to your computer and use it in GitHub Desktop.
Save ajstarks/093581ac1fbc355f8402 to your computer and use it in GitHub Desktop.
Building Debian on the Beaglebone Black, installing Go

#Install Debian on the Beaglebone Black, along with Go 1.1

##Ingredients:

  1. Internet connected computer running Mac OS X (you may substitute some other Unix/Linux box---you'll need enough disk space to hold the Debian image (about 2GB), the ability to fetch content from the Internet, uncompress xz files, and the ability to write the image to a connected MicroSD card)

  2. MicroSD card (> 4GB recommended)

  3. MicroSD/SD adapter, USB SD card reader, built in SD card reader

  4. Beaglebone Black (BBB), connected to your local network via Ethernet.

##Steps:

(1) On the Mac, get the debian image, and unpack it

Mac$ curl http://s3.armhf.com/debian/wheezy/bone/debian-wheezy-7.0.0-armhf-minfs-3.8.12-bone17.img.xz | xz -dc > bone.img

(2) write the image to the microSD

Place the MicroSD card into your Mac, typically via USB or via built-in card reader. You will probably need to place the MicroSD card into a SD card adapter.

Here is a script (makeimage) that writes the image:

#!/bin/sh
if test $# -ne 2
then
    	echo specify disk and image file 1>&2
    	exit 1
fi
disk=$1
img=$2
diskutil umount /dev/disk${disk}s1
sudo dd bs=1m if=$img of=/dev/rdisk$disk
diskutil eject /dev/disk${disk}s1

you run it like:

Mac$ makeimage 1 bone.img

The tricky part is the determine the correct disk #. CAUTION getting this incorrect will corrupt your system, so double check, and if you (or I) mess this up, its on you.

(3) Boot from the MicroSD

When the image write is complete, and the MicroSD card has been dismounted, remove the MicroSD from the Mac, place it into a powered-down Beaglebone Black -- you will hear a faint "click" as the card goes into place.

Next, press the BOOT button located by the MicroSD slot, and apply power to the BBB. Note, use a proper power adapter (5VDC, 1000mA), not the supplied USB cable to supply power. This will ensure maximum performance.*

The BBB will boot in under 20 seconds.

(4) log into the freshly booted BBB

If you connected the BBB to a monitor, you will see a login prompt. Login with user name "debian", password "debian". If you booted the BBB headless, you can ssh in from the Mac. The IP address that the BBB responds to will vary with your network configuration.

Mac$ ssh debian@192.168.1.3
debian@192.168.1.3's password:

(5) Check the disk configuration

When you wrote the Debian image, you only used about 2GB of the MicroSD

debian@debian-armhf:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          1.8G  366M  1.3G  22% /
/dev/root       1.8G  366M  1.3G  22% /
devtmpfs        248M     0  248M   0% /dev
tmpfs            50M  220K   50M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           100M     0  100M   0% /run/shm
/dev/mmcblk0p1 1004K  480K  524K  48% /boot/uboot

Here are the disk devices: /dev/mmcblk0 is the device you booted from, the MicroSD. /dev/mmcblk1 is the built-in eMMC.

debian@debian-armhf:~$ ls -l /dev/mm*
brw-rw---T 1 root floppy 179,  0 Jan  1  2000 /dev/mmcblk0
brw-rw---T 1 root floppy 179,  1 Jan  1  2000 /dev/mmcblk0p1
brw-rw---T 1 root floppy 179,  2 Jan  1  2000 /dev/mmcblk0p2
brw-rw---T 1 root floppy 179,  8 Jan  1  2000 /dev/mmcblk1
brw-rw---T 1 root floppy 179, 16 Jan  1  2000 /dev/mmcblk1boot0
brw-rw---T 1 root floppy 179, 24 Jan  1  2000 /dev/mmcblk1boot1
brw-rw---T 1 root floppy 179,  9 Jan  1  2000 /dev/mmcblk1p1
brw-rw---T 1 root floppy 179, 10 Jan  1  2000 /dev/mmcblk1p2

(6) Expand the filesystem

Use fdisk to expand the filesystem to fill the capacity of the card. The fdisk command shows you the full capacity (In my case I used a 16GB card) The sequence below expands the re-partitions the card in-place.

debian@debian-armhf:~$ sudo fdisk /dev/mmcblk0

Command (m for help): p

Disk /dev/mmcblk0: 16.0 GB, 16012804096 bytes
4 heads, 16 sectors/track, 488672 cylinders, total 31275008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048        4095        1024    1  FAT12
/dev/mmcblk0p2            4096     3751935     1873920   83  Linux

Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (4096-31275007, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-31275007, default 31275007): +14G

Command (m for help): p

Disk /dev/mmcblk0: 16.0 GB, 16012804096 bytes
4 heads, 16 sectors/track, 488672 cylinders, total 31275008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048        4095        1024    1  FAT12
/dev/mmcblk0p2            4096    29364223    14680064   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
debian@debian-armhf:~$ sudo reboot

(7) Complete the expansion

After reboot, expand the file system:

debian@debian-armhf:~$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3670016 blocks long.

Great. Now we have more space.

debian@debian-armhf:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           14G  368M   13G   3% /
/dev/root        14G  368M   13G   3% /
devtmpfs        248M     0  248M   0% /dev
tmpfs            50M  216K   50M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           100M     0  100M   0% /run/shm
/dev/mmcblk0p1 1004K  480K  524K  48% /boot/uboot

(8) make the user account

The next step is to add a user to the newly expanded BBB.
I used the same username as on my Mac because I plan to ssh in. Having the same username simplifies things.

debian@debian-armhf:~$ sudo adduser ajstarks
Adding user `ajstarks' ...
Adding new group `ajstarks' (1001) ...
Adding new user `ajstarks' (1001) with group `ajstarks' ...
Creating home directory `/home/ajstarks' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for ajstarks
Enter the new value, or press ENTER for the default
  Full Name []: Anthony Starks
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y
debian@debian-armhf:~$ sudo addgroup ajstarks sudo
Adding user `ajstarks' to group `sudo' ...
Adding user ajstarks to group sudo
Done.

(9) login or ssh into the new account, install Go prerequisites, get and unpack the Go source distro.

ajstarks@debian-armhf:~$ cd
ajstarks@debian-armhf:~$ sudo apt-get update && sudo apt-get upgrade
ajstarks@debian-armhf:~$ sudo apt-get install gcc
ajstarks@debian-armhf:~$ sudo apt-get install git
ajstarks@debian-armhf:~$ sudo apt-get install mercurial
ajstarks@debian-armhf:~$ wget --quiet --output-document - https://go.googlecode.com/files/go1.1.src.tar.gz | tar zxvf - 

(10) Install and Test Go 1.1

ajstarks@debian-armhf:~$ cd go
ajstarks@debian-armhf:~/go/src$ ./all.bash

After about 45 minutes you will see a ALL TESTS PASS message. If you don't, figure out why.

Adjust environment

ajstarks@debian-armhf:~$ mkdir gopath bin work

This makes the gopath directory, your private bin, and a work area (this is were I test and play with code outside of my GOPATH)

Next, add these lines to ~/.profile

export GOPATH=$HOME/gopath
PATH=$PATH:$HOME/go/bin:$GOPATH/bin

and make them active:

ajstarks@debian-armhf:~$ . ~/.profile
ajstarks@debian-armhf:~$ go version
go version go1.1 linux/arm

(11) test build (ts.go)

Instead of the typical hello world program, I use a short program that searches twitter. It's more fun and exercises facilities like networking. Get ts.go from https://gist.github.com/ajstarks/3760929

ajstarks@debian-armhf:~$ cd ~/work
ajstarks@debian-armhf:~/work$ go build -o ~/bin/ts ts.go
ajstarks@debian-armhf:~/work$ ts \#golang

(12) Install packages from the net

ajstarks@debian-armhf:~/work$ go get github.com/ajstarks/svgo
ajstarks@debian-armhf:~/work$ go install github.com/ajstarks/svgo/...
ajstarks@debian-armhf:~/work$ android

##References:

http://www.armhf.com/index.php/expanding-linux-partitions-part-2-of-2/

http://www.armhf.com/index.php/download/

http://golang.org/doc/install/source

@kovir
Copy link

kovir commented May 24, 2013

Thank You for this "how to". Works fine for me.
Do You know how to force bbb to boot from microSD card without pressing "boot switch"?
After rebooting Debian is starting but after power off and on won't start....

Marc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment