Wednesday, February 21, 2024

Bluetooth Low-Energy Devices, Windows and Linux

 I've attempted, many times, to get bluetooth devices paired to multiple OSes simultaneously, on the same machine, and never succeeded. Usually, the OSes involved are Windows and Linux, as I primarily use Linux, but use Windows for certain special apps that require it.

The user 'Mygod' posted a really, really useful GitHub gist, a number of years ago, that solves the problem, rather neatly:
https://gist.github.com/Mygod/f390aabf53cf1406fc71166a47236ebf

The only dependencies are:

  1. having your Windows partition mounted somewhere on your Linux system
  2. installing the 'chntpw' package installed

Once you have both of those, download the script from the gist, which I have included here, for convenience:

#!/usr/bin/python3
"""
Copyright 2021 Mygod

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


What is this: Export your Windows Bluetooth LE keys into Linux!

Thanks to:
* http://console.systems/2014/09/how-to-pair-low-energy-le-bluetooth.html
* https://gist.github.com/corecoding/eac76d3da20c7e427a1848b8aed8e334/revisions#diff-6eeb0d27c24cc10680e8574f75648585

Usage:

$ ./export-ble-infos.py 
$ sudo bash -c 'cp -r ./bluetooth /var/lib && service bluetooth force-reload'
$ rm -r bluetooth
"""

import os
import shutil
import subprocess
import sys
import tempfile

from configparser import ConfigParser
from optparse import OptionParser

default_template = """
[General]
Name=Designer Mouse
Appearance=0x03c2
AddressType=static
SupportedTechnologies=LE;
Trusted=true
Blocked=false
Services=00001800-0000-1000-8000-00805f9b34fb;00001801-0000-1000-8000-00805f9b34fb;0000180a-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb;00001812-0000-1000-8000-00805f9b34fb;

[IdentityResolvingKey]
Key=

[LocalSignatureKey]
Key=
Counter=0
Authenticated=false

[LongTermKey]
Key=
Authenticated=0
EncSize=16
EDiv=
Rand=

[DeviceID]
Source=2
Vendor=1118
Product=2053
Version=272

[ConnectionParameters]
MinInterval=6
MaxInterval=6
Latency=60
Timeout=300
"""


def main():
    parser = OptionParser()
    parser.add_option("-v", "--verbose", action='store_true', dest='verbose')
    parser.add_option("-s", "--system", dest="system", metavar="FILE",
                      default="/mnt/Windows/System32/config/SYSTEM",
                      help="SYSTEM file in Windows. Usually at /Windows/System32/config/system.")
    parser.add_option("-k", "--key", dest="key", metavar="KEY",
                      default=r"ControlSet001\Services\BTHPORT\Parameters\Keys",
                      help="Registry key for BT. [default: %default]")
    parser.add_option("-o", "--output", dest="output", metavar="DIR", default="bluetooth",
                      help="Output directory. [default: %default]")
    parser.add_option("-t", "--template", dest="template", metavar="FILE", help="Template file.")
    parser.add_option("-a", "--attributes", dest='attributes', help="Additional attributes file to be copied.")
    options, args = parser.parse_args()

    if options.template:
        with open(options.template) as file:
            template = file.read()
    else:
        template = default_template

    out = tempfile.mktemp(".reg")
    reged = subprocess.Popen(["reged", "-x", options.system, '\\', options.key, out], stdout=sys.stderr)
    reged.wait()
    if reged.returncode:
        return reged.returncode
    dump = ConfigParser()
    with open(out) as file:
        reged_out = file.read()
        if options.verbose:
            print(reged_out)
        dump.read_string(reged_out.split('\n', 1)[1])
    os.unlink(out)

    for section in dump:
        path = section[len(options.key) + 2:].split('\\')
        assert not path[0]
        if len(path) == 3:
            path[1] = ':'.join([path[1][i:i + 2] for i in range(0, len(path[1]), 2)]).upper()
            path[2] = ':'.join([path[2][i:i + 2] for i in range(0, len(path[2]), 2)]).upper()
            print("Dumping {}/{}...".format(path[1], path[2]))
            config = ConfigParser()
            config.optionxform = str

            # See if device has been paired in Linux before
            existing_template = '/var/lib/bluetooth/{}/{}/info'.format(path[1], path[2])
            if (os.path.exists(existing_template)):
                with open(existing_template) as file:
                    config.read_string(file.read())
            else:
                config.read_string(template)

            def read_reg(key, expected_type):
                def read_reg_actual(key, expected_type):
                    actual_type, content = dump[section]['"{}"'.format(key)].split(':', 1)
                    if expected_type == 'hex16':
                        assert actual_type == 'hex'
                        content = content.split(',')
                        assert len(content) == 16
                        return ''.join(content).upper()
                    if expected_type == 'qword':
                        assert actual_type == 'hex(b)'
                        content = content.split(',')
                        assert len(content) == 8
                        return str(int(''.join(content[::-1]), 16))
                    if expected_type == 'dword':
                        assert actual_type == expected_type
                        return str(int(content, 16))
                    assert False
                result = read_reg_actual(key, expected_type)
                if options.verbose:
                    print("{} of type {}: {}".format(key, expected_type, result))
                return result
            config['LongTermKey']['Key'] = read_reg('LTK', 'hex16')
            # KeyLength ignored for now
            config['LongTermKey']['Rand'] = read_reg('ERand', 'qword')
            config['LongTermKey']['EDiv'] = read_reg('EDIV', 'dword')
            if '"IRK"' in dump[section]:
                config['IdentityResolvingKey']['Key'] = read_reg('IRK', 'hex16')
            if '"CSRK"' in dump[section]:
                config['LocalSignatureKey']['Key'] = read_reg('CSRK', 'hex16')
            output_dir = os.path.join(options.output, path[1], path[2])
            os.makedirs(output_dir, exist_ok=True)
            with open(os.path.join(output_dir, 'info'), 'w') as file:
                config.write(file, False)
            if options.attributes:
                shutil.copyfile(options.attributes, os.path.join(output_dir, 'attributes'))


if __name__ == "__main__":
    sys.exit(main())

Once you have the script copied to your system, do the following, noting that your keys will be different than mine:

$ chmod 0755 export-ble-infos.py
$ ./export-ble-infos.py -s /PATH TO YOUR WINDOWS PARTITION/Windows/System32/config/SYSTEM
reged version 0.1 140201, (c) Petter N Hagen
Exporting to file '/tmp/tmppe0q46xu.reg'...
Exporting key 'Keys' with 1 subkeys and 0 values...
Exporting key '50284a36a81b' with 1 subkeys and 1 values...
Exporting key 'ffffcfd7dd52' with 0 subkeys and 10 values...
Dumping 50:28:4A:36:A8:1B/FF:FF:CF:D7:DD:52...
$ sudo cp -r bluetooth /var/lib/
$ sudo systemctl force-reload bluetooth
Now, your device should be linked on Linux as well as Windows, when you boot each OS.

Thanks MyGod!

- Alex


Wednesday, November 8, 2023

New-to-me Kindle DX Graphite and My Struggles With It

At the VCF Mid Atlantic swap meet, held October 28, 2023, I acquired an Amazon Kindle DX. For some reason, I have always been fascinated with e-kink devices, and ebook readers, specifically. That doesn't mean that I actually read many books on computers, or online, it's just something about the tech that I love.

This particular Kindle DX is a "Kindle DX Graphite", and is in very nice condition, coming wrapped in a fake leather case, which I believe is the stock one from Amazon. The battery was dead, as would be expected for a >13-year-old device, but that was easily replaced. The software side would not be nearly as easy!

When I first powered the Kindle up, it seemed to work fine, showing me leftovers from the previous owner. I immediately factory-reset the device, to make sure that I didn't keep any personal data. Once reset, the Kindle informed me that it needed to be registered, which I figured would be no problem, as I do have an Amazon account, and own quite a number of free and purchased ebooks that are visible in my desktop and iOS Kindle apps. On that front, I could not possibly have been more wrong!

Apparently, the Kindle DX has a 3G modem and SIM card installed, and with the shutdown of the US 3G cellular network, there is no more connectivity. That normally wouldn't be a big deal, but the Kindle DX predates the addition of WiFi to the Kindle line.

Once I discovered this blocker, I went looking for a way around the registration problem, because it blocked my access to most of the settings on the device. I quickly found the MobleRead forum, which has an unbelievable amount of information. That amount of information was somewhat overwhelming for a Kindle newbie like me, but I eventually, through much trial-and-error, figured out how to get this device set up.

For anyone else (or even me, in the future, when I forget all about this!) with a Kindle DX Graphite, here are the steps needed:

  1. All of the links that you need are here, on MobileRead
  2. Jailbreak the Kindle
    1. Download the following archive, and extract it
    2. Connect the Kindle to your PC with a USB micro cable
      1. Make sure the cable has data capability, as many manufacturers cheaped out and made charging-only USB micro cables
    3. Copy the file "Update_jailbreak_0.13.N_dxg_install.bin" to the root directory of the "Kindle" virtual drive that was mounted on your PC
    4. Eject the "Kindle" drive
    5. Press the "Home" button on the Kindle
    6. Press the "Menu" button on the Kindle
    7. Use the joystick to move down to "Settings", and then click the joystick
    8. Press the "Menu" button, again
    9. Use the joystick to select "Update Your Kindle"
      1. If the selection is greyed out, in the menu, you have copied the wrong file. "dxg" refers to the US version of the Kindle DX Graphite. "dx" refers to the original Kindle DX
    10. The Kindle will then install the update and restart.
    11. Once the Kindle is back up, the jailbreak is complete
  3. Install USBNetwork
    1. Download the following archive, and extract it
    2. Connect the Kindle to your PC with a USB micro cable
    3. Copy the file "Update_usbnetwork_0.57.N_dxg_install.bin" to the root directory of the "Kindle" virtual drive that was mounted on your PC
    4. Eject the "Kindle" drive
    5. Press the "Home" button on the Kindle
    6. Press the "Menu" button on the Kindle
    7. Use the joystick to move down to "Settings", and then click the joystick
    8. Press the "Menu" button, again
    9. Use the joystick to select "Update Your Kindle"
    10. The Kindle will then install the update and restart.
    11. Once the Kindle is back up, the USBNetwork installation is complete
  4. Activate USBNetwork
    1. Push the "Del" button on the Kindle's keyboard, to bring up a search field
    2. Type ";debugOn" and press the Kindle's "Return" key (right below "Del", marked with an arrow)
    3. Push the "Del" button on the Kindle's keyboard, to bring up a search field
    4. Type "`usbNetwork" and press the "Return" key
      1. Note that the command starts with a backtick "`" character, and this must be typed
    5. Connect the Kindle to your PC with a USB micro cable
    6. Configure the USB network interface that now appears, as follows:
      1. IP address: 192.168.2.1
      2. Subnet mask: 255.255.255.0
      3. Disable DHCP
    7. Bring the network interface online
  5. Register the Kindle
    1. Using ssh, login to the Kindle as root:
      1. ssh root@192.168.2.2
    2. The password is blank
    3. Type "mntroot rw"
    4. Type "vi /var/local/java/prefs/reginfo" and add the following content to the file:
      1. <?xml version="1.0" encoding="UTF-8"?>                                          
        <response>                                                                      
           <user_device_name> Alex's Kindle DX </user_device_name>                      
           <global_device_name> jjacocks@mac.com </global_device_name>                  
           <given_name> kindledxg </given_name>                                         
           <name> Alex's Kindle </name>                                                 
           <alias>alex</alias>                                                          
        </response>
      2. You can edit the fields to your liking, but make sure that you leave the formatting exactly as I show it
    5. Hit the "Esc" key on your keyboard, and then ":wq" to save the file
    6. Your Kindle should now be registered
    7. As before, reboot, and you are set to go

 Hopefully this helps someone else, as it took a heck of a lot of reading and research and mistakes, on my part, to get this working.

 Here are some links that can get you started:

 

Wednesday, December 7, 2022

NetBSD pkgsrc on Solaris 10/sparc

Anyone who still has a fondness for pre-Oracle Solaris knows the hell that is getting a functional C compiler installed and building common open source packages. One common way to deal with this problem, if you want up-to-date packages, is to use the pkgsrc collection, from the NetBSD project.

pkgsrc has been around for quite some time, having been forked from FreeBSD's ports collection in the late 1990s. Solaris support (initially termed "zoularis", for the initial build script creator, Christos Zoulas) was added just before the new millennium.

The theory is that pkgsrc is easy to get going, and the basic tasks needed are:

  1. download pkgsrc.tar.gz from NetBSD
  2. extract to /usr/pkgsrc
  3. cd to /usr/pkgsrc/bootstrap
  4. run ./bootstrap

Under Solaris 10, though, the system doesn't come with a functional C compiler, making the process a bit of a chicken and egg problem. After doing quite a bit of research, and digging through a lot of blogs, here is the process that worked for me:

  • using the Sun-supported SFW gcc 3.4 and related tools, install a newer version of gcc
    • Set your path to include /usr/sfw/bin and /usr/ccs/bin
# export PATH=/usr/sbin:/usr/bin:/usr/sfw/bin:/usr/ccs/bin
    • I used gcc-9.3.0, which is apparently the final version that supports Solaris 10
# gtar zxvf gcc-9.3.0.tar.gz
# mkdir objdir
# cd objdir
# ~/gcc-9.3.0/configure --enable-obsolete --prefix=/op
t/gcc-9.3.0 --enable-languages=c,c++,fortran

# gmake
# gmake install
    • Add the gcc library directories to the runtime linker paths with crle
# crle -u -l /opt/gcc-9.3.0/lib
# crle -64 -u -l /opt/gcc-9.3.0/lib/sparcv9
    • Grab pkgsrc, I used current stable, which is at the moment 2022-Q3
    • Extract to /usr/pkgsrc
    • Bootstrap pkgsrc
# cd /usr/pkgsrc/bootstrap
      • set your path to include your new gcc and the /usr/ccs/bin tools, like ar, nm and friends and remove /usr/sfw
# export PATH=/usr/sbin:/usr/bin:/opt/gcc-9.3.0/bin:/usr/ccs/bin
# env CFLAGS=-O2 ./bootstrap
    • Once this is complete, add pkgsrc tools to your path
# export PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/sbin:/usr/bin:/opt/gcc-9.3.0/bin:/usr/ccs/bin
    • Edit your pkgsrc mk.conf to use the gcc version that you built
      • Add the following lines to /usr/pkg/etc/mk.conf:
GCCBASE=                /opt/gcc-9.3.0
USE_NATIVE_GCC=         yes
 
 
Now, you should be able to use the NetBSD pkgsrc collection to build a create variety of useful software on Solaris 10.

Sunday, November 20, 2022

IBM PC and Compatible Video Standards: the Early Days

For those who did not use IBM-compatible PCs in the 1980s and 1990s, it may be surprising to hear that there were many, many possible standards of monitors, video cards, and video modes. And many of these were incompatible in both documented and undocumented ways. To start with, we had the IBM-defined original video standards:

  • MDA
    • This was defined by the original IBM Monochrome Display adapter, commonly found in the IBM 5150 PC, 5160 XT, and 5170 AT. It was capable of monochrome text only, in 80 columns by 24 lines.
    • https://www.seasip.info/VintagePC/mda.html
  • CGA
    • The first CGA card was the IBM Color Graphics Adapter, giving the standard its name. CGA was commonly found in the same IBM PCs as MDA, but was also common in early clone PCs, XTs and ATs, as it was significantly cheaper to implement than EGA. CGA was capable of 40 and 80 column text, and multiple graphics modes from 160x100 to 640x200 with monochrome, 2, or 4 colors possible, depending on the mode. The original IBM card, and some clones, supported composite output with 16 colors, at low resolution.
    • https://www.seasip.info/VintagePC/cga.html
  • PC/jr
    • The introduction of the IBM PC/jr in 1983 added support for two new video modes to the CGA standard, 160x200 and 320x200 with 16 colors and 640x200 with 4 colors. This standard would become much more widely used with the introduction of the Tandy 1000 series of personal computers, by Radio Shack.
    • https://en.wikipedia.org/wiki/IBM_PCjr#Video
  • EGA
    • This standard was created by IBM's Enhanced Graphics Adapter. The EGA card was backwards-compatible to both CGA and MDA, and added support for up to 64 colors (with additional video RAM) and resolutions of up to 640x350. There were also 2 RCA-style connectors on the backplate, but they were not designed for CGA-style composite output.
    • https://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter
  • PGA
    • The IBM Professional Graphics Adapter, which supported 640x480 with 256 colors out of a palette of 4096. This is quite a rare card, mostly used for CAD drafting and other high end graphics applications on the IBM PC, XT, and AT. It requires a dedicated monitor, and is not compatible with VGA. It does feature CGA backwards compatibility.
    • https://www.seasip.info/VintagePC/pgc.html
  • VGA
    • This is the IBM Video Graphics Array, which defined the standard for 16 color graphics at a resolution of 640x480 pixels, and 256 colors at 320x200. It produced analog output, rather than the digital output of the MDA, CGA and EGA cards, and used a DE-15 connector, rather than the DE-9 connector used for MDA, CGA and EGA. VGA was backwards-compatible with MDA, CGA and EGA modes, while not being able to be connected to RGBI digital monitors.
    • https://en.wikipedia.org/wiki/Video_Graphics_Array
  • 8514/A
    • IBM introduced the 8514/A adapter in 1987, and it extended the VGA standard with basic graphics acceleration, and a 1024x768 (interlaced) graphics mode. It was available only for the PS/2 line of systems, until compatible clone versions of the card became available.
    • https://en.wikipedia.org/wiki/IBM_8514
  • XGA
    • IBM introduced the XGA display standard of 1024x768 (non-interlaced) pixels at 256 colors, in 1990, again extending the VGA standard. Additionally, XGA (which was again only available for PS/2 systems, supported 64k colors at 640x480, which was a first for IBM original video cards on the PC. Interestingly, XGA, like the 8514, lacked support for 800x600, which was quite common in VGA clone video cards, at the time. There was a minor update to XGA, called XGA-2, which added support for 256 grey scale colors, and finally the addition of 800x600, with up to 64k colors.
    • https://ardent-tool.com/video/XGA1.html

And then, we had a variety of third-party created standards:

  • Hercules monochrome
    • The Hercules Graphics Card was introduced in 1982, having been designed so that its creator could edit his masters thesis in the Thai language. It provided very high resolution (for the time) monochrome graphics at 720x348 and backwards compatible text modes with the IBM MDA card. It was extremely popular, and clones of this card were found in many PCs up until the release of the 486, when most computers were supplied with VGA.
    • https://en.wikipedia.org/wiki/Hercules_Graphics_Card
    • https://www.seasip.info/VintagePC/hercplus.html
  • Plantronics ColorPlus
    • This card was a CGA-compatible video card that added support for 16 colors at 320x200 and 4 colors at 640x200. It was not widely supported, but a surprising number of CGA clone cards supported this standard.
    • https://www.seasip.info/VintagePC/plantronics.html
  • Tandy Graphics
    • Tandy's 1000 line of personal computers were very similar to IBM's failed PC/jr line, in both graphics and sound. They popularized the 320x200 16 color graphics mode, which was very widely supported in video games for DOS.
    • https://en.wikipedia.org/wiki/Tandy_Graphics_Adapter
  • SVGA
    • SVGA was created by the Video Electronics Standards Association (VESA), founded by NEC, in 1988. It popularized the 800x600 video mode, at 16 and 256 colors, and then went on to create official, rather than de-facto, standards for PC-compatible video output formats. 
    • https://en.wikipedia.org/wiki/Super_VGA

There were also a number of other video output standards, most either clones that enhanced CGA, EGA, or VGA.

Is it a wonder that nobody understands IBM PC graphics? What a huge list of somewhat mutually incompatible standards there were!

Saturday, October 15, 2022

Landing Softly with Linux in 1992

From a young age, I have been in love with UNIX, having been exposed to it at my mother’s office. She used to take me with her to the office, when she went into the office, on the weekends. Being a geek, this was nirvana, as my mother was a publisher who worked for a major satellite communications corporation. So, they had almost every type of publishing and graphics related hardware and software that was available, in the 1980s. On one of my earliest visits, my mother left me in front of a Wang-made UNIX System V system, and started Colossal Cave Adventure (ADVENT) for me. I was immediately entranced, and played for hours. Later that afternoon I got my first taste of the shell when I managed to exit from the game.


After that first experience, I pined for my own UNIX workstation. However, being a kid born in the mid 1970s, the cost of such an endeavor was far too large for my own means, and would have to wait for the availability of a free UNIX system that would run on the limited IBM PC clone hardware that I had at my disposal. The Softlanding Linux System, or SLS, for short, was one of the first complete Linux distributions, and was first available in August in 1992. That availability gave me my chance, as I was informed of its release by an older friend who lived in Washington, DC. He even made for me a partial copy of the 3.5” floppy-based installation media, but unfortunately either the copy was damaged, incomplete, or I was too lacking in understanding to get it working. However, that attempt did strongly re-motivate me to get a complete system working.

SLS was available for download from the Internet, or on CD or floppy from the publisher, or most commonly, copied from someone else who had downloaded it. For my second installation attempt, I bought a new box of cheap white-label 3.5” floppy disks from Egghead Software, which was one of the local computer store chains in Maryland, where I grew up. I then took those floppies with me to my high school, where I volunteered in the library and computer programming labs, to image with the new copy of SLS that I downloaded using their (for the time) fast 1.5 Mbps Internet connection. Once I had all of the disk images downloaded, I started creating floppy disks from them. Of course, being inexperienced, I had no idea what disks I would actually need, and which I could skip, so I made them all. This amounted to 22 floppy disks, and this is where I ran into my first significant problem: cheap floppy disks were unreliable! I had no computer, at school, to test the installation on, so every time I wanted to try to replace bad floppy disks, I had to go to Egghead, exchange the failed disks, and return to my high school, on the other side of town. I didn’t have access to a car, so this was all on my bike. Thus, I could make (at most) one attempt per day. It took me several weeks to finally get a complete set of installation media!

Once I had a complete installation set, the real fun began. I can still remember my nervousness as I erased DOS from my 105MB Seagate (yeah, I’m a geek, and I remember the exact hardware that I used!) hard drive, to prepare for the Linux build. Hard drives were very expensive, and I could not afford a second drive, or to get one large enough to also install DOS on. As you might expect, my first installation did not succeed. If my memory is correct, I got all of the software loaded on the system, but the bootloader (the software that starts Linux, when the system is powered on) failed to function properly. I repeated the installation process over and over, until I got a very basic running system.

Folks who didn’t use early Linux probably wonder why I didn’t ask for help, or just look on the Internet for a detailed explanation of the process. In the early 90s, you couldn’t just sign up with an Internet Service Provider, and use your fancy new telephone modem (the predecessor to today’s cable modems) to make a phone connection to the ‘net. In order to have an Internet connection, at the time, one had to be a scientific or educational institution. Commercial access to the Internet didn’t come about until 1995, in any widespread manner. So, I didn’t have anyone to ask, or any easy source of information, since my high school didn’t subscribe to USENET, which is the predecessor to today’s online forums. Because of that lack, I had to complete the process using only the documentation present on the installation media, and trial and error.

With my newly completed base system, I next wanted to be able to use a graphical environment, and not just a text-based command line interface. The system that provided such an interface, at the time, is called the X Window System, and was created by MIT in 1984. There was a version created for PC-based UNIXes, like Linux, and 386/Free/NetBSD, called XFree86, in 1991. That system was included on the installation media for SLS, but it was very much a manual process to configure it. Not only did you need to know exactly what video hardware was in your system, but you had to manually specify the exact parameters of the video signal that you wanted your system to produce. To get the necessary information, you needed to have the instruction manual for your monitor and your video card. If you made an error in the video configuration, not only would you not get a functional graphical environment, you could actually damage your monitor. Given all of this, and the fact that I, like many other computer users of the time, did not buy my monitor or video card new, it took me several weeks to get the X Window System properly configured.

Once the system was up and running, with the graphical user interface functional, I proceeded towards the last obstacle: customizing the Linux kernel. With modern operating systems, including Linux, you no longer have to build your own kernel, but with all UNIX variants until the mid 1990s, kernel compiling was required to add support for your specific hardware configuration. For example, if you wanted to add support for a sound card, like a Sound Blaster, Adlib, or Pro Audio Spectrum, you needed to build a custom kernel. Building the kernel was a mostly straightforward procedure, with one exception: you had to know exactly what hardware was in your system, and how it was configured. There was a large list of yes/no questions that had to be answered correctly, and once complete you could install the new kernel. If you made any errors, the new kernel would fail to boot the system, and you would have to fall back on the previous one (assuming that you hadn’t replaced it!).

With all of these caveats, and the clear complexity, you might well ask yourself why anyone would attempt to install and run Linux, in 1992. The answer varied by the individual, but for me, it gave access to the advanced tools and efficiency of a UNIX system, on PC hardware that were within my budget. All of the difficulties were just part of the journey.

Tuesday, September 20, 2022

Setting Apple Keyboards to Default to Function Keys, Instead of Media Keys

This is just a quick post, but many of y'all may have run into the same issue that I have; that Apple devices default to sending media actions (volume up/down, key backlight, screen brightness, etc.) instead of the normal function key (F1, F2, etc.).

TLDR:

$ echo options hid_apple fnmode=0 | sudo tee -a /etc/modprobe.d/hid_apple.conf

This sets the system to send the scan code for the function key by default, and to send the media action if you press the Fn key, along with the function key.

Friday, December 31, 2021

Setting Up a Networked SunOS 4.1.4 VM in qemu

If you're only interested in the implementation, skip ahead to SETUP.

A Little History

I started my UNIX career at the US National Institutes of Health (NIH). When I first started there, in 1992, I was a student intern with the Office of the Director. I returned, as a student assistant computer specialist, in 1995. At that time, I was given access to an amazing variety of state of the art equipment, including a pair of Sun SPARCstation 2s and a SPARCstation 10, which were exclusively for my use. Given the time period, I installed Solaris 2.x on them, starting with release 2.5. There were still machines around, mostly SS1, SS1+, and SS2 models, running SunOS 4.x, but I didn't have much interaction with them. They were mostly AFS (Andrew file system, an early distributed filesystem standard, created by Carnegie Mellon University) hosts, and were old tech, to me. So, while I saw fellow employees using them, I didn't pay a lot of attention to how they worked.

Interest Surfaces

I have always had an interest in what would be considered vintage equipment, since I didn't have the means to purchase state of the art machines. The first UNIX box that I personally owned was a DECstation 5000/120 that I purchased from Terrapin Trader, the surplus sales group at the University of Maryland, College Park. That machine didn't come with a complete operating system, so I quickly located The NetBSD Project, and the nascent pmax port, just before its first release, in NetBSD 1.1. I did some basic testing, and got my system working around November of 1997. This was my first real interaction with BSD UNIX, in any form. I quickly came to appreciate the extremely open and collaborative nature of NetBSD, and have enjoyed it, in many forms, from then until now. My interest in NetBSD led to investigations into the history of BSD, in general, and to my presentation on "Unusual UNIXes" at the Vintage Computer Festival East 2019.

Setup

So, let's get rolling with some actual shell! To get started, you should make sure that you have qemu built for your system. Here are some links to get you started:

I use qemu on a ton of platforms, but as I type this, I'm on vacation, so I am currently using an Apple MacBook Air (2020/M1). So, I built qemu (with GL acceleration), following the instructions from knazarov's homebrew-qemu-virgl repo. Once I had that running, I created a new folder to store my SPARCstation 5 VM in, and grabbed the necessary components:

$ mkdir sunos-414-sparc
$ cd sunos-414-sparc
$ wget https://fsck.technology/software/Sun%20Microsystems/SunOS%20Install%20Media/SunOS%204.1.4%20SPARC%20%28CD%29/sunos_4.1.4_install.iso
$ wget https://github.com/itomato/NeXTSPARC/raw/master/ROMs/SPARC/ss5.bin

Once I had those, I started the configuration of the VM. Let me first thank KEKLKAKL, who provided a great starting point for this exercise. To get started, I generated the disk that I would be installing SunOS 4.1.4 on, and created my launch script:

$ qemu-img create -f qcow2 -o compat=1.1 sunos414.img 2G
$ cat << EOF > run.sh
> #!/bin/bash
qemu-system-sparc -L . \
-bios ss5.bin \
-m 32 \
-M SS-5 \
-drive file=sunos414.img,format=qcow2,media=disk \
-drive file=sunos_4.1.4_install.iso,format=raw,media=cdrom \
-net nic \
-net user,net=192.168.76.0/24,hostfwd=tcp::2222-:22
> EOF

Notice that I have changed the default network range that qemu provides for user (SLIRP) networking. I did this because I was having issues in getting SunOS to set the netmask correctly for qemu's default 10.0.2.0/24 subnet. I then launched the installation, using ./run.sh, and followed KEKLKAKI's excellent walk-through of the installation of SunOS 4.1.4. During the installation, I chose 192.168.76.15 as the IP address for the VM.

Once that was complete, I rebooted the system, and configured the default gateway. This is a little more difficult than it is in Solaris 2.x/SunOS 5.x, as there is no /etc/defaultrouter file. Instead, we add the following to /etc/rc.local:

$ echo "route add net 0.0.0.0 192.168.76.2 1" >> /etc/rc.local

This adds a default route (0.0.0.0 network) with 192.168.76.2 as the gateway and a metric of 1, since there is one hop to that gateway.

DNS on SunOS 4.1.4

By default, SunOS 4.x does not do DNS, except as a fall-back from NIS. Yes, Sun really wanted everyone to get onboard with NIS, and even expected you to use it for TCP/IP name resolution. So, your options are:

  1. install a NIS/YP server as a DNS proxy
  2. do some library hacking to change the resolution priorities

I chose to do #2, as that sounded a lot more straight-forward. Sun actually wrote up a great document on how to do just that, and I have captured it here. I created the resolv.conf as follows:

 $ echo "nameserver 192.168.76.3" > /etc/resolv.conf

Once you do that, you have a working emulated SPARCstation 5, running SunOS 4.1.4, with functional TCP/IP!