366 points · by type0 · 8y ago · 87 comments
(The gokrazy and u-root people all work at Google, I just contacted them to see if we can help each other. Not a competing project.)
Nerves is based on a Buildroot core but most of the system is built with Elixir and BEAM/OTP. It's fantastic having a high level language built for robustness and reasonable security. Still, I have dreams of porting BEAM to Redox OS one day [2] and replacing the C userland-bits with Rust-bits. Especially if you could represent the micro-kernel services as actors. That would be amazing!
1: https://nerves-project.org/ 2: https://github.com/redox-os/redox
Google has created a stack called NERF (Non-Extensible Reduced Firmware) for this:
https://firmwaresecurity.com/2017/07/23/google-nerf-non-exte...
There's a presentation about it on youtube:
gokrazy generates strong passwords by default and listens only on private IP addresses by default to reduce the attack surface.
There are a few Basic, Pascal, Oberon and Java (not Android related) options available, but only a minority cares for them.
Still, big enough to keep those vendors doing business.
Having a minimal bare metal runtime for Go would also be nice, but it is a gigantic effort to make it portable across all types of hardware.
Want something like this for one of the languages that I know... Node.js, Python or Rust. I'd include C++11, though for this kind of deployment method I think one needs packages easily available in a way separate from Linux distro (since there is none).
Instead, a filesystem like btrfs should be used which can give the appearance of multiple versions, yet only use actual storage space where versions differ.
I'd prefer the root filesystem to be something using a FUSE-like layer which can store format specific binary diff/patches between versions, and then transparently apply (and cache) them on access.
Taking it a step further, I wish desktop linux distros had a package-manager-fs, which is a readonly virtual filesystem which displayed all the files installed by all packages, but the underlying real filesystem only contained all the original compressed packages and a cache of recently used files.
But it is very simple and robust. What one tests pre rollout is identical to what will go on production devices, down to the byte. Each device with same version is identical. It can be cryptographically verified easily. Automatic rollback can be performed on update fail, including self-checks.
This approach of shipping a custom userland without any of the generic Linux userland should drastically bring down the size.
The initial installation of the OS is simply done by unzipping a carefully crafted [1] install.zip file to the Raspberry Pi SD card. By exploiting zsync features, it's quite efficient to reconstruct the original install.zip from the unpacked files. Once that's done, all future updates also use zsync and only fetch changes to the locally stored 'install.zip' file. After updating this file we then unpacked everything again to the next A/B partition, so the exact state of the system is always known. Updates are quite small that way. It also helps that the complete OS is only ~37MB compressed at the moment.
[1] The root file system is squashfs and is stored uncompressed in the zip file to avoid double compression and allows zsync to use the squashfs blocksize to find a minimal set of changes. Similarly the initramfs.gz is compressed --rsyncable and also also stored uncompressed in the zip file.
A minimal gokrazy root file system is 16MB in size. On a 8GB SD card, I certainly am willing to sacrifice another 16MB to get A/B updates :).
This is so cool! I’m very happy to learn an effort like this exists, and looking forward to perusing the code for it... in Go (a language I really enjoy reading).
https://github.com/gokrazy/kernel/blob/3ecdc901da51c2c5b6bf7...
Apologies if this is not helpful.
"For a long time, we were unhappy with having to care about security issues and Linux distribution maintenance on our various Raspberry Pis."
But-- there are so many applications for having a full IoT Linux distribution that I can't believe this isn't already a solved problem. I'm imagining an ultra-stable distro that is easy to deploy to a headless machine, handles security updates, handles flaky wi-fi issues, tests the SD card (I've had more than a few burn out on me), and automatically logs to the cloud for easy debugging.
In other words: Why am I still maintaining my RasPis as if they are apache servers from the 1990s?
When your computer runs headless, the init/process tree system is userland. Background (cron) jobs are userland, daemons are userland. Etc.
Why is this choice better than a language that provides memory safety using linear types so you don't even need a runtime or garbage collector?
Not really a huge number, no. Java is probably the most obvious, if you count that as compiled. Maybe Haskell or D? I suppose even Swift of Objective C if you include RC in the definition of GC.
I would say the focus shouldn't be entirely on GC, however. Safety as a whole is the most important factor, and it's possible to be say without GC, as you point out. I reckon Go is actually quite an attractive language for this sort of application regardless – quite safe, quite lightweight, good libraries.
Of course I used my favorite programming language for building gokrazy :).
I really like Go, and suspect a Go app would beat the pants off anything powered by Electron (performance wise).
In case any of periph.io’s features require changes to the kernel configuration, I’m happy to change it accordingly.