Here I'm republishing an old blog post of mine originally from February 2017. The article has been slightly improved.
The first post of this mini series was about legacy systems in general and about what installing the old FreeBSD 4.11 is like. In the second one I showed the initial configuration of the system, how to SSH into it despite the obsolete DSA host key problem and how to bootstrap pkgsrc, NetBSD's portable ports system. I also covered the installation of SVN, checking out of the 4.11-STABELE code and updating the system. This post will cover installing newer software.
Updating FreeBSD 4.11 (1/4) - Blast from the past
Updating FreeBSD 4.11 (2/4) - Digging up old graves
So far we have a pkgsrc tree from mid 2007 and things seem to be working. However that's pretty close to 4.11's release in 2005 and thus not too amazing. Working with such an old system, there are plenty of cases which mean "game over". Here are just three errors of that kind which you can encounter trying to build more modern software:
/usr/libexec/elf/ld: cannot find -lpthread
There simply is no modern pthreads available on 4.11. Game over.
/usr/include/sys/resource.h:58: error: field 'ru_utime' has incomplete type
We'll have to do with very old system headers missing a lot of what we take for granted today. Game over again.
fileio.o(.text+0x354): undefined reference to `towupper'
collect2: ld returned 1 exit status
Sorry, that ancient libc that we have on our system doesn't provide that symbol. Game over yet again.
How far do you think can we take it in building and installing more recent software? Make a guess now and see if you were right! To be honest I was not expecting the end result. Not at all. So let's get back to work!
We're going to compile a lot of stuff this time - building SVN and dependencies was just a warm up. And what do you do when you're building stuff remotely over SSH? You're doing so in a _screen_ or _tmux session_ of course. Neither is part of the base system so we've got to build one. Tmux was not yet available in 2007 so it's not too hard a choice:
# cd /usr/pkgsrc/07/misc/screen
# bmake install clean clean-depends
# rehash
# screen
GNU screen started up and ready (PNG)
If you don't know _screen_ do some reading because you will want to start using it (or rather the superior _tmux_). It basically allows you to detach from a session and reconnect later - and your programs will continue running on the remote system even while you're logged out. You can also resume the session from another terminal or computer, share sessions, etc. And that's just one of the things that it does. There are other features like allowing you to have multiple shell instances in just one terminal between which you can switch back and forth (think tabs of a browser) and a lot more. Should you not like this (what's wrong with you?!), fine. Don't install screen. It's optional.
Now it's time to take care of the main problem of our system: That darned version 3.5 of OpenSSH! Let's build whatever our pkgsrc tree has to offer:
# cd /usr/pkgsrc/07/security/openssh
# bmake install clean clean-depends
# rehash
# ssh -V
OpenSSH_4.6p1, OpenSSL 0.9.7d-p1 17 Mar 2004
Still far from a modern version of OpenSSH but also a lot better. And the best thing: It supports RSA keys. Let's generate host keys with this newer SSH and make it the version that FreeBSD launches during startup:
# ssh-keygen -f /usr/local/temp/etc/ssh/ssh_host_key -N '' -t rsa1
# ssh-keygen -f /usr/local/temp/etc/ssh/ssh_host_rsa_key -N '' -t rsa
# ssh-keygen -f /usr/local/temp/etc/ssh/ssh_host_dsa_key -N '' -t dsa
# mkdir -p /usr/local/temp/run
# echo 'sshd_program="/usr/local/temp/sbin/sshd"' >> /etc/rc.conf
Ok, everything is in place. We could reboot now - or just kill off the old daemon and launch the new one. Let's first look for _sshd_ and see which PID it has (this of course varies from system to system!):
# ps aux | grep sshd
Got it? Great, let's kill it (your SSH connection is maintained by a child and it's generally save to kill the parent. You won't lose your SSH connection!), start the new one and ensure that it's running:
# kill [PID on your system]
# /usr/local/temp/sbin/sshd
# ps aux | grep sshd
What's this? It looks like it's not running! Yes, it looks like it but actually it should be running... Let's grep again:
# ps aux | grep local
This does return one process - and trust me it's actually our new sshd. What's happening here is this: The output of _ps_ is truncated because more wouldn't fit on the screen. And only that data is handed to _grep_! So the process with the name _/usr/local/temp_ that we found (see the screenshot above) is actually _/usr/local/temp/sbin/sshd_ with the last part of it cut off... This is why grep doesn't find "sshd". There's a funny way to fix this, though: Maximize your terminal emulator so that more space is available. Then grep will find sshd!
Now we can quit the old SSH session so we can make one with the new server. We can even keep our screen session open, but we need to detach from it by pressing _CTRL-A_ and then _D_ before we logout from vierelf:
[detached]
# logout
> exit
Connection to 192.168.1.5 closed.
Time to edit your _known hosts_ file and get rid of the former host key for vierelf or else you'll see that scary SSH warning when you try to login again. Oh, and you can leave out that compatibility option from now on - which is a major step ahead! When you're back in, you can resume the screen session:
% ssh kraileth@192.168.1.5
> su -
# screen -r
Connecting to the new SSH server (debug mode) (PNG)
Alright. Currently we have the last version of the second generation of GCC on our system. We totally need to get our hands on something newer. How about updating the last version of generation three? Let's try that! We only want the C and C++ compilers. Fortran is deactivated by default for this version (it would need GMP installed and the version of GMP that's in the tree requires GCC3. It's a good idea to avoid that potential circular dependency). However Java and Object-C are activated. There's no need to waste time on them, they should be deactivated as well. The following _sed_ command may look a bit complex, but it's not that bad. Just copy all three lines that make up that single command and you're good to go:
# cd /usr/pkgsrc/07/lang/gcc34
# cp Makefile Makefile.bak
# sed -e '64,65d' -e '63a\\
BUILD_JAVA?= NO' -e '63a\\
BUILD_OBJC?= NO' Makefile.bak > Makefile
# bmake install clean clean-depends
After installing that newer GCC, the path needs to be changed again so that the system picks it up instead of the older system compiler:
# vi /root/.cshrc
Prepend the following path to the PATH variable:
/usr/local/temp/gcc34/bin
Now let's log out and in again and see if the new compiler is available:
# exit
[screen is terminating]
# logout
> su -
# screen
# cc -v
[...]
gcc version 3.4.6
Since we also have a more recent OpenSSH now, we can checkout a newer copy of pkgsrc from CVS! That takes a while, be patient. Even after it is finished downloading (and you see no new lines on the screen) it will still take some time to clean things up. This is normal and you have to wait a little longer. Don't _CTRL+C_ it as that would leave your tree in bad shape!
# cd /usr/pkgsrc
# cvs -danoncvs@anoncvs.netbsd.org:/cvsroot get -rpkgsrc-2009Q4 -P pkgsrc
# mv pkgsrc 09
Thanks to the newer SSH: CVS works now, too! (PNG)
We'll need some ports from there later. But since we have GCC 3 available now we can also grab an even newer copy and primarily use that one:
# cvs -danoncvs@anoncvs.netbsd.org:/cvsroot get -rpkgsrc-2013Q2 -P pkgsrc
# mv pkgsrc 13
We're going to start a fresh environment, using only GCC (and sshd) from the old one. To do so we first bootstrap the pkgsrc from 2013 into a new directory:
# mkdir /usr/local/pkgsrc
# cd /usr/pkgsrc/13/bootstrap
# ./bootstrap --prefix=/usr/local/pkgsrc --varbase=/usr/local/pkgsrc
The next step is to adjust the PATH variable so that the binaries from the new location are being used. To do so we need to replace _/usr/local/temp_ with _/usr/local/pkgsrc_ for both _sbin_ and _bin_. Don't change the compiler path, though! GCC 3 will remain in temp. After logging out and back in, screen is no longer in PATH so we need to execute it with the absolute path:
# cp /root/.cshrc /root/.cshrc.bak
# sed -e 's:temp/bin:pkgsrc/bin:' -e 's:temp/sbin:pkgsrc/sbin:' /root/.cshrc.bak > /root/.cshrc
# exit
# logout
> su -
# /usr/local/temp/bin/screen
This gives us a way to easily build software from 2013. Let's continue on by fetching some source tarballs by hand that are no longer available on the mirrors that pkgsrc knew for them:
# cd /usr/pkgsrc/09/distfiles
# fetch http://ftp.cc.uoc.gr/mirrors/NetBSD/packages/distfiles/binutils-2.17.tar.gz
# fetch http://ftp.cc.uoc.gr/mirrors/NetBSD/packages/distfiles/pkg-config-0.23.tar.gz
The following part is not too interesting: We're going to build the dependencies in preparation for the next big step. In general we try to build the newest version possible (2013) but resort to old (2009) or even older (2007) where necessary if newer versions don't build for various reasons:
# cd /usr/pkgsrc/13/converters/libiconv
# bmake install clean clean-depends
_Zip_ from 2009 and onwards is incompatible with FreeBSD 4.11's libc. And the 2007 version expects _tar_ in a location where there's none on our system. Instead of building tar we can safely symlink it:
# ln -s /usr/bin/tar /usr/local/pkgsrc/bin/tar
# cd /usr/pkgsrc/07/archivers/zip
# bmake install clean clean-depends
The _binutils_ programs are a special case. The port normally builds the utilities of which it consists with a prefix so they don't get in the way of the system binaries. Since we actually want to use them instead of the old stuff from the base system, we need to get rid of that prefix:
# cd /usr/pkgsrc/09/devel/binutils
# bmake GNU_PROGRAM_PREFIX='' install clean clean-depends
# rehash
# ld -v
GNU ld version 2.17
The next few are trivial:
# cd /usr/pkgsrc/09/devel/gettext-tools
# bmake install clean clean-depends
# cd /usr/pkgsrc/13/devel/m4
# bmake install clean clean-depends
# cd /usr/pkgsrc/09/devel/bison
# bmake install clean clean-depends
The _bash_ port from 2013 would draw in a newer version of gettext which would not build. But bash can actually be built with the old one, too. So we have to make a simple change in the _buildlink_ file for gettext in 2013's pkgsrc tree:
# cd /usr/pkgsrc/13/devel/gettext-lib
# cp buildlink3.mk buildlink3.mk.bak
# sed 's/0.18/0.14/g' buildlink3.mk.bak > buildlink3.mk
With that change done, the next port can be built:
# cd /usr/pkgsrc/13/shells/bash
# bmake install clean clean-depends
Next in line is Perl. The 2013 port would however build it with _dtrace_ support by default - which is of course not available on 4.11. Therefore it needs to be switched off by making an addition to the pkgsrc config file:
# vi /usr/local/pkgsrc/etc/mk.conf
Add the following line at the end of the file (but above _.endif_):
PKG_OPTIONS.perl= -dtrace
Now let's build the last few remaining dependencies:
# cd /usr/pkgsrc/13/lang/perl5
# bmake install clean clean-depends
# cd /usr/pkgsrc/13/archivers/xz
# bmake install clean clean-depends
# cd /usr/pkgsrc/09/devel/autoconf
# bmake install clean clean-depends
With this all dependencies from earlier than 2013 are in place we are good to go for the biggest update. We're still not interested in Java and Object-C, so let's edit pkgsrc's configuration again:
# vi /usr/local/pkgsrc/etc/mk.conf
and add one more line (e.g. after the Perl one):
PKG_OPTIONS.gcc44= -gcc-java -gcc-objc
Building the newer version of GCC means building two more dependencies as well, one of which is _libgmp_. GMP is the first package so far that uses C++, and in fact our C++ compiler has been broken the whole time. Luckily a symlink can heal it and another one will make GCC happy so that we can finally build it - which takes quite a bit of time though (I've seen the compilation stop at one point and I'm not sure what happens there. But just issuing _bmake_ again will eventually complete the build process!):
# ln -s /usr/local/pkgsrc/lib/libiconv.so.7 /usr/lib/libiconv.so.7
# ln -s /usr/local/temp/gcc34/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1
# cd /usr/pkgsrc/13/lang/gcc44/
# bmake install clean clean-depends
Once it's built, we need to change our PATH so that the newer GCC becomes the primary compiler:
# mv /root/.cshrc /root/.cshrc.bak
# sed 's:temp/gcc34:pkgsrc/gcc44:' /root/.cshrc.bak > /root/.cshrc
Now all that we have to do is log out and back in once more:
# exit
# logout
> su -
# /usr/local/temp/bin/screen
Let's take a look if the new compiler responds to cc (and fix c++ support along the way):
# ln -sf /usr/local/pkgsrc/gcc44/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1
# cc -v
[...]
gcc version 4.4.7 (GCC)
GCC 4.4.7 running on FreeBSD 4.11 (PNG)
Yes, we really have _GCC 4.4_ running on FreeBSD 4.11! While it's certainly not a modern compiler, it's recent enough to build a lot of software. The latest release of OpenBSD, version 6.0 released on September 2016, still comes with _GCC 4.2_, BTW! Yes, OpenBSD maintained that all the time and the team heavily patches it. Still we now actually have a compiler available on FreeBSD 4.11 from 2005 which is two major versions newer than that!
With this we're kind of back in business. But this post is already becoming quite long and for that reason I'm putting the "grand finale" off to one more post. See you there for the final outcome of this "little" experiment (which I hadn't intended to write more than three posts for, but there you have it).
Updating FreeBSD 4.11 (4/4) - Reflecting radical resurrection