Unbelievable: A single-file web server that runs on six OSes • The Register

2022-06-21 10:41:05 By : Ms. Tracy Lei

A bunch of almost unbelievably clever tech tricks come together into something practical with redbean 2: a webserver plus content in a single file that runs on any x86-64 operating system.

The project is the culmination – so far – of a series of remarkable, inspired hacks by programmer Justine Tunney: αcτµαlly pδrταblε εxεcµταblε, Cosmopolitan libc, and the original redbean. It may take a little time to explain what it does, so bear with us. We promise, you will be impressed.

To begin with, redbean uses a remarkable hack known as APE, which stands for Actually Portable Executable – which its author styles αcτµαlly pδrταblε εxεcµταblε. (If you know the Greek alphabet, this reads as "actmally pdrtable execmtable", but hey, it looks cool.)

The gist of the idea of APE is this: whatever programming language you use, if you compile your code to a native binary, it produces x86-64 machine code – and any x86-64 processor runs the same machine code. If you wrote a program that didn't call on any external code at all, then in principle, the only difference between a Windows binary and (say) a Linux binary is the format of the file that contains the binary. So if you could only get around that, your program would be able to run on any OS.

Linux uses a format called Executable and Linkable Format (ELF). In the old days, proprietary x86 Unixes used Common Object File Format or COFF. That's why the recent conversion of Lotus 1-2-3 for Unix to Linux used a tool called coffsyrup to convert COFF to ELF.

The joke in the name APE comes from the fact that Windows NT still uses a format derived from the old COFF standard, called Portable Executable (PE). The PE format is "portable" only inasmuch as if you run a Windows .EXE file under DOS, it will in fact execute: PE files contain a tiny DOS stub which displays the message "This program cannot be run in DOS mode." But "Portable Executables" aren't really portable at all – unlike, say, family applications, which ran natively under both DOS and OS/2.

APE files are, as the name says, Actually Portable Executables. A single APE file executes correctly on any x86-64 operating system. Take the file and run it on Windows, then it acts as a Windows executable. Run the same file on macOS, and it's a macOS executable. Run it on Linux, and it's a Linux binary… and the same on FreeBSD, and OpenBSD, and NetBSD, even though they all have their own, different, executable formats.

The snag is that almost any real program has to call out to some library, even if only the C standard library… which is where the Cosmopolitan libc comes in. "Cosmo" is a libc for APE, so that C programs can be compiled and run on any OS that APE supports.

With Cosmo and the APE format, you can write a C program and compile it to a single file that will load and run on six totally different operating systems. Oh, and if that wasn't enough, the same binary can be booted directly from the PC BIOS, as well. Which means you can run it under Tunney's Blinkenlights, and watch the PC's registers changing live, like an old-time mainframe.

At this point, many techies' minds may well be reeling in astonishment. So, to give you something pretty to look at, there are some demo programs, too. The demo video on the Blinkenlights page shows printimage.com, which can print JPG files on the text console. If you are still not impressed, printvideo.com does the same for video.

The original redbean made the combination of APE and Cosmo into something slightly more useful. After all, amazing as the combination is, having just a libc is quite limiting in the 21st century. You can't build any kind of graphical application, for instance. But every OS that APE supports can run a web browser, so redbean embedded a web server (and SQLite database, and Lua scripting) into a single binary file too. All you need to do is change the file extension to .ZIP, add in your static web content using an archive manager, save it, rename it again, and bingo: self-contained web app.

Think of it as being a little like an Electron app, except that instead of embedding the entire browser into your innocent little program, you use your existing browser.

Now, redbean 2.o (yes, that does say two-dot-oh, not two-dot-zero) takes the original redbean and adds in a REPL – for non-Lispy types, an interactive command line – and a Unix SysV API (yes, even on Windows), plus logging and more.

Talking about Lisp, another of Tunney's astonishing projects is SectorLisp, which embeds a Lisp interpreter into a PC boot sector. SectorLisp 2 adds garbage-collection too, making it the smallest GC language in the world. Given this interest in programs that can be booted directly, without an OS at all, it may not surprise you that a future goal for redbean is to make it bootable: to embed a TCP/IP stack and network-card drivers, for a completely standalone tool. ®

If you don't just take our word for it, and want to try redbean for yourself, then it's worth knowing that there are issues on some operating systems. Recent versions of macOS (11 and 12) break some of the trickery that allows APE to work, as does Ubuntu. The Hacker News discussion about the project and its antecedents contain some workarounds.

Review The Reg FOSS desk took the latest update to openSUSE's stable distro for a spin around the block and returned pleasantly impressed.

As we reported earlier this week, SUSE said it was preparing version 15 SP4 of its SUSE Linux Enterprise distribution at the company's annual conference, and a day later, openSUSE Leap version 15.4 followed.

The relationship between SUSE and the openSUSE project is comparable to that of Red Hat and Fedora. SUSE, with its range of enterprise Linux tools, is the commercial backer, among other sponsors.

It is a truth universally acknowledged that all operating systems suck. Some just suck less than others.

It is also a comment under pretty much every Reg article on Linux that there are too many to choose from and that it's impossible to know which one to try. So we thought we'd simplify things for you by listing how and in which ways the different options suck.

This would be an impossibly long list if we looked at all of them since Distrowatch currently lists 270. So we need to thin the herd a bit.

Comment Recently, The Register's Liam Proven wrote tongue in cheek about the most annoying desktop Linux distros. He inspired me to do another take.

Proven pointed out that Distrowatch currently lists 270 – count 'em – Linux distros. Of course, no one can look at all of those. But, having covered the Linux desktop since the big interface debate was between Bash and zsh rather than GNOME vs KDE, and being the editor-in-chief of a now-departed publication called Linux Desktop, I think I've used more of them than anyone else who also has a life beyond the PC. In short, I love the Linux desktop.

Apple is extending support for its Rosetta 2 x86-64-to-Arm binary translator to Linux VMs running under the forthcoming macOS 13, codenamed Ventura.

The next version of macOS was announced at Apple's World Wide Developer Conference on Monday, and the new release has a number of changes that will be significant to Linux users. The company has disclosed the system requirements for the beta OS, which you can read on the preview page.

One level of Linux relevance is that macOS 13 still supports Intel-based Macs, but only recent ones, made in 2017 and later. So owners of older machines – including the author – will soon be cut off. Some will run Windows on them via Bootcamp, but others will, of course, turn to Linux.

A Linux distro for smartphones abandoned by their manufacturers, postmarketOS, has introduced in-place upgrades.

Alpine Linux is a very minimal general-purpose distro that runs well on low-end kit, as The Reg FOSS desk found when we looked at version 3.16 last month. postmarketOS's – pmOS for short – version 22.06 is based on the same version.

This itself is distinctive. Most other third-party smartphone OSes, such as LineageOS or GrapheneOS, or the former CyanogenMod, are based on the core of Android itself.

Right after the latest release of the KDE Frameworks comes the Plasma Desktop 5.25 plus the default desktop for the forthcoming Linux Mint 23.

Canonical's Linux distro for edge devices and the Internet of Things, Ubuntu Core 22, is out.

This is the fourth release of Ubuntu Core, and as you might guess from the version number, it's based on the current Long Term Support release of Ubuntu, version 22.04.

Ubuntu Core is quite a different product from normal Ubuntu, even the text-only Ubuntu Server. Core has no conventional package manager, just Snap, and the OS itself is built from Snap packages. Snap installations and updates are transactional: this means that either they succeed completely, or the OS automatically rolls them back, leaving no trace except an entry in a log file.

The Linux Mint XApps suite of cross-desktop accessories has a new member – the Timeshift backup tool.

The Linux Mint blog post for June revealed that Mint team lead Clement Lefevbre recently took over maintenance of the Timeshift backup tool used in Linux Mint.

Timeshift is akin to Windows System Restore in that it automatically keeps backups of system files. It's not Mint-specific and was originally developed by Tony George. That name might sound familiar as we recently mentioned his company TeeJeeTech as the creator of the original Unity-based remix, UMix.

Fresh versions of three of the bigger open-source application suites just landed for those seeking to break free from proprietary office apps.

LibreOffice is the highest profile of them, and the project recently put out version 7.3.4, the latest release in the Community version of the suite.

The Document Foundation maintains two versions of LibreOffice; the other is the Enterprise branch.

Intezer security researcher Joakim Kennedy and the BlackBerry Threat Research and Intelligence Team have analyzed an unusual piece of Linux malware they say is unlike most seen before - it isn't a standalone executable file.

Dubbed Symbiote, the badware instead hijacks the environment variable (LD_PRELOAD) the dynamic linker uses to load a shared object library and soon infects every single running process.

The Intezer/BlackBerry team discovered Symbiote in November 2021, and said it appeared to have been written to target financial institutions in Latin America. Analysis of the Symbiote malware and its behavior suggest it may have been developed in Brazil. 

The Register - Independent news and views for the tech community. Part of Situation Publishing

Biting the hand that feeds IT © 1998–2022