The Unix Way
Posted: September 12, 2012 | Author: Sideb0ard | Filed under: history, unix, video | Comments OffAce early Unix infomercial –
perl parp parp
Posted: September 2, 2012 | Author: Sideb0ard | Filed under: howto, internet, networking, TCP/IP, unix | Comments Off
I updated the IP address for both my Name Servers tonite, and was monitoring to see how quickly the new addresses were propagating. First stop was the exceptionally useful Whats My DNS
At the host level I also wanted to track the incoming DNS queries using tcpdump. I could see them streaming into the new host, and visually you could see an obvious difference when viewing the output of the same command on the old host. I googled around for a timer utility which run a command for a given time, so i could quantify the difference. Perfect answer was here, a simple perl wrapper function.
Here’s how to use it to run tcpdump command for sixty seconds, and count the packets seen:
# doalarm () { perl -e 'alarm shift; exec @ARGV' "$@"; }
# doalarm 60 tcpdump -u -i eth0 port 53 -n |wc -l
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
19504
(( graphic is a photo of artwork by the super awesome Jacob Borshard ))
Like Treacle, Solving Perl Net::SFTP Slow Transfer Speeds
Posted: February 19, 2012 | Author: Sideb0ard | Filed under: big data, cloud, distribution, internet, networking, perl, programming, unix | Comments OffI’ve been trying to track down problems with really slow network transfer speeds between my servers and several DSPs. I knew it wasn’t local I/O, as we could hit around 60Mb/s to some services, whereas the problematic ones were a sluggish 0.30Mb/s; I knew we weren’t hitting our bandwidth limit, as cacti showed us daily peaks of only around 500Mb/s of our 600Mb/s line.
I was working with the network engineer on the other side, running tcpdump captures while uploading a file and analysing that in Wireshark’s IO Graphs – stream looked absolutely fine, no lost packets, big non-changing tcp receive windows. We were pretty much stumped, and the other engineer recommend i look into HPN-SSH, which does indeed sound very good, but first i started playing around with trying different ciphers and compression.
Our uploads are all run via a perl framework, which utilises Net::SFTP in order to do the transfers. My test program was also written in perl and using the same library. In order to try different cyphers i started testing uploads with the interactive command line SFTP. Boom! 6Mb/s upload speed. Biiiig difference from the Net::SFTP client. I started playing with blowfish cipher and trying to enable compression with Net::SFTP – it wasn’t really working, it can only do Zlib compression, which my SSHD server wouldn’t play with until i specifically enabled compression in the sshd_config file.
After much more digging around, i came across reference to Net::SFTP::Foreign, which uses the installed ssh binary on your system for transport rather than relying on the pure perl Net::SSH.
Syntax is very similar, so it was a minor rewrite to switch modules, yet such a massive payback, from 0.30Mb/s up to 6Mb/s.
(It turns out the DSPs i mentioned earlier who could achieve 60Mb/s were actually FTP transfers, not SFTP)
building a DEB package from a perl script
Posted: February 16, 2012 | Author: Sideb0ard | Filed under: configuration management, debian, perl, unix | Comments OffI have a speedtest perl script i wrote – nothing complicated, takes a file and uploads it to a remote FTP or SFTP server, while calculating how long, then gives you a a measure of the MB/per second bandwidth between two sites.
I want it available on a selection of machines so it can run from wherever, so I thought i’d package it up as a .DEB file and stick it in our local repo. Nothing complicated in that, and there are a number of online tutorials about building your own debs. The main drawback with most I found was that they assume you are actually building from source rather than just distributing a script, although I also found a relevant Ubuntu thread which is pretty simple and to the point.
However, even using these tutorials it still took me a few hours to figure out. There are just a couple of non-obvious points, so i figure writing out my own steps is worth recording –
So first, grab your required packages:
apt-get install dh-make dpkg-dev debhelper devscripts fakeroot lintian
You will need to build from a directory with the name of your script in the form packagename-version, so for mine i created /tmp/speedtest-1.0, then copied in my script ‘speedtest‘ and it’s data file 25MBFLAC.file ( which i could have created with dd on the box rather than copy over, but downloading the file is actually quicker in this situation ).
The first step is to run:
dh_make -s --indep --createorig -e thor@valhalla.com
(dash-s means create a single binary .deb – i.e. no source version; indep means architecture-independent; and createorig is to indicate you are the original maintainer)
this creates a top-level ‘debian‘ directory containing all the necessary config files.
The main one you need to edit is debian/control – you prob only need fill in “section”, “homepage” and “Description”
Mine looks like:
Source: speedtest
Section: web
Priority: extra
Maintainer: Thorsten Sideboard <thor@valhalla.com>
Build-Depends: debhelper (>= 7.0.50~)
Standards-Version: 3.8.4
Homepage: http://github.com/sideboard/speedtest.git
Package: speedtest
Architecture: all
Depends: ${misc:Depends}
Description: Test Upload Speeds
One of the things which baffled me for a while, which was answered in the askubuntu link above, was how to specify where something is installed — it goes in a file ‘debian/install‘ which isn’t created for you. The format of the file is ‘filename location/to/be/installed” (without the initial slash)
so in my case, i ran:
echo "speedtest usr/local/Scriptz/" > debian/install
echo "25MBFLAC.file usr/local/Scriptz/" >> debian/install
At this point, you should then be able to run:
debuild -us -uc
and you should have a deb file built. but..
First i ran into :
dpkg-source: error: can't build with source format '3.0 (quilt)': no orig.tar file found
As the above-mentioned askubuntu post says, you can
echo "1.0" > debian/source/format
then re-running the debuild -us -uc i ran into
dpkg-source: error: cannot represent change to speedtemp-1.0/25MBFLAC.file: binary file contents changed
This error is due to leftover build-cruft from my last run – if you check the directory one step up from where you are, you’ll see debuild has already built some files for you, typically a tar.gz, a .dsc and a .build file. Delete all them, then re-run debuild -us -uc — now it should build properly!
ah!
dh_usrlocal: debian/speedtemp/usr/local/Scriptz/speedtest is not a directory
This one also caught me out for a while – turns out this is caused by my specifying “/usr/local/Scriptz” as my install location –
Most third-party software installs itself in the /usr/local directory hierarchy. On Debian this is reserved for private use by the system administrator, so packages must not use directories such as /usr/local/bin but should instead use system directories such as /usr/bin, obeying the Filesystem Hierarchy Standard (FHS).
(from here)
So, yeah, i changed my debian/install file to be “speedtest usr/bin”
and finally! running debuild -us -uc completes properly, outputting a /tmp/speedtest_1.0-1_all.deb which can then be installed via
dpkg -i /tmp/speedtest_1.0-1_all.deb
One last note — there are four useful scripts to also know about — preinst, postinst, prerm, postrm — these should be in the debian/ directory – pretty self-explanatory – pre- and post- install and remove scripts – if these exist, they will be run exactly as they are named, so for example, i wanted my 25MBFLAC.file still to be installed under /usr/local/Scriptz, so i listed it to be installed in the debian/install file as “25MBFLAC.file tmp” and then in my postinst file, i added:
#!/bin/sh
mv /tmp/25MBFLAC.file /usr/local/Scriptz/
CPAN Diff script
Posted: December 16, 2011 | Author: Sideb0ard | Filed under: configuration management, perl, programming, unix | Comments Off
I put together a quick perl script for comparing installed CPAN modules between two hosts. Find it here.
Quite easy to use:
Usage: ./CompareHostCpanModules.pl login@host1 login@host2
The script ssh’s into both hosts (so it’s easier if you have your ssh-keys setup) and grabs a list of installed CPAN modules and versions, then outputs the differences – it returns two lists – one of modules installed but having different versions, and another list of modules missing from the second host.
80s hair unixz
Posted: June 11, 2011 | Author: Sideb0ard | Filed under: history, unix, video | Tags: BSD, Dr Kirk McKusick, video | Leave a comment »History of BSD – this is awesome:
Brief history of NCP -> IP/TCP transition, also awesome:
Get Off Of My Cloud!
Posted: May 27, 2011 | Author: Sideb0ard | Filed under: abstraction, cloud, configuration management, future, hadoop, hardware, puppet, simulator, unix, virtualization, xen | Leave a comment »I work around Hadoop a lot at work, however my duties don’t really require me to interact much beyond the occasional data-mining work in Hive. Recently, I was intrigued to read that Amazon’s EC2 services are built upon Xen Hypervisor, which is also something I use, but don’t administer. I figured I would combine them into learning exercise by setting up a Xen server, create a little virtual cluster, configure them all via Puppet (another project i’ve been wanting a look at) and finally setup Hadoop on them all. Here’s what happened..

XEN INSTALL——————–
So - Xen is virtualisation software – the master host where the Hypervisor software is installed is called Dom0, and it can have many DomU guests, each a virtual machine which can run a host Operating System. In order to install the Xen Hypervisor and run Dom0, the kernel needs some modifications, and my first surprise was to discover recent releases of Ubuntu’s kernel don’t have Dom0 support. (The most recent discussion I could find on this was here, from 2010, so things may have changed)
My Ubuntu install has been through several years of upgrading and was getting a little crufty, plus the recent move to Unity desktop with Natty 11.04 wasn’t exciting me very much. I’ve also been keen to give Debian another go, as it’s been a few years, so rather than backport a Debian kernel to Ubuntu, I just went for a fresh install of Debian 6.0/Squeeze.
Aside from kernel support, more recent hardware support seems, if not essential, to make installation a lot easier. You need some BIOS support and CPU support – I’m running on a DELL Precision 390 – BIOS v.2.1.2 and CPU is a Pentium Core-2 Duo. I switched on Virtualization under the Performance section of my BIOS.
Aiight, so following instructions at http://wiki.debian.org/Xen i installed kernel and meta package..
apt-get install xen-linux-system
Then to ensure the xen kernel is loaded first, you have to move some files around:
cd /etc/grub.d/
mv 10_linux 50_linux
update-grub
Reboot machine and you should be running with a Dom0 kernel:
root@bitbot:/etc/puppet# uname -a
Linux bitbot 2.6.32-5-xen-amd64 #1 SMP Thu May 5 00:57:12 UTC 2011 x86_64 GNU/Linux
Now install Xen tools..
apt-get install xen-tools
Following some older HOWTO’s i started building my own filesystems for my first Guest machine:
dd if=/dev/zero of=/Xen/host/weebit1/root.img bs=1024k count=1024mkfs -t ext3 /Xen/hosts/weebit1/root.img
dd if=/dev/zero of=/Xen/host/weebit1/swap bs=1024k count=1024
However – DON’T! there’s no need - Have a read through of the instructions here -
xen-create-image –manual
(basically it does everything for you – i.e. creating partitions & swap, formatting, filesystems, xen config file, installing OS)
Then all you need to type is:
xen-create-image –hostname weebit –vcpus 2 –scsi –dist squeeze–pygrub –dir=/Xen/host
(i had tried installing natty first, but was having trouble booting the VM - ran into issues with “ALERT! /dev/sda2 does not exist. Dropping to a shell!“)
With Debian systems, the Xen install doesn’t enable the Ethernet bridging by default so you need to edit /etc/xen/xend-config.sxp and uncomment:
(network-script network-bridge)
(Or when you try to start up your VM later you will run into:
“xm create /etc/xen/weebit.cfg -cError: Device 0 (vif) could not be connected. Could not find bridge, and none was specified“)
Restart Xend
/etc/init.d/xend restart
Once you have your Xen hosts created succesfully, you can start them with a command like:
xm create /etc/xen/weebit.cfg -c (where the cfg file matches the name of the host you created)
I created two VM’s – weebit and weebot – (and my master host is called bitbot) – yes, it gets confusing!
PUPPET SETUP..——————
Okay, two VMs setup with networking, so next thing was setting up Puppet on them – this part was by far the most troublesome – although there is nothing particularly complex about Puppet, it’s error messages aren’t the most verbose or helpful, and I found it quite sensitive to permissions and other peculiarities.
Here’s the main docs:
http://docs.puppetlabs.com/guides/configuring.html
This part is not essential (you can override it in configuration), however a default Puppet install expects the server to be called puppet so it’s best to setup some name resolution -I set it up simply via /etc/hosts.
PUPPET SERVER setup:
apt-get install puppet puppetmaster
update-rc.d puppetmaster defaults
Just to test it locally, run a puppet agent on the server:
puppet agent –test
All looks good, apart from it doesn’t do anything yet. My first test and following with many of the HOWTOs out there was to fix sudoers perms
vi manifests/site.pp
# fixup permissions on sudo
class sudo {
file { “/etc/sudoers”:
owner => root,
group => root,
mode => 440,
}
}
node default {
include sudo
}
In order to give it something to fix, i changed the ownership to my own user and altered the perm:
chown thorsten /etc/sudoers
chmod 400 /etc/sudoers
Ran this again:
puppet agent –test
Nothing! huh. however, running:
puppet apply /etc/puppet/manifests/site.pp
That worked fine. So first lesson – after any config changes – you need to restart Puppet -
/etc/init.d/puppermaster restart
puppet agent –test
notice: /Stage[main]/Sudo/File[/etc/sudoers]/owner: owner changed ‘thorsten’ to ‘root’
Boom! all good.
Now, rather than have a monolithic site manifest, Puppet best practises advocates a modular approach.
“Each module has a specific directory structure that allows Puppet to find all elements of the module and auto-load them.”
mkdir -p /etc/puppet/modules/sudo/manifests
move the ‘sudo’ class logic from site.pp to modules/sudo/manifests/init.pp:
vi modules/sudo/manifests/init.pp
# /etc/puppet/modules/sudo/manifests/init.pp
class sudo {
package { sudo: ensure => latest }
file { “/etc/sudoers”:
owner => root,
group => root,
mode => 440,
source => “puppet:///sudo/sudoers”,
require => Package["sudo"],
}
}
mkdir /etc/puppet/modules/sudo/files
cp /etc/sudoers /etc/puppet/modules/sudo/files
Modules in the modulepath should be auto loaded, however we can explicitly import them too:
# /etc/puppet/manifests/modules.pp
import “sudo”
Move the Node list into manifests/nodes.pp
node default {
include sudo
}
Finally, update site.pp to remove previous statements, and have it import the new modules and nodes .pp files:
# /etc/puppet/manifests/site.pp
import “modules”
import “nodes”
Again, restart Puppetmaster, then test the agent:
puppet agent –test
err: /Stage[main]/Sudo/File[/etc/sudoers]: Could not evaluate: Error 400 on SERVER: Permission denied – /etc/puppet/modules/sudo/files/sudoers Could not retrieve file metadata for puppet:///sudo/sudoers: Error 400 on SERVER: Permission denied – /etc/puppet/modules/sudo/files/sudoers at /etc/puppet/modules/sudo/manifests/init.pp:13
Second lesson! Make sure the modules dir is owned by your Puppet user account:
chown -R puppet modules
puppet agent –test
Cool, all good again!
PUPPET CLIENT INSTALL———-
apt-get install puppet
In order to have it start at boot:
vi /etc/default/puppet
Test it..
puppet agent –server puppet –waitforcert 60 –test
You should see:
info: Requesting certificate
warning: peer certificate won’t be verified in this SSL session
notice: Did not receive certificate
This is the inbuilt security, whereby the server needs to approve and sign the client certificates before they can be administered.
Back on the server type:
puppet cert –list
You should see your client machine listed. To approve it set:
puppet cert –sign weebot
BANG!
Now on your client, you can run:
puppet agent –test
(the –test option adds verbose and no-daemonize to the runtime so you can see whats going on)
You should hopefully see it now install the sudo package on your clients.
I wanted to test adding another package beyond the SUDO setup, so went ahead with NTP
cd /etc/puppet/modules/
mkdir -p ntp/manifests <– WATCH OUT, I ORIGINALLY NAMED THIS ‘MANIFEST’ – SINGULAR – AND IT TOOK ME AGES TO FIND OUT WHY IT WASN’T WORKING
vi ntp/manifests/init.pp
# /etc/puppet/modules/ntp/manifests/init.pp
class ntp {
package { “ntp”:
ensure => installed
}
service { “ntp”:
ensure => running,
}
}
Added ntp to manifests/modules with:
import “ntp”
updated manifests/nodes.pp with:
include ntp
And again -
chown -R puppet modules
/etc/init.d/puppermaster restart
On the clients:
puppet agent –test
So just to summarize – watch your permissions, watch yer typos and remember to restart!
For troubleshooting, puppetmaster logs to /var/log.syslog by default
I searched around for a while to find out whether I would need to set up cron jobs to automate the client, but no, if you set /etc/default/puppet to start at boot, as mentioned above, it will launch and daemonize itself. Default is to run every 30mins. To find out all the default options, run puppet agent –genconfig
HADOOP SETUP————————-
Okay, we have one master node, and two VM’s running, all configured with Puppet. Now to setup Hadoop on them.
There are no Hadoop packages in the standard Debian repositories, so you have to add Cloudera’s manually. They don’t have specific packages for Squeeze yet, but the Lenny ones work fine.
Add the following to your /etc/apt/sources.list on the Master:
#HADOOP
deb http://archive.cloudera.com/debian lenny-cdh3b3 contrib
deb-src http://archive.cloudera.com/debian lenny-cdh3b3 contrib
Then add their public key to your apt keyring:
curl -s http://archive.cloudera.com/debian/archive.key | sudo apt-key add -
apt-get update
and
apt-get install hadoop-0.20
to ensure that all works fine on the server.
All good?
aiiiight..
Okay, so we’ve been using Puppet to configure the VMs, so let’s also add apt.sources to our Puppet configuration:
cd /etc/puppet
mkdir -p modules/apt/manifests
mkdir -p modules/apt/files
cp /etc/apt/sources.list modules/apt/files/
Create:
# /etc/puppet/modules/apt/manifests/init.pp
class apt {
file { “/etc/apt/sources.list”:
owner => root,
group => root,
mode => 644,
source => “puppet:///apt/sources.list”,
}
exec { subscribe-echo:
command => “/usr/bin/apt-get -q -q update”,
logoutput => false,
refreshonly => true,
subscribe => file["/etc/apt/sources.list"]
}
}
chown -R puppet modules/
Add the new entries to:
vi manifests/modules.pp
import “apt”
vi manifests/nodes.pp
include apt
/etc/init.d/puppetmaster restart
At this point, I manually added the cloudera public key to both VMs (same command as above) – probably a smarter way of doing this, but this sufficed for my own efforts:
“curl -s http://archive.cloudera.com/debian/archive.key | sudo apt-key add -”
Again, run the:
puppet client –test
and if the planets are in alignment, your updated sources.list file should be copied over to the clients, and an apt-get update will be run.
Ok, so hopefully just one last step for Hadoop installation. Lets now add a Hadoop class to Puppet:
mkdir -p /etc/puppet/modules/hadoop/manifests
vi /etc/puppet/modules/hadoop/manifests/init.pp
# /etc/puppet/modules/hadoop/manifests/init.pp
class hadoop {
package { “hadoop-0.20″:
ensure => installed
}
}
The now familiar dance..
vi manifests/modules.pp
add import “hadoop”
vi manifests/nodes.pp
add include hadoop
chown -R puppet modules/
/etc/init.d/puppetmaster restart
Moment of truth.. Go to the clients and run our:
puppet agent –test
The following packages have unmet dependencies:
hadoop-0.20 : Depends: sun-java6-jre but it is not going to be installed
Depends: sun-java6-bin but it is not going to be installed
Bugger! You have to accept a user license to use Sun’s (well Oracle now) version of Java, so I had to run ‘apt-get -f install‘ by hand so i could accept Yes on the license. I’m not sure if there is an automated way of doing this or if it is necessary. Again, for my purposes it was fine to just do by hand. If you have a much bigger installation you might want to work out a workaround for this. ( I had already installed Java on my master/physical machine)
So – an almost automated install of Hadoop on a three node cluster! I haven’t configured my cluster with anything useful yet, so I’ll leave that for another article..
thor
#############
The following resources all proved useful :
http://docs.puppetlabs.com/references/latest/configuration.html
http://docs.puppetlabs.com/guides/tools.html
http://docs.puppetlabs.com/man/agent.html
http://bitfieldconsulting.com/puppet-tutorial
http://www.debian-administration.org/articles/526
http://projects.puppetlabs.com/projects/puppet/wiki/Simplest_Puppet_Install_Pattern
http://bitcube.co.uk/content/puppet-errors-explained
http://groups.google.com/group/puppet-users/browse_thread/thread/66361418d801a97c
Disk Destroyer!
Posted: May 10, 2011 | Author: Sideb0ard | Filed under: music, pain, unix | Leave a comment »Today, one of my tasks was identifying and transferring approx 403k MP3 recordings from an office in the states over a VPN to a local NFS mount here in London. Each file is approx 4MB (128kbps files), so a total of ~1,6TB of data.
I tried a few test copies with rsync and scp but both were giving me ridiculous transfer rates, taking ~3mins to transfer 10 test files even though each file individually was achieving around 2.65MB/s. With that transfer rate I should have been able to copy 10files in about 15 seconds. I attribute the extra time to the connection setup and tear down for each file coming through. No way, thats gonna work.
I’ve had several bosses over the years who’ve been complete Unix masters – One of them showed me the wonders of DD – supposedly meaning “Data Description” but also known as “Disk Destroyer” because of how, if you get your Input and Outputs wrong, it can easily (and quietly) destroy your data. (info here).
DD is used for low-level block copying of data, but like many unix tools is quite versatile. My old boss used it for creating files of any specified size, and then timed how long it took to copy across a network link, thereby giving a measurement of transfer rate, which is how i was using it today.
To create a file of 1GB in size:
dd if=/dev/zero of=./1000MB bs=1024 count=1024000
(/dev/zero is a special Unix file which will return as many null characters as you ask it for. It’s of the same family as /dev/null and /dev/full)
Back then, we were using FTP, but these days SCP does actually tell you the transfer rate:
thorsten@invincible:~$ time scp 1000MB foreignhost:
Scp tells me transfer rate was 10.0MB/s however real time says it tooks 1m54sec, so my calculations actually say 8.77MB/s
So, 403k x 4MB = 1612000MB. With a transfer rate of 8.77MB it should take 183808.43 seconds = 3063mins = 2.12 days.
Just over 2 days is acceptable, it is a decent amount of data, and certainly better than 3mins for 10MP3s which would be, what, 121083.3 mins=84 days? phew! Thankfully in this case, there’s a decent amount of space on both servers, so I can tar up the required files up and do a single rsync and hopefully should be able to use the full bandwidth.
Termcap
Posted: May 4, 2011 | Author: Sideb0ard | Filed under: abstraction, history, unix | Tags: abstraction | Leave a comment »Termcap is super ancient Unix tech, from back when terminals were physical hardware devices such as the DEC VT100 or Wyse 60′s connected to Mainframes or Minicomputers. Rather than each program having to know about the capabilities of the terminal being used, such as which Escape/Control characters are used to position the cursor on screen, scroll, colors blinking etc., Termcap was a library and database which abstracted the physical terminal away from the program. It was later replaced by Terminfo back in 1981/82.

So why am i writing about it now? Well, bizarrely, after installing a binary of the *latest* PostgreSQL 9.1 beta today, when i then went to run the psql client program i experienced this:
postgres@invincible:~$ psql -p 5434
Password:
psql (9.1beta1)
Type “help” for help.
Cannot read termcap database;
using dumb terminal settings.
Aborted
d’oh. You can read a thread about the problem here. They mention various workarounds and hacks, but none seemed to work for me on Ubuntu.
I assume this wouldn’t be a problem if you compile from source, it would correctly find and use the ncurses library to discover terminal capabilities, but it also seemed quite a trivial problem and after a little reading up, and strace’ing, it actually worked out quite easy to fix. The infocmp should be installed on your system, which prints out the capabilities of your system from terminfo. Terminfo and Termcap use slightly different variable names to represent capabilites, however if you pass the -C switch to infocmp, it will output the Termcap names for them. Turns out it was as simple as running:
infocmp -C > /etc/termcap
I did this for both xterm and vt100. My exact command sequence was:
root@invincible:~# echo $TERM
xterm
root@invincible:~# infocmp -C > /etc/termcap
root@invincible:~# export TERM=vt100
root@invincible:~# infocmp -C >> /etc/termcap
boom! all good after that..
postgres@invincible:~$ psql -p 5434
Password:
psql (9.1beta1)
Type “help” for help.
postgres=#
If you fancy some historical readings, more info here:
http://tldp.org/HOWTO/Text-Terminal-HOWTO.html#toc16
http://www.delorie.com/gnu/docs/termcap/termcap_toc.html
(Richard Stallman LEGO figure by Andrew Becraft taken under CC licence)
time travelling with Unix
Posted: May 1, 2011 | Author: Sideb0ard | Filed under: history, simulator, unix | 2 Comments »
I discovered Unix back in 1998. At the time i was a lowly Windows desktop support engineer when i started dabbling with Red Hat Linux v 4.2. Compared to the process of fixing Windows 3.1 systems ( i.e. reinstall drivers and reboot – if that doesn’t work, reinstall OS and drivers – repeat until it does work), playing with Linux was a joy of knowledge. Every part of the installation process was a problem hiding a wormhole of required knowledge. Eventually, we managed to start X – very literally, all we had was a grey screen with an ‘X’ to represent the mouse pointer. However, it was addictive – every time you had to fix something, there was a reason for it, and you learned from that experience, and once fixed, it would stay fixed.
So, fast forward 13 years, and I find myself in a wiki loop, reading up on Bell Labs, then early iterations of Unix, and especially Version 7 Unix – http://en.wikipedia.org/wiki/Version_7_Unix – Back in 1998, i had my head full learning Linux and the newly released SunOS 5.7, so even though i was surrounded by older Vax, SGI, and Digital, I didn’t explore much historical software at the time even though i did have a bit of a fixation with the PDP-11.
What caught my eye on the wiki page was this line – “Bootable images for V7 can still be downloaded today, and can be run on modern hosts using PDP-11 emulators such as SIMH.”.
whut??
Yeah! So, this is my step-by-step instructions for compiling SIMH on OS X (Snow Leopard 10.6.7), running the PDP-11 emulator and getting a V7 Unix image up and running on it. There are other HOWTOs out there and the documentation with SIMH does explain all this, but even so, I found it took me several hours of reading and searching to get things working, so I figure theres still room on the internets for what hopefully is a bit more of a concise howto..
You can find the SIMH homepage at:
http://simh.trailing-edge.com/
The SIMH project consists of emulators for a bunch of historical machines, load of DEC machines from the VAX, through to the PDP range, plus IBMs, Honeywell, and even the Altair 8080.
(You can also find a precompiled OS X binary at http://homepage.mac.com/mba/simh/index.html however compiling wasn’t hard, and its all part of the fun, right?!)
First, if you don’t already have it, you’ll need to install Libpcap for network support, which you can get from http://www.tcpdump.org/ - Install libpcap with the usual ./configure, make, make install dance, then download the simh source.
To install on OS X you need to export the OSTYPE environment variable.
(Or you’ll get:
ld: library not found for -lrt
collect2: ld returned 1 exit status
make: *** [BIN/pdp1] Error 1)
export OSTYPE
make USE_NETWORK=1
I encountered my first failure here, no BIN directory. Easily fixed with:
mkdir BIN
make USE_NETWORK=1
./pdp11
After compiling, you can fire up any of the emulators and you’ll find yourself in a sim> shell.
“Now what the hell do i do?” was my first thought.
It took me a bit of reading to understand how to use the simulators, basically they are composed of the devices such as the CPU, disk, memory etc, plus Registers for which you set values. They are quite fully explained in – http://simh.trailing-edge.com/pdf/simh_doc.pdf -
In order to load up any of the software, you have to set some device options, map your software image to a device then load it up. You’ll find the software at:
http://simh.trailing-edge.com/software.html
(and for more thorough explanation, read the doc at http://simh.trailing-edge.com/pdf/simh_swre.pdf)
The correct V7 Unix to run on the PDP-11 is :
http://simh.trailing-edge.com/kits/uv7swre.zip
The instructions given in the documentation are:
sim> set cpu u18
sim> set rl0 RL02
sim> att rl0 unix_v7_rl.dsk
sim> boot rl0
@boot
New Boot, known devices are hp ht rk rl rp tm vt
: rl(0,0)rl2unix
#
They are absolutely correct, however, a gotcha for me was that after i typed “boot rl0” I only got an “@” sign, and nothing more. I thought perhaps i had a corrupt image or something was different with my emulator. But no, i was just being a numpty, you actually need to type “boot” and press return, then type in the “rl(0,0)rl2unix ” line too.
I also had to create a /tmp directory so i could view man pages, but yeah, apart from that, you should be good to go!
I also had fun playing with 2.11 BSD which i got from :
http://ftp.fibranet.cat/UnixArchive/PDP-11/Boot_Images/2.11_on_Simh/
This is a really well put together package, with a clear README file on how to use it.
download, unzip and run as:
./pdp11 211bsd.simh
You can even telnet into your virtual host:
rar!




