Go Alone
Go Alone 是将 Go 作为一种面向设备的操作系统运行的简短实验。
我们不会在裸机上运行 Go,也不会在 Go 中编写内核 -- 我们使用 Linux,只是用 Go 应用替换用户空间。 所有的用户空间。
单个 Go 应用程序刚刚成为机器的初始化程序 PID 1。 这里没有什么真正困难的,它只是有效。
其中包含的脚本构建了一个最小内核,旨在在 KVM 中运行。 它们甚至不包括对块设备的支持。 采取 12 要素应用程序!
这是运行它们的方法:
# if you have a local clone of linux.git, put it in ~/src/linux/ # to speed up first run ./do-build-kernel # build and run the hello world example app ./do-run-hello-word # build and run the network app and forward port 8000 to it ./do-run-network # in a browser, open http://localhost:8000/ # when done, type control-A x
假定使用 x86_64 平台和 qemu-system-x86_64 的有效安装。
输出应如下所示:
Unpacking initramfs... Freeing initrd memory: 580K (ffff880007f5f000 - ffff880007ff0000) io scheduler noop registered (default) ACPI: PCI Interrupt Link [LNKC] enabled at IRQ 11 Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled 00:05: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A Freeing unused kernel memory: 648K (ffffffff81279000 - ffffffff8131b000) Hello, world! I have 4 CPUs ACPI: Preparing to enter system sleep state S5 reboot: Power down
路线图
- 发挥网络配置的作用
- 也许建立 virtfs
- 可能在 initramfs 中捆绑资产文件和/或配置
- 从临时脚本迁移到实用程序命令,并具有可配置性,例如 RAM 大小。悬而未决的问题:
- 如何处理所需的生成文件?
- 存放在哪里?
- 不可见地缓存,或者将其作为 UI 的一部分?
- 内核可以在许多应用程序之间共享,initramfs 是每个应用程序(版本)
- 快速 cli 想法
# build kernel</span> alone build-kernel [--version=VER] [--mirror=PATH] OUT_PATH # create initramfs alone take INITRAMFS_PATH_TO_CREATE GO_PACKAGE # run the previously-created kernel and initramfs alone exec [--ram=512M] KERNEL INITRAMFS # sort of like `go run`, but takes package. builds kernel if needed alone run [--kernel-version=VER] [--ram=512M] GO_PACKAGE
(The first version translated by vz on 2020.08.01)