Use pkgsrc on ARM

What is this page?

This page describes how to use pkgsrc on ARM architecture with EABI support. I bought TeraStation Live, which is called "TeraStation Living" in Japan, and wanted to use it as a home server. The original system in TeraStation Live, however, contains the very minimum software, and does not have development environment. If you want to use some new software, you have to prepare an additional system to install it. There are several ways, for example, crosstool, Debian ARM EABI Port, and other package systems...

From the multiple choices, I decided to use pkgsrc. The main reason is that I can change prefix (location to install) when bootstrap. If prefix is /usr and it's not customizable, the package system may break the original system. Among well-known package systems, pkgsrc seems to be the only one whose prefix can be changed.

I think pkgsrc is a good choice to use on embedded systems like TeraStation, but there are not many pages which answer my purpose. I'm happy if this page is of reference to someone.


This binary was built on "CodeSourcery ARM 2005q3-2". You can check whether your system is the same or not by running /lib/

# /lib/
GNU C Library stable release version 2.3.6, by Roland McGrath et al.
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
Compiled by GNU CC version 3.4.4 (release) (CodeSourcery ARM 2005q3-2).
Compiled on a Linux 2.6.12-rc3 system on 2006-01-26.

If your environment is different from mine, and you want to know how to make this tarball, see Bootstrapping pkgsrc section.

Setting up pkgsrc

I assume you can login to TeraStation as root, and your main HDD partition is mounted under /mnt/array1.

# mkdir /mnt/array1/system
# cd /mnt/array1/system
# tar zxf /path/to/arm-2005q3-2_pkg2008MMDD.tar.gz

Make links to /usr.

# ln -s /mnt/array1/system/pkg /usr
# ln -s /mnt/array1/system/pkgsrc /usr


# echo 'export PATH=/usr/pkg/bin:/usr/pkg/sbin:/usr/pkg/gcc34/bin:${PATH}' >> ~/.profile
# source ~/.profile
# hash -r

Set ld's library path and run ldconfig.

# mv /etc/ /etc/
# echo /usr/pkg/lib >> /etc/
# cat /etc/ >> /etc/
# ldconfig

Checkout pkgsrc from CVS.

# cd /mnt/array1/system
# CVS_RSH=ssh cvs -d checkout pkgsrc

Then, /usr/pkg and /usr/pkgsrc are now ready to use.

Setting up glibc and linux headers

To compile something, headers of glibc and linux are required. Get arm-2005q3-2-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 and unpack it. There is glibc in arm-none-linux-gnueabi.

# mkdir /mnt/array1/system/arm-2005q3
# cd /mnt/array1/system/arm-2005q3
# wget
# bzcat arm-2005q3-2-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 | tar xf -
# mv arm-none-linux-gnueabi/libc /mnt/array1/system

Make links.

# ln -s /mnt/array1/system/libc/usr/include /usr
# ln -s /mnt/array1/system/libc/etc/rpc /etc


# echo 'export PATH=${PATH}:/mnt/array1/system/libc/usr/bin:/mnt/array1/system/libc/sbin' >> ~/.profile
# source ~/.profile
# hash -r

That's it. You can now build software using pkgsrc. Enjoy!

Some Q & A

First, how can I get a root privilege in TeraStation?
I don't write the details. There are several ways, and using firmware update seems to be one of the popular way for it. I could get root by not the firmware update, but a pretty classic way. This is the time to show your stuff. Good luck!
pkgsrc cannot find ncurses.h or when building some software.
Add the following line to the pkgsrc's Makefile.
.include "../../mk/"
Notice that this line should be before the line .include "../../mk/". For example, see /usr/pkgsrc/devel/gtexinfo/Makefile.
pkgsrc reports an error related to iconv when building some software.
That may be because there are two headers of the same name, /usr/include/iconv.h and /usr/pkg/include/iconv.h. Temporarily, you may bypass the error by renaming the one in /usr/include.
# mv /usr/include/iconv.h /usr/include/iconv.h.bak
Where has devel/cvs gone?
It's been moved to devel/scmcvs. See also: HEADS UP: devel/cvs -> devel/scmcvs
I don't want to permit any change of /mnt/array1/system through samba!
Edit /etc/samba/smb.conf and restart samba. Or, stopping samba service is also a good idea if you don't use samba.
I set LANG=ja_JP.UTF-8, but it does not have effect. Why?
That may be because glibc doesn't know the locale. To check effective locales, run locale -a.
# locale -a
In this case, only C and POSIX locale are available. To make Japanese UTF-8 locale, for example, do:
# mkdir /mnt/array1/system/libc/usr/lib/locale
# ln -s /mnt/array1/system/libc/usr/lib/locale /usr/lib
# ln -s /mnt/array1/system/libc/usr/share/i18n /usr/share
# localedef -i ja_JP -c -f UTF-8 ja_JP.UTF-8
I can ssh from TeraStation to another machine if I'm root. But if I'm not root, I cannot ssh with the error "Host key verification failed". Why?
That may be because the permission of /dev/tty is wrong. To check the permission, run ls -l /dev/tty.
# ls -l /dev/tty
crw-r--r-- 1 root root 5, 0 Dec 28 01:27 /dev/tty
In this case, only root can ssh. To ssh even if not root, add write permission to /dev/tty.
# chmod 666 /dev/tty

Bootstrapping pkgsrc

This section is my memo which explains how to bootstrap pkgsrc. First, make a buildbox and copy the original system.
Reference: chroot Arm Build Environment

# mkdir /mnt/array1/buildbox
# cd /
# for d in `ls |grep -v dev |grep -v proc|grep -v mnt`; do tar cf /mnt/array1/buildbox/$d.tar $d; done
# cd /mnt/array1/buildbox
# for f in *.tar; do tar xf $f; done

Get native development tools arm-tools-0_16-8.tgz and unpack it.

# cd /mnt/array1/buildbox
# tar zxf /path/to/arm-tools-0_16-8.tgz

Mount proc and dev to chroot environment.

# mount -t proc none /mnt/array1/buildbox/proc
# mount -o bind /dev /mnt/array1/buildbox/dev

chroot into the buildbox.

# chroot /mnt/array1/buildbox /bin/sh

If /tmp is a symbolic link (in my case, symlink to /mnt/ram), remove it and make new tmp dir.

# rm /tmp
# mkdir /tmp

Get pkgsrc and unpack it.

# cd /tmp
# wget
# cd /usr
# tar zxf /tmp/pkgsrc.tar.gz

Get some additional software from Precompiled Binaries and install to /opt directory.

# cd /tmp
# wget
# wget
# wget
# wget
# mkdir /opt
# cd /opt
# bzcat /tmp/coreutils-6.7-r1.tbz2 | tar xf -
# bzcat /tmp/gawk-3.1.5-r2.tbz2 | tar xf -
# bzcat /tmp/grep-2.5.1a-r1.tbz2 | tar xf -
# bzcat /tmp/patch-2.5.9-r1.tbz2 | tar xf -


# export PATH=/opt/bin:/opt/usr/bin:${PATH}
# hash -r

Rename a linux header which causes a build error.

# mv /usr/include/linux/ext2_fs.h /usr/include/linux/ext2_fs.h.bak

Apply a patch to bootstrap, and finally run bootstrap!

# cd /tmp
# wget
# cd /usr/pkgsrc/bootstrap
# patch -p0 < /tmp/bootstrap-20080104.patch
# TR=/opt/bin/tr AWK=/opt/bin/awk GREP=/opt/bin/grep TOUCH=/opt/bin/touch ./bootstrap --prefix=/usr/pkg --pkgdbdir=/usr/pkg/var/db/pkg --varbase=/usr/pkg/var

After bootstrap, you can install software using pkgsrc in the chroot environment. Building GCC is a little complicated task, so I create a separate section to explain it.

How to build GCC for ARM with EABI support

GCC starts to support EABI feature from version 4.1. In pkgsrc, however, there is no lang/gcc41 or lang/gcc42. One solution is to use CodeSourcery's GCC-3.4, to which some patches are applied to support ARM EABI. You can get the source from Download the ARM 2005q3-2 Release.

# cd /tmp
# wget
# bzcat arm-2005q3-2-arm-none-eabi.src.tar.bz2 | tar xf -



Unpack the CodeSourcery's GCC instead of pkgsrc's original gcc34.

# cd /usr/pkgsrc/lang/gcc34
# bmake extract
# cd work
# bzcat /tmp/arm-2005q3-2-arm-none-eabi/gcc-2005q3-2.tar.bz2 | tar xf -
# mv gcc-3.4.6 gcc-3.4.6.orig
# mv gcc-2005q3 gcc-3.4.6
# cd -

Edit Makefile to change CONFIGURE_ARGS. I added following lines:

CONFIGURE_ARGS+= --host=armv5tejl-unknown-linux-gnueabi
CONFIGURE_ARGS+= --target=armv5tejl-unknown-linux-gnueabi
CONFIGURE_ARGS+= --with-float=soft
CONFIGURE_ARGS+= --enable-c99

Then, run bmake. Or, if you want info files, bmake MAKEINFO=/usr/pkg/bin/makeinfo. After the build is finished, run bmake install. In arm-2005q3-2_pkg2008MMDD.tar.gz, this gcc34 is included.

Another solution is to use pkgsrc-wip, which has gcc42.

# cd /usr/pkgsrc
# CVS_RSH=ssh cvs -d checkout wip

Then you can use wip/gcc42. After gcc42 is installed, set PATH and ld's library path. It's almost the same way in the case of gcc34. In addition, you may have to apply this patch to pkgsrc/mk/compiler/

Remember to re-install devel/libtool-base after gcc34 or gcc42 is installed.