Computer Nerd Kev

Home|About|Projects|Links


Projects > Tiny Core > Pkgsrc

Using Pkgsrc to Install Software in Tiny Core Linux

2023-08-03

Some notes on setting up Pkgsrc in Tiny Core Linux 14 Pure64.

I could only find two sources of Pkgsrc binary packages for Linux on x86_64, for RHEL 7 and for Slackware. Neither work on Tiny Core Linux 14 Pure64 unfortunately, for some reason the binaries aren't compatible. Perhaps an earlier TC version works?

Instead this guide sets up compiling software from source code using Pkgsrc's build scripts and package management system. Also see the documentation on, and linked from, this page on the NetBSD Wiki.

Note that this does not create Tiny Core extensions. Program files are stored in a conventional way, with files scattered around in /usr/pkg. It also takes up gigabytes of storage just for the build system, which is in no way "tiny". The advantage is that in theory it allows automatically building any of over 26,000 supported programs and libraries, along with their dependencies. Known security vulnerabilities of software installed with Pkgsrc can also be monitored with the pkg_admin tool.

Without any working sources for binary packages, so far it seems like often it wouldn't be much harder to compile programs manually and make Tiny Core extensions for them. But it might be quicker for applications that have many dependencies which aren't available as TC extensions.

Installing Pkgsrc

Pkgsrc stores build files in /usr/pkgsrc and installed files in /usr/pkg. These need to be on a permanent file system so that they persist between reboots. It strongly objects to using symlinks, so I used bind mounts to physically locate those directories in the "tce" directory while still appearing in /usr.

Note that the filesystem where the tce directory is located must be mounted with the "exec" option for this to work, and that even with just a few basic programs installed it's already using over 3GB of storage space (some of that can probably be reclaimed, but 1.2GB is used up right at the start when pkgsrc.tar.xz is unpacked).

Set up bind mounts for the Pkgsrc directories in tce (or replace "/etc/sysconfig/tcedir" with another location, eg. /mnt/sda1, if desired).

  $ sudo mkdir /usr/pkgsrc /usr/pkg /etc/sysconfig/tcedir/pkg /etc/sysconfig/tcedir/pkgsrc
  $ sudo mount -o bind /etc/sysconfig/tcedir/pkgsrc /usr/pkgsrc
  $ sudo mount -o bind /etc/sysconfig/tcedir/pkg /usr/pkg

Download the current Pkgsrc package (~50MB) to the tce directory and extract the contents as root.

  $ cd /etc/sysconfig/tcedir
  $ wget ftp://ftp.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.xz
  $ sudo tar xvJf pkgsrc.tar.xz

As root, open /usr/pkgsrc/mk/tools/tools.Linux.mk and change the line starting with "_LINUX_BINPATHS?=" to:

  _LINUX_BINPATHS?=       /usr/local/bin /bin /usr/bin /usr/local/sbin /sbin /usr/sbin

The bootstrap script sets up the Pkgsrc system, which includes compiling various tools. First some extensions need to be installed.

  $ tce-load -wil compiletc ncursesw-dev zlib_base-dev coreutils tar xz bzip2 gzip openssl-1.1.1 wget

Now run the script in /usr/pkgsrc/bootstrap. "--prefer-native yes" means that it will try to use programs already installed, so use that if you're sure that all libraries currently installed with TC extensions will also be loaded when you later run programs built with pkgsrc. "--make-jobs" can be set to the number of CPU cores available. Other options can be listed with "./bootstrap -h".

Switch to the root user.

  $ sudo su

Run the bootstrap script, which will take a while.

  # cd /usr/pkgsrc/bootstrap
  # ./bootstrap --prefer-native yes --make-jobs 4

Edit /etc/profile and change the line starting with "PATH=" to:

  PATH="/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:/apps/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Add /etc/profile to .filetool.lst:

  # echo etc/profile >> /opt/.filetool.lst

Add the pkgsrc library directory to ld.so.conf.

  # echo /usr/pkg/lib >> /etc/ld.so.conf
  # ldconfig

Create some symlinks which I found were necessary to prevent errors.

  # ln -s `which sort` /bin/sort
  # ln -s `which gawk` /usr/pkg/bin/nawk

Now it should be possible to compile software with the Pkgsrc build system.

Compiling an Application With Pkgsrc

See Updating Pkgsrc for a more concise example.

As an example, let's build GNU Enscript. Note that this will also compile Perl and Flex as dependencies if perl5.tcz and flex-dev.tcz aren't installed (and Pkgsrc might still want to build them itself anyway).

This alias allows for easily finding the directory where a program's build scripts are located (wildcards can also be used if quoted or \ escaped):

  $ alias pkgdir='find /usr/pkgsrc -maxdepth 2 -type d -name'
  $ pkgdir enscript
  /usr/pkgsrc/print/enscript
  $ cd /usr/pkgsrc/print/enscript
  $ cat DESCR
  This is a filter that converts text files to PostScript and spools generated
  PostScript output  to  the  specified  printer or leaves it to file.  If no
  input files are given, enscript processes  standard  input.  enscript can be
  extended to handle different output media and it has many options which can
  be used to customize printouts.

It seems to be best to run all of the following commands as root.

  $ sudo su

Download the source code files for Enscript and all of the build and run-time dependencies that aren't installed already from extensions in Tiny Core. There will be quite a few because this is the first time building in the new pkgsrc installation:

  # bmake fetch-list | sh

Compile all the dependencies, and finally Enscript. Set "MAKE_JOBS=" to the number of CPU cores available:

  # MAKE_JOBS=4 bmake

For me it failed because a "Parsetexi.la" file wasn't created while building the gtexinfo package. I ended up generating a dummy file with this command, then running "MAKE_JOBS=4 bmake" again.

  # touch /usr/pkgsrc/devel/gtexinfo/work/.destdir/usr/pkg/lib/texinfo/Parsetexi.la

Sometimes the compiler failed because required header files weren't found. I needed to find the pkgsrc directory for the corresponding library, cd into there, and run "bmake install". Then switch back to the /usr/pkgsrc/print/enscript directory and run "MAKE_JOBS=4 bmake" again.

Once it completes without an error, install the Enscript into the /usr/pkg directory tree with:

  # bmake install

You may need to run these commands so that the newly installed program and libraries are detected.

  # ldconfig
  # hash -r

Now running this should work:

  $ enscript --version
  GNU Enscript 1.6.6
    Copyright (C) 1995-2003, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
    GNU Enscript comes with NO WARRANTY, to the extent permitted by law.
    You may redistribute copies of GNU Enscript under the terms of the GNU
    General Public License, version 3 or, at your option, any later version.
    For more information about these matters, see the files named COPYING.

Restoring Pkgsrc After a Reboot

Save this script somewhere, eg. ~/bin/pkginit.sh:

  #!/bin/ash
  # Restore pkgsrc after reboot, with files kept in tcedir
  mkdir /usr/pkgsrc /usr/pkg
  mount -o bind /etc/sysconfig/tcedir/pkgsrc /usr/pkgsrc
  mount -o bind /etc/sysconfig/tcedir/pkg /usr/pkg
  echo /usr/pkg/lib >> /etc/ld.so.conf
  ldconfig
  sudo ln -s `which sort` /bin/sort

Make it executable:

  $ chmod a+x ~/bin/pkginit.sh

Run it as root to set up pkgsrc after a reboot:

  $ sudo ~/bin/pkginit.sh

You could also add the commands in the pkginit.sh script to /opt/bootlocal.sh to have pkgsrc restored immediately after start-up.

Updating Pkgsrc

CVS is used to update the Pkgsrc build system without needing to download a Tar archive again and overwrite everything in /usr/pkgsrc. Note that packages still need to be recompiled after the update if a newer version is available.

CVS isn't currently packaged for TC14 on x86_64, so the first job is to compile it with Pkgsrc using the sequence described above.

  $ pkgdir '*cvs*'
  /usr/pkgsrc/www/cvsweb
  /usr/pkgsrc/devel/cvsclone
  /usr/pkgsrc/devel/cvs-for-gits
  /usr/pkgsrc/devel/cvsutils
  /usr/pkgsrc/devel/cvsps3
  /usr/pkgsrc/devel/cvsup-gui-bin
  /usr/pkgsrc/devel/cvsps
  /usr/pkgsrc/devel/fromcvs
  /usr/pkgsrc/devel/cvsync
  /usr/pkgsrc/devel/pcl-cvs
  /usr/pkgsrc/devel/cvsdiff2patch
  /usr/pkgsrc/devel/git-cvs
  /usr/pkgsrc/devel/cvsgraph
  /usr/pkgsrc/devel/tkcvs
  /usr/pkgsrc/devel/gcvs
  /usr/pkgsrc/devel/cvs2cl
  /usr/pkgsrc/devel/cvsup-bin
  /usr/pkgsrc/devel/cvs2html
  /usr/pkgsrc/devel/scmcvs
  /usr/pkgsrc/devel/cvs-fast-export
  /usr/pkgsrc/devel/refinecvs
  /usr/pkgsrc/devel/cvs2svn
  /usr/pkgsrc/devel/cvslock
  /usr/pkgsrc/devel/cvsd
  /usr/pkgsrc/sysutils/cvsreport
  $ cd /usr/pkgsrc/devel/scmcvs
  $ cat DESCR 
  CVS is a version control system, which allows you to keep old versions
  of files (usually source code), keep a log of who, when, and why
  changes occurred, etc., like RCS or SCCS.  It handles multiple
  developers, multiple directories, triggers to enable/log/control
  various operations, and can work over a wide area network.
  $ tce-load -i compiletc ncursesw-dev zlib_base-dev coreutils tar xz   bzip2 gzip openssl-1.1.1 wget
  $ sudo su
  # bmake fetch-list | sh
  # MAKE_JOBS=4 bmake
  # bmake install
  # ldconfig

Now you should be able to update pkgsrc via CVS like this (it might take a while):

  $ tce-load -i openssh wget coreutils
  $ cd /usr/pkgsrc && sudo cvs update -dP

Parting Thoughts

Note that I've only been using Pkgsrc for a few days, so there are sure to be better, and possibly more reliable, ways of doing things. This is just a rough guide.

It's possible that by setting CFLAGS and CXXFLAGS variables in the Pkgsrc Makefile settings (somewhere in /usr/pkgsrc/mk) to the values recommended for Tiny Core, and changing the LOCALBASE setting to "/usr/local" in /usr/pkgsrc/mk/defaults/mk.conf, Pkgsrc could be used to build binaries that could be manually turned into TC extensions. PLIST, in the package directories, can be used to identify all the files installed for a package, which can then be split into program.tcz, program-doc.tcz, program-dev.tcz...

"ldd" can show which libraries are used from Tiny Core extensions, and which are from /usr/pkg/lib, so the latter can be turned into TC extensions as well.

On the other hand it's an extra level of things to go wrong, so I think compiling programs manually for Tiny Core extensions might still be easier in the end.


Home|About|Projects|Links


Content Copyright Kevin Koster 2023