Initial ForgeOS project

This commit is contained in:
joe committed 2026-06-16 14:07:52 -04:00
commit 7db7cf1540
42 files changed
+3308

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
# Local Codex/agent state
.agents/
.codex/
# Build and staging outputs
build/
downloads/
out/
sources/
staging/
# Generated boot artifacts and disk images
*.cpio
*.cpio.gz
*.efi
*.EFI
*.img
*.iso
# Generated signing material
*.cer
*.crt
*.key
*.pem
# Local logs and temporary files
*.log
*.tmp
tmp/
+109
View File
@@ -0,0 +1,109 @@
SHELL := /usr/bin/env bash
export ARCH ?= x86_64
export KERNEL_VERSION ?= 7.1
export BUSYBOX_VERSION ?= 1.38.0
export SYSTEMD_VERSION ?= 260
export DBUS_VERSION ?= 1.16.2
export DESKTOP ?= console
export ENABLE_DESKTOP ?= 0
export ROOT_LABEL ?= FORGE_ROOT
export EFI_LABEL ?= FORGE_EFI
desktop_enabled := $(filter 1 true TRUE yes YES on ON,$(ENABLE_DESKTOP))
export IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(desktop_enabled),4096,2048))
export ESP_SIZE_MIB ?= 256
export JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
export SECURE_BOOT ?= 0
export SECURE_BOOT_KEY ?=
export SECURE_BOOT_CERT ?=
export GNOME_SUITE ?= trixie
export GNOME_MIRROR ?= http://deb.debian.org/debian
.PHONY: help fetch kernel busybox systemd dbus rootfs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean
help:
@printf '%s\n' \
'ForgeOS targets:' \
' make fetch - download upstream source tarballs' \
' make kernel - build the Linux kernel and stage modules' \
' make busybox - build BusyBox rescue utilities' \
' make systemd - build systemd PID 1' \
' make dbus - build the D-Bus system bus daemon' \
' make rootfs - assemble the systemd rootfs and initramfs' \
' ENABLE_DESKTOP=1 make rootfs - add Openbox/tint2/PCManFM desktop' \
' make gnome-rootfs - assemble a Debian GNOME desktop rootfs' \
' make image - build a bootable GPT/UEFI disk image' \
' make gnome-image - build a bootable GPT/UEFI GNOME disk image' \
' make secure-boot-keys - generate a local Secure Boot signing keypair' \
' make run - boot kernel + initramfs in QEMU' \
' make run-image - boot the UEFI disk image in QEMU' \
' ENABLE_DESKTOP=1 make run-desktop - boot the Openbox desktop image' \
' make run-gnome - boot the GNOME image in graphical QEMU' \
' make list-disks - list candidate installation disks' \
' sudo make install DISK=/dev/sdX - install ForgeOS to a real disk' \
' make clean - remove build, staging, and output artifacts' \
' make distclean - also remove downloaded and extracted sources'
fetch:
@./scripts/fetch-sources.sh
kernel: fetch
@./scripts/build-kernel.sh
busybox: fetch
@./scripts/build-busybox.sh
systemd: fetch
@./scripts/build-systemd.sh
dbus: fetch
@./scripts/build-dbus.sh
rootfs:
@./scripts/build-rootfs.sh
gnome-rootfs: DESKTOP = gnome
gnome-rootfs: IMAGE_SIZE_MIB = 12288
gnome-rootfs:
@./scripts/build-gnome-rootfs.sh
image:
@./scripts/build-image.sh
gnome-image: DESKTOP = gnome
gnome-image: IMAGE_SIZE_MIB = 12288
gnome-image:
@./scripts/build-image.sh
secure-boot-keys:
@./scripts/generate-secure-boot-keys.sh
run:
@./scripts/run-qemu.sh direct
run-image:
@./scripts/run-qemu.sh image
run-desktop: ENABLE_DESKTOP = 1
run-desktop: IMAGE_SIZE_MIB = 4096
run-desktop: MEMORY_MB = 3072
run-desktop: image
@./scripts/run-qemu.sh image-gui
run-gnome: DESKTOP = gnome
run-gnome: IMAGE_SIZE_MIB = 12288
run-gnome: MEMORY_MB = 4096
run-gnome: gnome-image
@./scripts/run-qemu.sh image-gui
list-disks:
@./scripts/install-to-disk.sh --list
install:
@./scripts/install-to-disk.sh --device "$(DISK)" $(INSTALL_ARGS)
clean:
@./scripts/clean.sh
distclean: clean
@rm -rf downloads sources
+154
View File
@@ -0,0 +1,154 @@
# ForgeOS
ForgeOS is a custom `x86_64` operating system project that defaults to a CLI-only source-built userspace instead of an existing Linux distribution tree. It uses the Linux kernel as the kernel layer, systemd as PID 1, BusyBox as a compact shell/rescue utility set, a custom root filesystem overlay, and direct UEFI boot through the kernel EFI stub. An optional GNOME desktop image flavor is available through a Debian package bootstrap.
As of `2026-06-16`, the project defaults to:
- Linux kernel `7.1`
- systemd `260`
- D-Bus `1.16.2`
- BusyBox `1.38.0`
- `amd64` / `x86_64` only
- 64-bit only
- UEFI boot
- text console only
- optional GNOME desktop image using Debian `trixie` packages
## What This Repository Produces
- a reproducible build pipeline for a from-scratch OS image
- a minimal root filesystem with systemd as `/sbin/init`
- a bootable GPT disk image with:
- an EFI system partition
- an ext4 root partition
- a faster QEMU smoke-test path using `kernel + initramfs`
## Layout
- `config/`: kernel and BusyBox configuration fragments
- `docs/`: architecture and limitations
- `overlay/rootfs/`: files copied into the root filesystem
- `scripts/`: fetch, build, image, and run scripts
## Quick Start
```bash
cd /home/joe/forgeos
make rootfs
make run
```
That path builds the kernel, systemd, D-Bus, BusyBox rescue tools, and a compressed initramfs, then boots it directly in QEMU over serial.
To build a UEFI disk image:
```bash
cd /home/joe/forgeos
make image
make run-image
```
To add a lightweight desktop to the normal ForgeOS rootfs, enable the Openbox desktop layer:
```bash
cd /home/joe/forgeos
ENABLE_DESKTOP=1 make image
ENABLE_DESKTOP=1 make run-desktop
```
This keeps the regular ForgeOS rootfs path and stages Openbox, tint2, PCManFM, Xorg, fonts, icons, and a terminal into it. The serial root shell remains on `ttyS0`; `tty1` starts the desktop session.
To build a GNOME desktop image, install `mmdebstrap` on the host and use the GNOME targets:
```bash
cd /home/joe/forgeos
make gnome-image
make run-gnome
```
The GNOME image uses ForgeOS's kernel and boot image flow with a Debian `trixie` GNOME userspace. The default desktop account is `forge` with password `forge`, and GDM autologin is enabled by default. Override `GNOME_USER`, `GNOME_USER_PASSWORD`, `GNOME_AUTOLOGIN=0`, `GNOME_SUITE`, `GNOME_MIRROR`, or `IMAGE_SIZE_MIB` when building if needed.
To list candidate installation disks:
```bash
cd /home/joe/forgeos
make list-disks
```
To install ForgeOS to a real disk from a Linux host:
```bash
cd /home/joe/forgeos
sudo make install DISK=/dev/nvme0n1
```
## Build Notes
- The root filesystem is not copied from a distro. It is assembled from upstream systemd, upstream D-Bus, upstream BusyBox rescue tools, copied runtime library dependencies for systemd and D-Bus, and the files in `overlay/rootfs/`.
- The default removable-media boot path uses GRUB at `EFI/BOOT/BOOTX64.EFI` and keeps the kernel EFI stub at `EFI/BOOT/FORGEOS.EFI`.
- The built-in kernel command line targets `PARTLABEL=root` and keeps Intel graphics modesetting enabled, with a couple of laptop display workarounds for newer firmware.
- For default direct QEMU testing, `scripts/run-qemu.sh direct` uses the generated `rootfs.cpio.gz`.
- The host-side installer expands the root partition to fill larger target disks.
- systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, early switch-root support, and emergency command-line tools.
- A ForgeOS-native `neofetch` command is included in the overlay with a custom ForgeOS ASCII logo at `/usr/share/neofetch/ascii/distro/forgeos`.
- The console starts an immediate root shell on `tty1` and `ttyS0` through native systemd units instead of BusyBox `inittab`.
- The system bus is provided by source-built `dbus-daemon` and socket-activated at `/run/dbus/system_bus_socket`.
- DHCP networking is handled by `systemd-networkd`; DNS is handled by `systemd-resolved`, with `/etc/resolv.conf` linked to `/run/systemd/resolve/resolv.conf`.
- `ENABLE_DESKTOP=1` adds an Openbox/tint2/PCManFM desktop layer to the normal ForgeOS rootfs by extracting a minimal Debian package payload while preserving the source-built systemd and D-Bus daemons.
- `DESKTOP=gnome` switches rootfs assembly to a Debian package bootstrap because GNOME depends on a large desktop stack that ForgeOS does not source-build yet.
Set `BOOTLOADER=stub` when building an image to use the direct kernel EFI-stub fallback path instead of GRUB.
## Secure Boot Signing
ForgeOS can build a Secure Boot-compatible fallback loader by signing the kernel EFI stub before it is copied to `EFI/BOOT/BOOTX64.EFI`.
Generate a local signing keypair:
```bash
cd /home/joe/forgeos
make secure-boot-keys
```
Build a signed disk image:
```bash
cd /home/joe/forgeos
SECURE_BOOT=1 \
SECURE_BOOT_KEY=out/secure-boot/ForgeOS.key \
SECURE_BOOT_CERT=out/secure-boot/ForgeOS.crt \
make image
```
The host needs `sbsign` for signed builds. Enroll `out/secure-boot/ForgeOS.cer` in the target firmware Secure Boot database, or import it through a trusted shim/MOK flow, before booting the image with Secure Boot enabled. The generated private key should stay private; anyone with it can sign EFI binaries trusted by machines where the certificate is enrolled.
## Toolchain Notes
BusyBox is configured as a static rescue binary by default. If the host toolchain does not provide static libc support, use a musl-capable compiler for the BusyBox part, for example:
```bash
cd /home/joe/forgeos
CC=musl-gcc make rootfs
```
or:
```bash
cd /home/joe/forgeos
CROSS_COMPILE=x86_64-linux-musl- make rootfs
```
systemd and D-Bus are built with Meson/Ninja and staged dynamically. The build copies the ELF runtime library closure from the native build host into the root filesystem, so cross-building the systemd userspace is not supported yet.
## Current Limits
- UEFI only for now; BIOS boot is not implemented.
- The kernel config includes common desktop, laptop, and QEMU storage/input paths, but not every vendor driver.
- Wireless firmware, GPU acceleration, stock Microsoft-trusted Secure Boot/shim integration, audio, and power-management polish are not bundled yet.
- There is no package manager yet.
- The Openbox desktop layer is a staged runtime payload, not an in-OS package manager.
- GNOME support is currently a package-bootstrapped desktop flavor, not a source-built ForgeOS desktop stack.
- The installer is host-side only; there is no in-OS guided installer yet.
More detail is in [docs/ARCHITECTURE.md](/home/joe/forgeos/docs/ARCHITECTURE.md).
Installer usage is documented in [docs/INSTALLER.md](/home/joe/forgeos/docs/INSTALLER.md).
+73
View File
@@ -0,0 +1,73 @@
CONFIG_STATIC=y
CONFIG_FEATURE_INSTALLER=y
CONFIG_FEATURE_SH_STANDALONE=y
CONFIG_FEATURE_PREFER_APPLETS=y
CONFIG_SH_IS_ASH=y
CONFIG_ASH=y
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
CONFIG_ASH_BASH_COMPAT=y
CONFIG_ASH_JOB_CONTROL=y
CONFIG_ASH_ALIAS=y
CONFIG_CAT=y
CONFIG_CHMOD=y
CONFIG_CHOWN=y
CONFIG_CP=y
CONFIG_CUT=y
CONFIG_DATE=y
CONFIG_DD=y
CONFIG_DF=y
CONFIG_DMESG=y
CONFIG_ECHO=y
CONFIG_ENV=y
CONFIG_FIND=y
CONFIG_FREE=y
CONFIG_GREP=y
CONFIG_GUNZIP=y
CONFIG_GZIP=y
CONFIG_HOSTNAME=y
# CONFIG_INIT is not set
CONFIG_IP=y
CONFIG_IPADDR=y
CONFIG_IPLINK=y
CONFIG_IPROUTE=y
CONFIG_KLOGD=y
CONFIG_LESS=y
CONFIG_LN=y
CONFIG_LOGIN=y
CONFIG_LS=y
CONFIG_MDEV=y
CONFIG_FEATURE_MDEV_CONF=y
CONFIG_MKDIR=y
CONFIG_MKNOD=y
CONFIG_MOUNT=y
CONFIG_UMOUNT=y
CONFIG_MV=y
CONFIG_PIDOF=y
CONFIG_PRINTF=y
CONFIG_PS=y
CONFIG_PWD=y
CONFIG_REBOOT=y
CONFIG_ROUTE=y
CONFIG_RM=y
CONFIG_RMDIR=y
CONFIG_SED=y
CONFIG_SLEEP=y
CONFIG_SORT=y
CONFIG_SWITCH_ROOT=y
CONFIG_SYNC=y
CONFIG_SYSLOGD=y
CONFIG_TAIL=y
CONFIG_TAR=y
CONFIG_TEE=y
# CONFIG_TC is not set
CONFIG_TEST=y
CONFIG_TOUCH=y
CONFIG_TR=y
CONFIG_TRUE=y
CONFIG_UDHCPC=y
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
CONFIG_UNAME=y
CONFIG_UNZIP=y
CONFIG_VI=y
CONFIG_XARGS=y
CONFIG_GETTY=y
+92
View File
@@ -0,0 +1,92 @@
CONFIG_LOCALVERSION="-forge"
CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_GZIP=y
CONFIG_RD_XZ=y
CONFIG_CGROUPS=y
CONFIG_CGROUP_SCHED=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CPUSETS=y
CONFIG_MEMCG=y
CONFIG_CGROUP_BPF=y
CONFIG_NAMESPACES=y
CONFIG_CGROUP_NS=y
CONFIG_UTS_NS=y
CONFIG_IPC_NS=y
CONFIG_PID_NS=y
CONFIG_NET_NS=y
CONFIG_USER_NS=y
CONFIG_FHANDLE=y
CONFIG_EPOLL=y
CONFIG_SIGNALFD=y
CONFIG_TIMERFD=y
CONFIG_INOTIFY_USER=y
CONFIG_FANOTIFY=y
CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y
CONFIG_SECCOMP=y
CONFIG_SECCOMP_FILTER=y
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
CONFIG_EFI=y
CONFIG_EFI_STUB=y
CONFIG_EFI_MIXED=y
CONFIG_FB_EFI=y
CONFIG_EFI_PARTITION=y
CONFIG_VT=y
CONFIG_VT_CONSOLE=y
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_DRM=y
CONFIG_DRM_SIMPLEDRM=y
CONFIG_DRM_NOUVEAU=y
CONFIG_DRM_NOUVEAU_BACKLIGHT=y
CONFIG_VGA_SWITCHEROO=y
CONFIG_SYSFB_SIMPLEFB=y
CONFIG_INPUT_EVDEV=y
CONFIG_SERIO_I8042=y
CONFIG_KEYBOARD_ATKBD=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_UNIX98_PTYS=y
CONFIG_PCI=y
CONFIG_PCI_MSI=y
CONFIG_ATA=y
CONFIG_SATA_AHCI=y
CONFIG_SCSI=y
CONFIG_BLK_DEV_SD=y
CONFIG_BLK_DEV_SR=y
CONFIG_CHR_DEV_SG=y
CONFIG_BLK_DEV_NVME=y
CONFIG_NVME_CORE=y
CONFIG_USB_SUPPORT=y
CONFIG_USB_XHCI_HCD=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_OHCI_HCD=y
CONFIG_USB_UHCI_HCD=y
CONFIG_USB_STORAGE=y
CONFIG_VIRTIO=y
CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_BLK=y
CONFIG_VIRTIO_NET=y
CONFIG_VIRTIO_CONSOLE=y
CONFIG_EXT4_FS=y
CONFIG_VFAT_FS=y
CONFIG_FAT_DEFAULT_UTF8=y
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_TMPFS_XATTR=y
CONFIG_AUTOFS_FS=y
CONFIG_NET=y
CONFIG_INET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
CONFIG_E1000=y
CONFIG_E1000E=y
CONFIG_R8169=y
CONFIG_IGB=y
CONFIG_IGC=y
CONFIG_TG3=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="root=PARTLABEL=root rootfstype=ext4 rootwait rw console=tty0 console=ttyS0,115200n8 loglevel=7 ignore_loglevel i915.enable_psr=0 i915.fastboot=0"
# CONFIG_CMDLINE_OVERRIDE is not set
+100
View File
@@ -0,0 +1,100 @@
# ForgeOS Architecture
## Goal
ForgeOS defaults to a CLI-only operating system for `x86_64` desktops and laptops that does not use an existing Linux distribution as its base. It composes upstream projects directly:
- Linux kernel for the kernel layer
- systemd for PID 1 and service supervision
- D-Bus for the system message bus
- BusyBox for `/bin/sh`, early switch-root support, and compact rescue tools
- custom units and configuration files from this repository
There is also an optional `DESKTOP=gnome` image flavor. That flavor keeps the ForgeOS kernel, GRUB/EFI boot flow, image builder, and kernel modules, but uses a Debian `trixie` GNOME userspace because GNOME's dependency closure is much larger than the current source-built ForgeOS userspace.
The normal ForgeOS rootfs can also be built with `ENABLE_DESKTOP=1`. That does not switch to a new OS flavor: it keeps the source-built ForgeOS userspace and stages an Openbox/tint2/PCManFM desktop layer into the same rootfs.
## Boot Model
ForgeOS currently targets UEFI systems.
1. The disk image contains a GPT.
2. Partition 1 is a FAT32 EFI System Partition labeled `FORGE_EFI`.
3. By default, `out/BOOTX64.EFI` is a standalone GRUB UEFI fallback loader with a small debug boot menu.
4. The built kernel EFI stub is copied to `EFI/BOOT/FORGEOS.EFI`.
5. UEFI firmware executes GRUB from `EFI/BOOT/BOOTX64.EFI`, and GRUB starts the kernel.
6. The built-in kernel command line mounts `PARTLABEL=root` as the real root filesystem.
7. systemd starts as `/sbin/init`, activates the D-Bus system bus, starts `systemd-resolved` and `systemd-networkd`, reaches `multi-user.target`, and launches ForgeOS root-shell services on `tty1` and `ttyS0`.
## Root Filesystem Model
The root filesystem is assembled in `staging/rootfs` from:
- systemd install output from `staging/systemd`
- D-Bus install output from `staging/dbus`
- runtime library dependencies copied from the native build host for systemd and D-Bus binaries
- BusyBox install output for shell and rescue utilities
- kernel modules from the kernel build
- the repository overlay in `overlay/rootfs`
The default network path uses DHCP through `systemd-networkd`. DNS servers learned from DHCP are exposed through `systemd-resolved`, and `/etc/resolv.conf` is a symlink to the resolved-managed compatibility file at `/run/systemd/resolve/resolv.conf`. Tools that query systemd over D-Bus use the system bus at `/run/dbus/system_bus_socket`.
The default console build also generates `out/rootfs.cpio.gz` for quick QEMU smoke tests. Desktop-enabled rootfs builds skip the initramfs artifact and boot through the ext4 root partition image.
For `DESKTOP=gnome`, `scripts/build-gnome-rootfs.sh` uses `mmdebstrap` or root-run `debootstrap` to assemble a Debian GNOME root filesystem in `staging/rootfs`, adds ForgeOS identity defaults, creates the initial desktop user, enables GDM and NetworkManager, and copies ForgeOS kernel modules. The GNOME image path deliberately does not copy `rootfs.cpio.gz` into the EFI System Partition because a desktop rootfs is too large for the initramfs-based smoke-test flow.
For `ENABLE_DESKTOP=1`, `scripts/stage-openbox-desktop.sh` asks apt to download the Openbox desktop package closure, extracts only the runtime payloads into `staging/rootfs`, skips base daemon packages that would replace source-built systemd or D-Bus, and enables `forgeos-desktop.service` on `tty1`.
## Why EFI Stub Boot
The project can still boot the kernel EFI stub directly with `BOOTLOADER=stub`, which keeps the implementation smaller and more direct:
- no external distro boot stack
- no dependency on GRUB or systemd-boot
- one kernel artifact doubles as the EFI executable
The tradeoff is that the current implementation depends on a built-in kernel command line.
## Secure Boot Model
ForgeOS supports a signed EFI-stub loader path for machines where the signing certificate has been enrolled in firmware Secure Boot `db`, or imported through a trusted shim/MOK flow.
This does not make ForgeOS trusted by stock Microsoft Secure Boot keys. That would require a Microsoft-signed shim or another trusted first-stage loader. The current project keeps the direct EFI-stub model and signs that EFI executable with a user-controlled key.
## Hardware Scope
The kernel fragment forces built-in support for:
- UEFI boot
- serial and virtual terminals
- devtmpfs
- ext4 and vfat
- GPT partition tables
- AHCI / SATA
- NVMe
- USB storage
- common keyboard and USB input paths
- common QEMU virtio paths
This is enough for a first CLI OS image and a development boot path, but not yet a broad hardware certification matrix.
## Known Gaps
- BIOS boot path
- Microsoft/shim-signed Secure Boot chain
- measured boot and full verified boot
- full laptop Wi-Fi and firmware coverage
- package management
- source-built GNOME and graphical desktop dependency closure
- source-built Openbox/Xorg/GTK graphical dependency closure
- source-built dependency closure for systemd and D-Bus runtime libraries
- user management beyond the root shell
- in-OS guided installer and update system
- hardening review of the kernel and userspace defaults
## Suggested Next Steps
1. Add a source-built libc and dependency sysroot so systemd no longer needs copied host libraries.
2. Teach the installer to support target-specific kernel command lines so multiple ForgeOS disks can coexist more safely.
3. Add network profiles, SSH, and a package/update mechanism.
4. Expand kernel coverage for Wi-Fi, Bluetooth, audio, suspend, and vendor input devices.
+89
View File
@@ -0,0 +1,89 @@
# ForgeOS Installer
ForgeOS currently ships with a host-side installer script:
- [scripts/install-to-disk.sh](/home/joe/forgeos/scripts/install-to-disk.sh)
It installs the built raw ForgeOS image to a real block device from an existing Linux host.
## What It Does
1. validates that the target is a disk
2. refuses to overwrite obvious active system storage
3. optionally unmounts non-critical target partitions
4. writes the ForgeOS raw image to the target disk
5. repairs the GPT backup header on larger disks
6. expands partition `2` and the ext4 root filesystem to fill the device
7. randomizes the ext4 root filesystem UUID by default
## Basic Usage
List candidate disks:
```bash
cd /home/joe/forgeos
make list-disks
```
Install to a disk:
```bash
cd /home/joe/forgeos
sudo make install DISK=/dev/nvme0n1
```
Non-interactive install:
```bash
cd /home/joe/forgeos
sudo make install DISK=/dev/sdc INSTALL_ARGS="--yes --unmount"
```
Install without expanding the root filesystem:
```bash
cd /home/joe/forgeos
sudo make install DISK=/dev/sdc INSTALL_ARGS="--no-expand-root"
```
## Direct Script Usage
```bash
sudo ./scripts/install-to-disk.sh --device /dev/sdc
```
Optional arguments:
- `--image /path/to/forgeos.img`
- `--yes`
- `--unmount`
- `--no-expand-root`
- `--keep-root-uuid`
## Secure Boot Images
To install a Secure Boot-compatible image, build it with a signed EFI loader first:
```bash
cd /home/joe/forgeos
make secure-boot-keys
SECURE_BOOT=1 \
SECURE_BOOT_KEY=out/secure-boot/ForgeOS.key \
SECURE_BOOT_CERT=out/secure-boot/ForgeOS.crt \
make image
sudo make install DISK=/dev/sdc
```
Enroll `out/secure-boot/ForgeOS.cer` in the target firmware Secure Boot database, or through a trusted shim/MOK flow, before booting with Secure Boot enabled. Without that enrollment, firmware should reject `EFI/BOOT/BOOTX64.EFI` even though it is signed.
## Safety Notes
- The installer is destructive. It erases the target disk.
- Run it from a Linux host, not from the disk you are installing over.
- The current boot model uses a built-in kernel command line with `root=PARTLABEL=root`.
- Avoid leaving multiple ForgeOS installations attached during early testing, because multiple disks with the same GPT partition label can confuse root selection.
- Secure Boot trust is tied to the enrolled signing certificate. Protect the generated private key.
## Current Limitation
This is a host-side installer, not an in-OS guided installer yet. There is no partitioning UI, user setup wizard, or live environment workflow in this version.
+9
View File
@@ -0,0 +1,9 @@
root:x:0:
tty:x:5:
disk:x:6:
utmp:x:43:
messagebus:x:81:
systemd-journal:x:190:
systemd-network:x:192:
systemd-resolve:x:193:
nobody:x:65534:
+1
View File
@@ -0,0 +1 @@
forgeos
+1
View File
@@ -0,0 +1 @@
ForgeOS \r (\m)
+3
View File
@@ -0,0 +1,3 @@
# ForgeOS ships a small BusyBox-compatible neofetch implementation.
# Keep this distro name available for tools that read neofetch-style config.
ascii_distro="forgeos"
+3
View File
@@ -0,0 +1,3 @@
NAME=ForgeOS
ID=forgeos
PRETTY_NAME="ForgeOS"
+5
View File
@@ -0,0 +1,5 @@
root::0:0:root:/root:/bin/sh
systemd-network:x:192:192:systemd Network Management:/:/bin/sh
systemd-resolve:x:193:193:systemd Resolver:/:/bin/sh
messagebus:x:81:81:System Message Bus:/:/bin/sh
nobody:x:65534:65534:nobody:/:/bin/sh
+9
View File
@@ -0,0 +1,9 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
PS1='[forgeos \w]# '
export PS1
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
@@ -0,0 +1,6 @@
[Match]
Name=en* eth*
[Network]
DHCP=yes
IPv6AcceptRA=yes
@@ -0,0 +1,15 @@
disable *
enable forgeos-shell@tty1.service
enable forgeos-shell@ttyS0.service
enable forgeos-bootdiag.service
enable forgeos-console-banner.service
enable dbus.service
enable dbus.socket
enable systemd-networkd.service
enable systemd-networkd.socket
enable systemd-resolved.service
enable systemd-resolved-monitor.socket
enable systemd-resolved-varlink.socket
enable systemd-udevd.service
enable systemd-udevd-control.socket
enable systemd-udevd-kernel.socket
@@ -0,0 +1,12 @@
[Unit]
Description=Record ForgeOS boot diagnostics
Documentation=man:systemd.service(5)
After=local-fs.target systemd-udevd.service
ConditionPathExists=/sbin/forgeos-bootdiag
[Service]
Type=oneshot
ExecStart=/sbin/forgeos-bootdiag systemd
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,12 @@
[Unit]
Description=Print ForgeOS console banner
Documentation=man:systemd.service(5)
After=systemd-user-sessions.service
ConditionPathExists=/sbin/forgeos-console-banner
[Service]
Type=oneshot
ExecStart=/sbin/forgeos-console-banner
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,24 @@
[Unit]
Description=ForgeOS root shell on %I
Documentation=man:systemd.service(5)
After=systemd-user-sessions.service
Before=getty.target
IgnoreOnIsolate=yes
[Service]
Type=simple
ExecStart=-/bin/sh -l
Restart=always
RestartSec=0
StandardInput=tty
StandardOutput=tty
StandardError=tty
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
[Install]
WantedBy=getty.target
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
mkdir -p /proc /sys /dev /run
mount -t proc proc /proc 2>/dev/null || true
mount -t sysfs sysfs /sys 2>/dev/null || true
mount -t devtmpfs devtmpfs /dev 2>/dev/null || true
mount -t tmpfs tmpfs /run 2>/dev/null || true
if grep -qw 'forgeos.switch_root=1' /proc/cmdline 2>/dev/null; then
exec /sbin/forgeos-switch-root
fi
exec /sbin/init
+2
View File
@@ -0,0 +1,2 @@
cd /root
exec /bin/sh
+176
View File
@@ -0,0 +1,176 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
STAGE=${1:-userspace}
ESP_MOUNT=/mnt/esp
MARKER_DIR=$ESP_MOUNT/EFI/BOOT/diag
MARKER_FILE=$MARKER_DIR/boot.log
MOUNTED_ESP=0
try_beep() {
command -v beep >/dev/null 2>&1 || return 0
beep -f 880 -l 120 -d 80 -r 2 >/dev/null 2>&1 || true
}
try_led_blink() {
local led
local i
local found=0
for led in /sys/class/leds/*capslock* /sys/class/leds/*numlock*; do
[ -w "$led/brightness" ] || continue
found=1
for i in 1 2 3; do
echo 1 > "$led/brightness" 2>/dev/null || true
sleep 0.15
echo 0 > "$led/brightness" 2>/dev/null || true
sleep 0.15
done
done
[ "$found" -eq 1 ] || return 0
}
try_backlight_on() {
local backlight
local max
for backlight in /sys/class/backlight/*; do
[ -w "$backlight/brightness" ] || continue
max=$(cat "$backlight/max_brightness" 2>/dev/null || true)
case "$max" in
''|*[!0-9]*|0)
continue
;;
esac
echo "$max" > "$backlight/brightness" 2>/dev/null || true
done
}
mount_esp() {
local dev
mkdir -p "$ESP_MOUNT"
MOUNTED_ESP=0
if grep -q " $ESP_MOUNT " /proc/mounts 2>/dev/null; then
return 0
fi
for dev in \
/dev/disk/by-label/FORGE_EFI \
/dev/sd[a-z][0-9] \
/dev/vd[a-z][0-9] \
/dev/nvme[0-9]n[0-9]p[0-9] \
/dev/mmcblk[0-9]p[0-9]; do
[ -b "$dev" ] || continue
mount -t vfat -o rw "$dev" "$ESP_MOUNT" 2>/dev/null || continue
if [ -f "$ESP_MOUNT/EFI/BOOT/FORGEOS.EFI" ]; then
MOUNTED_ESP=1
return 0
fi
umount "$ESP_MOUNT" 2>/dev/null || true
done
return 1
}
print_file() {
local title=$1
local path=$2
echo "--- $title ---"
if [ -r "$path" ]; then
cat "$path" 2>/dev/null || true
else
echo "unavailable: $path"
fi
echo
}
print_cmd() {
local title=$1
shift
echo "--- $title ---"
"$@" 2>/dev/null || true
echo
}
print_framebuffers() {
local fb
local attr
local found=0
echo "--- framebuffer devices ---"
ls -l /dev/fb* 2>/dev/null || true
for fb in /sys/class/graphics/fb*; do
[ -e "$fb" ] || continue
found=1
echo "${fb##*/}:"
for attr in name mode modes virtual_size bits_per_pixel blank state; do
[ -r "$fb/$attr" ] || continue
printf ' %s=' "$attr"
cat "$fb/$attr" 2>/dev/null || true
done
done
[ "$found" -eq 1 ] || echo "no /sys/class/graphics/fb* entries"
echo
}
print_drm_connectors() {
local status
local found=0
echo "--- drm connectors ---"
for status in /sys/class/drm/card*-*/status; do
[ -r "$status" ] || continue
found=1
printf '%s=' "${status%/status}"
cat "$status" 2>/dev/null || true
done
[ "$found" -eq 1 ] || echo "no connector status entries"
echo
}
write_marker() {
mount_esp || return 0
mkdir -p "$MARKER_DIR"
{
echo "=== ForgeOS boot diagnostic ==="
echo "stage=$STAGE"
echo "date=$(date 2>/dev/null || true)"
echo "uname=$(uname -a 2>/dev/null || true)"
echo "cmdline=$(cat /proc/cmdline 2>/dev/null || true)"
echo
print_file "proc consoles" /proc/consoles
print_file "active console" /sys/class/tty/console/active
print_cmd "foreground vt" fgconsole
print_cmd "tty devices" ls -l /dev/console /dev/tty /dev/tty0 /dev/tty1 /dev/ttyS0
print_cmd "block devices" ls -l /dev/sd* /dev/vd* /dev/nvme* /dev/mmcblk*
print_cmd "disk labels" ls -l /dev/disk/by-label /dev/disk/by-partlabel
print_cmd "blkid" blkid
print_cmd "mounts" cat /proc/mounts
print_cmd "drm devices" ls -l /sys/class/drm
print_drm_connectors
print_framebuffers
echo "--- dmesg tail ---"
dmesg 2>/dev/null | tail -n 180 || true
echo
} >> "$MARKER_FILE"
sync
if [ "$MOUNTED_ESP" -eq 1 ]; then
umount "$ESP_MOUNT" 2>/dev/null || true
fi
}
try_beep
try_led_blink
try_backlight_on
write_marker
exit 0
+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
for tty in /dev/tty0 /dev/tty1 /dev/ttyS0 /dev/console; do
[ -w "$tty" ] || continue
{
echo
echo "ForgeOS boot complete: $(uname -r) on $(uname -m)"
echo "Root shell is available on tty1 and ttyS0."
echo
} > "$tty" 2>/dev/null || true
done
+133
View File
@@ -0,0 +1,133 @@
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
NEWROOT=/newroot
ROOT_TIMEOUT=${FORGEOS_ROOT_TIMEOUT:-20}
root_fs_type() {
awk '$2 == "/" { print $3; exit }' /proc/mounts 2>/dev/null
}
in_initramfs() {
case "$(root_fs_type)" in
rootfs|tmpfs)
return 0
;;
*)
return 1
;;
esac
}
console_note() {
local tty
for tty in /dev/tty0 /dev/tty1 /dev/console; do
[ -w "$tty" ] || continue
printf '%s\n' "$*" > "$tty" 2>/dev/null || true
done
}
find_root_device() {
local dev
local info
for dev in /dev/disk/by-partlabel/root /dev/disk/by-label/FORGE_ROOT; do
[ -b "$dev" ] || continue
printf '%s\n' "$dev"
return 0
done
for dev in \
/dev/nvme[0-9]n[0-9]p[0-9] \
/dev/sd[a-z][0-9] \
/dev/mmcblk[0-9]p[0-9] \
/dev/vd[a-z][0-9]; do
[ -b "$dev" ] || continue
info=$(blkid "$dev" 2>/dev/null || true)
case "$info" in
*' PARTLABEL="root"'*|*' LABEL="FORGE_ROOT"'*)
printf '%s\n' "$dev"
return 0
;;
esac
done
return 1
}
wait_for_root_device() {
local attempt
local rootdev
for attempt in $(seq 1 "$ROOT_TIMEOUT"); do
mdev -s 2>/dev/null || true
rootdev=$(find_root_device) || true
if [ -n "$rootdev" ]; then
printf '%s\n' "$rootdev"
return 0
fi
sleep 1
done
return 1
}
is_mounted_newroot() {
grep -q " $NEWROOT " /proc/mounts 2>/dev/null
}
drop_to_rescue() {
local reason=$1
console_note "ForgeOS switch_root failed: $reason"
/sbin/forgeos-bootdiag switch-root-failed || true
if [ "$$" -eq 1 ]; then
exec /sbin/init
fi
return 1
}
if ! grep -qw 'forgeos.switch_root=1' /proc/cmdline 2>/dev/null; then
[ "$$" -eq 1 ] && exec /sbin/init
exit 0
fi
if [ "$$" -ne 1 ]; then
console_note "ForgeOS switch_root skipped: helper is not PID 1"
exit 1
fi
in_initramfs || exec /sbin/init
/sbin/forgeos-bootdiag switch-root-start || true
console_note "ForgeOS initramfs: locating real root filesystem..."
ROOTDEV=$(wait_for_root_device) || drop_to_rescue "root partition not found" || exit 1
mkdir -p "$NEWROOT"
mount -t ext4 -o rw "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
mount -t ext4 -o ro "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
drop_to_rescue "could not mount $ROOTDEV" || exit 1
if ! is_mounted_newroot; then
drop_to_rescue "$NEWROOT was not mounted" || exit 1
fi
if [ ! -x "$NEWROOT/sbin/init" ]; then
umount "$NEWROOT" 2>/dev/null || true
drop_to_rescue "$ROOTDEV does not contain /sbin/init" || exit 1
fi
/sbin/forgeos-bootdiag switch-root-exec || true
console_note "ForgeOS initramfs: switching to $ROOTDEV"
for dir in dev proc sys run; do
mkdir -p "$NEWROOT/$dir"
mount --move "/$dir" "$NEWROOT/$dir" 2>/dev/null || true
done
exec switch_root -c /dev/console "$NEWROOT" /sbin/init
drop_to_rescue "switch_root exec returned"
exit 1
+124
View File
@@ -0,0 +1,124 @@
#!/bin/sh
set -u
show_help() {
cat <<'EOF'
Usage: neofetch [--help] [--version]
Print ForgeOS system information with the ForgeOS ASCII logo.
EOF
}
case "${1:-}" in
--help|-h)
show_help
exit 0
;;
--version|-V)
echo "ForgeOS neofetch 1.0"
exit 0
;;
--*)
echo "neofetch: unsupported option: $1" >&2
exit 1
;;
esac
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
reset="$(printf '\033[0m')"
bold="$(printf '\033[1m')"
logo_color="$(printf '\033[36m')"
key_color="$(printf '\033[1;37m')"
else
reset=''
bold=''
logo_color=''
key_color=''
fi
os_release="${NEOFETCH_OS_RELEASE:-/etc/os-release}"
host_file="${NEOFETCH_HOSTNAME:-/etc/hostname}"
desktop_file="${NEOFETCH_DESKTOP_FILE:-/etc/forgeos-desktop}"
os_name="ForgeOS"
if [ -r "$os_release" ]; then
os_name="$(sed -n 's/^PRETTY_NAME=//p' "$os_release" | head -n 1 | sed 's/^"//;s/"$//')"
[ -n "$os_name" ] || os_name="$(sed -n 's/^NAME=//p' "$os_release" | head -n 1 | sed 's/^"//;s/"$//')"
[ -n "$os_name" ] || os_name="ForgeOS"
fi
host="$(cat "$host_file" 2>/dev/null || hostname 2>/dev/null || echo forgeos)"
kernel="$(uname -sr 2>/dev/null || echo unknown)"
arch="$(uname -m 2>/dev/null || echo unknown)"
shell_name="${SHELL:-/bin/sh}"
terminal="${TERM:-linux}"
init_name="systemd"
desktop="console"
if [ -r "$desktop_file" ]; then
desktop="$(sed -n 's/^NAME=//p' "$desktop_file" | head -n 1 | sed 's/^"//;s/"$//')"
[ -n "$desktop" ] || desktop="Openbox"
fi
uptime_text="unknown"
if [ -r /proc/uptime ]; then
uptime_seconds="$(cut -d. -f1 /proc/uptime 2>/dev/null | awk '{print $1}')"
case "$uptime_seconds" in
''|*[!0-9]*)
;;
*)
days=$((uptime_seconds / 86400))
hours=$(((uptime_seconds % 86400) / 3600))
mins=$(((uptime_seconds % 3600) / 60))
if [ "$days" -gt 0 ]; then
uptime_text="${days}d ${hours}h ${mins}m"
elif [ "$hours" -gt 0 ]; then
uptime_text="${hours}h ${mins}m"
else
uptime_text="${mins}m"
fi
;;
esac
fi
cpu="$arch"
if [ -r /proc/cpuinfo ]; then
cpu="$(sed -n 's/^model name[[:space:]]*:[[:space:]]*//p' /proc/cpuinfo | head -n 1)"
[ -n "$cpu" ] || cpu="$arch"
fi
memory="unknown"
if [ -r /proc/meminfo ]; then
mem_total="$(awk '/^MemTotal:/ {print int($2 / 1024)}' /proc/meminfo)"
mem_available="$(awk '/^MemAvailable:/ {print int($2 / 1024)}' /proc/meminfo)"
if [ -n "$mem_total" ] && [ -n "$mem_available" ]; then
mem_used=$((mem_total - mem_available))
memory="${mem_used}MiB / ${mem_total}MiB"
fi
fi
line() {
logo_line="$1"
label="$2"
value="$3"
if [ -n "$label" ]; then
printf '%b%-37s%b %b%s%b %s\n' "$logo_color" "$logo_line" "$reset" "$key_color" "$label" "$reset" "$value"
else
printf '%b%s%b\n' "$logo_color" "$logo_line" "$reset"
fi
}
printf '%b%s@%s%b\n' "$bold" "${USER:-root}" "$host" "$reset"
line ' ______ ____ _____' 'OS:' "$os_name"
line ' / ____/___ _________ ____ / __ \/ ___/' 'Host:' "$host"
line ' / /_ / __ \/ ___/ __ `/ _ \/ / / /\__ \' 'Kernel:' "$kernel"
line ' / __/ / /_/ / / / /_/ / __/ /_/ /__/ /' 'Uptime:' "$uptime_text"
line '/_/ \____/_/ \__, /\___/\____/____/' 'Shell:' "$shell_name"
line ' /____/' 'Terminal:' "$terminal"
line ' forged from source' 'Desktop:' "$desktop"
line '' 'Init:' "$init_name"
line '' 'CPU:' "$cpu"
line '' 'Memory:' "$memory"
line '' 'Packages:' 'overlay + source-built core'
@@ -0,0 +1,7 @@
______ ____ _____
/ ____/___ _________ ____ / __ \/ ___/
/ /_ / __ \/ ___/ __ `/ _ \/ / / /\__ \
/ __/ / /_/ / / / /_/ / __/ /_/ /__/ /
/_/ \____/_/ \__, /\___/\____/____/
/____/
forged from source
+24
View File
@@ -0,0 +1,24 @@
#!/bin/sh
[ -n "$interface" ] || exit 1
case "$1" in
deconfig)
ip addr flush dev "$interface" 2>/dev/null || true
ip route flush dev "$interface" 2>/dev/null || true
;;
renew|bound)
ifconfig "$interface" 0.0.0.0 2>/dev/null || true
ifconfig "$interface" "$ip" netmask "${subnet:-255.255.255.0}" up
route del default dev "$interface" 2>/dev/null || true
[ -n "${router:-}" ] && route add default gw "$router" dev "$interface" 2>/dev/null || true
[ -n "$dns" ] && {
: > /etc/resolv.conf
for server in $dns; do
echo "nameserver $server" >> /etc/resolv.conf
done
}
;;
esac
exit 0
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd make "$CC" bzip2
ensure_dirs
[[ -d "$BUSYBOX_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh"
msg "configuring BusyBox ${BUSYBOX_VERSION}"
rm -rf "$BUSYBOX_BUILD_DIR"
mkdir -p "$BUSYBOX_BUILD_DIR"
make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" defconfig
apply_kconfig_fragment "$BUSYBOX_BUILD_DIR/.config" "$ROOT_DIR/config/busybox.fragment"
msg "building BusyBox ${BUSYBOX_VERSION}"
make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" CROSS_COMPILE="$CROSS_COMPILE" -j"$JOBS" CC="$CC"
install -Dm755 "$BUSYBOX_BUILD_DIR/busybox" "$OUT_DIR/busybox"
install -Dm644 "$BUSYBOX_BUILD_DIR/.config" "$OUT_DIR/busybox.config"
msg "busybox binary is in $OUT_DIR"
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd meson ninja pkg-config "$CC" file ldd install tar xz
ensure_dirs
[[ -z "$CROSS_COMPILE" ]] || die "D-Bus rootfs staging currently requires a native build; CROSS_COMPILE is not supported"
[[ "$ARCH" == "x86_64" ]] || die "D-Bus rootfs staging currently supports ARCH=x86_64 only"
[[ -d "$DBUS_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh"
copy_runtime_dep() {
local dep=$1
local dest
[[ -e "$dep" ]] || return 0
dest="$DBUS_STAGING_DIR$dep"
mkdir -p "$(dirname "$dest")"
install -Dm755 "$dep" "$dest"
}
copy_elf_deps() {
local elf=$1
local line dep
ldd "$elf" 2>/dev/null | while IFS= read -r line; do
dep=
case "$line" in
*"=>"*"/"*)
dep=${line#*=> }
dep=${dep%% *}
;;
[[:space:]]/*)
dep=${line#"${line%%[![:space:]]*}"}
dep=${dep%% *}
;;
esac
[[ -n "${dep:-}" && "$dep" = /* ]] || continue
copy_runtime_dep "$dep"
done
}
msg "configuring D-Bus ${DBUS_VERSION}"
rm -rf "$DBUS_BUILD_DIR" "$DBUS_STAGING_DIR"
mkdir -p "$DBUS_BUILD_DIR" "$DBUS_STAGING_DIR"
meson setup "$DBUS_BUILD_DIR" "$DBUS_SRC_DIR" \
--prefix=/usr \
--libdir=lib \
--libexecdir=libexec \
--sysconfdir=/etc \
--localstatedir=/var \
--buildtype=release \
-Dmessage_bus=true \
-Dtools=true \
-Dsystemd=enabled \
-Dsystemd_system_unitdir=/usr/lib/systemd/system \
-Dsystemd_user_unitdir=/usr/lib/systemd/user \
-Duser_session=false \
-Ddbus_user=messagebus \
-Druntime_dir=/run \
-Dsystem_socket=/run/dbus/system_bus_socket \
-Dsystem_pid_file=/run/dbus/pid \
-Dsession_socket_dir=/tmp \
-Dtest_socket_dir=/tmp \
-Dtraditional_activation=false \
-Dapparmor=disabled \
-Dselinux=disabled \
-Dlibaudit=disabled \
-Dlaunchd=disabled \
-Dx11_autolaunch=disabled \
-Dinstalled_tests=false \
-Dintrusive_tests=false \
-Dmodular_tests=disabled \
-Ddoxygen_docs=disabled \
-Dducktype_docs=disabled \
-Dxml_docs=disabled \
-Dqt_help=disabled \
-Drelocation=disabled \
-Dvalgrind=disabled \
-Dstats=false
msg "building D-Bus ${DBUS_VERSION}"
meson compile -C "$DBUS_BUILD_DIR" -j "$JOBS"
msg "installing D-Bus ${DBUS_VERSION}"
DESTDIR="$DBUS_STAGING_DIR" meson install -C "$DBUS_BUILD_DIR" --no-rebuild
msg "copying D-Bus runtime library dependencies"
while IFS= read -r -d '' elf; do
file_type=$(file -b "$elf" 2>/dev/null || true)
case "$file_type" in
*ELF*) copy_elf_deps "$elf" ;;
esac
done < <(find "$DBUS_STAGING_DIR" -type f \( -perm /111 -o -name '*.so' -o -name '*.so.*' \) -print0)
[[ -x "$DBUS_STAGING_DIR/usr/bin/dbus-daemon" ]] || die "dbus-daemon binary was not installed"
[[ -S "$DBUS_STAGING_DIR/run/dbus/system_bus_socket" ]] && die "unexpected build-time system bus socket in staging"
touch "$DBUS_STAGING_DIR/.forgeos-dbus-complete"
msg "D-Bus staging tree: $DBUS_STAGING_DIR"
+285
View File
@@ -0,0 +1,285 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd find openssl rsync
ensure_dirs
GNOME_DEBIAN_ARCH=${GNOME_DEBIAN_ARCH:-amd64}
GNOME_COMPONENTS=${GNOME_COMPONENTS:-main,contrib,non-free-firmware}
GNOME_BOOTSTRAP_TOOL=${GNOME_BOOTSTRAP_TOOL:-auto}
GNOME_USER=${GNOME_USER:-forge}
GNOME_USER_UID=${GNOME_USER_UID:-1000}
GNOME_USER_PASSWORD=${GNOME_USER_PASSWORD:-forge}
GNOME_AUTOLOGIN=${GNOME_AUTOLOGIN:-1}
GNOME_PACKAGES=${GNOME_PACKAGES:-systemd-sysv dbus dbus-user-session gnome-core gdm3 network-manager sudo locales xserver-xorg xserver-xorg-video-all xserver-xorg-input-libinput mesa-utils fonts-dejavu firmware-linux-free}
normalize_packages_csv() {
local package_csv
package_csv=${GNOME_PACKAGES//$'\n'/ }
package_csv=${package_csv//$'\t'/ }
package_csv=${package_csv// /,}
while [[ "$package_csv" == *",,"* ]]; do
package_csv=${package_csv//,,/,}
done
package_csv=${package_csv#,}
package_csv=${package_csv%,}
printf '%s\n' "$package_csv"
}
choose_bootstrap_tool() {
case "$GNOME_BOOTSTRAP_TOOL" in
auto)
if command -v mmdebstrap >/dev/null 2>&1; then
printf 'mmdebstrap\n'
elif command -v debootstrap >/dev/null 2>&1; then
printf 'debootstrap\n'
else
die "install mmdebstrap, or install debootstrap and run this target as root"
fi
;;
mmdebstrap|debootstrap)
command -v "$GNOME_BOOTSTRAP_TOOL" >/dev/null 2>&1 || die "missing required command: $GNOME_BOOTSTRAP_TOOL"
printf '%s\n' "$GNOME_BOOTSTRAP_TOOL"
;;
*)
die "unsupported GNOME_BOOTSTRAP_TOOL=$GNOME_BOOTSTRAP_TOOL"
;;
esac
}
cleanup_chroot_mounts() {
local mountpoint
for mountpoint in \
"$ROOTFS_STAGING_DIR/dev/pts" \
"$ROOTFS_STAGING_DIR/dev" \
"$ROOTFS_STAGING_DIR/proc" \
"$ROOTFS_STAGING_DIR/sys"; do
if mountpoint -q "$mountpoint"; then
umount -R "$mountpoint"
fi
done
}
write_apt_sources() {
cat > "$ROOTFS_STAGING_DIR/etc/apt/sources.list" <<EOF
deb $GNOME_MIRROR $GNOME_SUITE ${GNOME_COMPONENTS//,/ }
deb http://security.debian.org/debian-security ${GNOME_SUITE}-security ${GNOME_COMPONENTS//,/ }
deb $GNOME_MIRROR ${GNOME_SUITE}-updates ${GNOME_COMPONENTS//,/ }
EOF
}
bootstrap_with_mmdebstrap() {
local package_csv
require_cmd mmdebstrap
package_csv=$(normalize_packages_csv)
msg "bootstrapping Debian $GNOME_SUITE GNOME rootfs with mmdebstrap"
DEBIAN_FRONTEND=noninteractive mmdebstrap \
--mode=auto \
--variant=apt \
--architectures="$GNOME_DEBIAN_ARCH" \
--components="$GNOME_COMPONENTS" \
--include="$package_csv" \
"$GNOME_SUITE" \
"$ROOTFS_STAGING_DIR" \
"$GNOME_MIRROR"
write_apt_sources
}
bootstrap_with_debootstrap() {
require_cmd apt-get chroot debootstrap mount mountpoint umount
[[ "$EUID" -eq 0 ]] || die "debootstrap mode must run as root; install mmdebstrap for rootless builds"
msg "bootstrapping Debian $GNOME_SUITE base rootfs with debootstrap"
debootstrap \
--arch="$GNOME_DEBIAN_ARCH" \
--components="$GNOME_COMPONENTS" \
"$GNOME_SUITE" \
"$ROOTFS_STAGING_DIR" \
"$GNOME_MIRROR"
write_apt_sources
mount -t proc proc "$ROOTFS_STAGING_DIR/proc"
mount -t sysfs sysfs "$ROOTFS_STAGING_DIR/sys"
mount --rbind /dev "$ROOTFS_STAGING_DIR/dev"
mount --make-rslave "$ROOTFS_STAGING_DIR/dev"
trap cleanup_chroot_mounts EXIT
msg "installing GNOME package set"
chroot "$ROOTFS_STAGING_DIR" env DEBIAN_FRONTEND=noninteractive apt-get update
chroot "$ROOTFS_STAGING_DIR" env DEBIAN_FRONTEND=noninteractive apt-get install -y $GNOME_PACKAGES
chroot "$ROOTFS_STAGING_DIR" env DEBIAN_FRONTEND=noninteractive apt-get clean
cleanup_chroot_mounts
trap - EXIT
}
unit_path() {
local unit=$1
if [[ -e "$ROOTFS_STAGING_DIR/lib/systemd/system/$unit" ]]; then
printf '/lib/systemd/system/%s\n' "$unit"
else
printf '/usr/lib/systemd/system/%s\n' "$unit"
fi
}
ensure_group() {
local group=$1
local gid=$2
local group_file="$ROOTFS_STAGING_DIR/etc/group"
grep -q "^${group}:" "$group_file" || printf '%s:x:%s:\n' "$group" "$gid" >> "$group_file"
}
add_group_member() {
local group=$1
local member=$2
local group_file="$ROOTFS_STAGING_DIR/etc/group"
local line
local name
local password
local gid
local members
line=$(grep "^${group}:" "$group_file" || true)
[[ -n "$line" ]] || return 0
IFS=: read -r name password gid members <<< "$line"
case ",$members," in
*",$member,"*) return 0 ;;
esac
members=${members:+$members,}$member
sed -i "s|^${group}:.*|${name}:${password}:${gid}:${members}|" "$group_file"
}
configure_user() {
local passwd_file="$ROOTFS_STAGING_DIR/etc/passwd"
local shadow_file="$ROOTFS_STAGING_DIR/etc/shadow"
local password_hash
local today
local home_dir="$ROOTFS_STAGING_DIR/home/$GNOME_USER"
ensure_group "$GNOME_USER" "$GNOME_USER_UID"
if ! grep -q "^${GNOME_USER}:" "$passwd_file"; then
printf '%s:x:%s:%s:ForgeOS GNOME User:/home/%s:/bin/bash\n' \
"$GNOME_USER" "$GNOME_USER_UID" "$GNOME_USER_UID" "$GNOME_USER" >> "$passwd_file"
fi
password_hash=$(openssl passwd -6 -salt "$GNOME_USER" "$GNOME_USER_PASSWORD")
today=$(($(date +%s) / 86400))
if grep -q "^${GNOME_USER}:" "$shadow_file"; then
sed -i "s|^${GNOME_USER}:.*|${GNOME_USER}:${password_hash}:${today}:0:99999:7:::|" "$shadow_file"
else
printf '%s:%s:%s:0:99999:7:::\n' "$GNOME_USER" "$password_hash" "$today" >> "$shadow_file"
fi
for group in sudo adm cdrom dip plugdev users video audio netdev; do
add_group_member "$group" "$GNOME_USER"
done
mkdir -p "$home_dir"
chmod 0750 "$home_dir"
if [[ "$EUID" -eq 0 ]]; then
chown -R "$GNOME_USER_UID:$GNOME_USER_UID" "$home_dir"
fi
mkdir -p "$ROOTFS_STAGING_DIR/etc/sudoers.d"
printf '%s ALL=(ALL:ALL) ALL\n' "$GNOME_USER" > "$ROOTFS_STAGING_DIR/etc/sudoers.d/forgeos"
chmod 0440 "$ROOTFS_STAGING_DIR/etc/sudoers.d/forgeos"
}
configure_desktop_services() {
local graphical_target
local gdm_service
local network_manager_service
graphical_target=$(unit_path graphical.target)
gdm_service=$(unit_path gdm3.service)
network_manager_service=$(unit_path NetworkManager.service)
mkdir -p \
"$ROOTFS_STAGING_DIR/etc/systemd/system" \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants"
ln -sfn "$graphical_target" "$ROOTFS_STAGING_DIR/etc/systemd/system/default.target"
if [[ -e "$ROOTFS_STAGING_DIR${gdm_service}" ]]; then
ln -sfn "$gdm_service" "$ROOTFS_STAGING_DIR/etc/systemd/system/display-manager.service"
fi
if [[ -e "$ROOTFS_STAGING_DIR${network_manager_service}" ]]; then
ln -sfn "$network_manager_service" \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/NetworkManager.service"
fi
mkdir -p "$ROOTFS_STAGING_DIR/etc/gdm3"
{
printf '[daemon]\n'
printf 'WaylandEnable=false\n'
if truthy "$GNOME_AUTOLOGIN"; then
printf 'AutomaticLoginEnable=true\n'
printf 'AutomaticLogin=%s\n' "$GNOME_USER"
fi
} > "$ROOTFS_STAGING_DIR/etc/gdm3/daemon.conf"
}
configure_identity() {
mkdir -p "$ROOTFS_STAGING_DIR/etc/default"
printf 'forgeos\n' > "$ROOTFS_STAGING_DIR/etc/hostname"
cat > "$ROOTFS_STAGING_DIR/etc/os-release" <<EOF
NAME=ForgeOS
ID=forgeos
ID_LIKE=debian
PRETTY_NAME="ForgeOS GNOME ($GNOME_SUITE userland)"
VERSION_CODENAME=$GNOME_SUITE
EOF
printf 'LANG=en_US.UTF-8\n' > "$ROOTFS_STAGING_DIR/etc/default/locale"
rm -f "$ROOTFS_STAGING_DIR/etc/machine-id"
: > "$ROOTFS_STAGING_DIR/etc/machine-id"
}
msg "assembling GNOME root filesystem"
BOOTSTRAP_TOOL=$(choose_bootstrap_tool)
[[ "$ARCH" == "x86_64" ]] || die "GNOME rootfs currently supports ARCH=x86_64 only"
[[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
[[ -d "$MODULES_STAGING_DIR/lib/modules" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
if [[ -d "$ROOTFS_STAGING_DIR" ]]; then
rm -rf "$ROOTFS_STAGING_DIR" || die "could not remove $ROOTFS_STAGING_DIR; rerun with sufficient permissions"
fi
mkdir -p "$ROOTFS_STAGING_DIR"
case "$BOOTSTRAP_TOOL" in
mmdebstrap)
bootstrap_with_mmdebstrap
;;
debootstrap)
bootstrap_with_debootstrap
;;
esac
msg "configuring ForgeOS GNOME defaults"
configure_identity
configure_user
configure_desktop_services
mkdir -p "$ROOTFS_STAGING_DIR/lib" "$ROOTFS_STAGING_DIR/boot"
rsync -a "$MODULES_STAGING_DIR/lib/" "$ROOTFS_STAGING_DIR/lib/"
install -Dm644 "$OUT_DIR/bzImage" "$ROOTFS_STAGING_DIR/boot/vmlinuz-${KERNEL_VERSION}-forge"
find "$ROOTFS_STAGING_DIR" -printf '%P\n' | LC_ALL=C sort > "$OUT_DIR/rootfs.manifest"
rm -f "$OUT_DIR/rootfs.cpio.gz"
msg "GNOME rootfs tree: $ROOTFS_STAGING_DIR"
msg "default desktop user: $GNOME_USER"
+214
View File
@@ -0,0 +1,214 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd qemu-img parted mkfs.vfat mkfs.ext4 mcopy mmd dd awk truncate
ensure_dirs
[[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
if [[ "$DESKTOP" == "gnome" ]]; then
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/gdm3/daemon.conf" ]] || "$ROOT_DIR/scripts/build-gnome-rootfs.sh"
else
if truthy "$ENABLE_DESKTOP"; then
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
else
[[ -d "$ROOTFS_STAGING_DIR" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
[[ -f "$OUT_DIR/rootfs.cpio.gz" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
fi
fi
IMAGE_PATH="$OUT_DIR/forgeos-${KERNEL_VERSION}.img"
EFI_LOADER="$OUT_DIR/BOOTX64.EFI"
EFI_KERNEL="$OUT_DIR/FORGEOS.EFI"
EFI_INITRD="$OUT_DIR/rootfs.cpio.gz"
GRUB_CFG="$OUT_DIR/grub.cfg"
ESP_END_MIB=$((1 + ESP_SIZE_MIB))
ESP_IMAGE="$OUT_DIR/forgeos-esp.img"
ROOT_IMAGE="$OUT_DIR/forgeos-root.img"
partition_field() {
local partition=$1
local field=$2
parted -sm "$IMAGE_PATH" unit B print | awk -F: -v part="$partition" -v idx="$field" '
$1 == part {
gsub(/B$/, "", $idx)
print $idx
}
'
}
write_grub_config() {
cat > "$GRUB_CFG" <<'EOF'
set timeout=10
set default=0
terminal_input console
terminal_output console
set gfxmode=1024x768,800x600,auto
set gfxpayload=keep
insmod all_video
insmod gfxterm
terminal_output gfxterm console
set linux_common="root=PARTLABEL=root rootfstype=ext4 rootwait rw console=tty0 loglevel=7 ignore_loglevel earlyprintk=efi,keep vt.global_cursor_default=1"
set initrd_common="rdinit=/sbin/init"
set handoff_common="rdinit=/init forgeos.switch_root=1"
menuentry "ForgeOS - Dell Precision 7720 default" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common i915.enable_psr=0 i915.fastboot=0
}
menuentry "ForgeOS - Intel display only" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common nouveau.modeset=0 i915.enable_psr=0 i915.fastboot=0
}
menuentry "ForgeOS - NVIDIA display only" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common i915.modeset=0
}
menuentry "ForgeOS - firmware framebuffer safe mode" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common nomodeset
}
EOF
if [[ "$DESKTOP" != "gnome" ]] && ! truthy "$ENABLE_DESKTOP"; then
cat >> "$GRUB_CFG" <<'EOF'
menuentry "ForgeOS - initramfs-assisted root default display" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common $handoff_common i915.enable_psr=0 i915.fastboot=0
initrd ($esp)/EFI/BOOT/rootfs.cpio.gz
}
menuentry "ForgeOS - initramfs-assisted root fixed GRUB framebuffer" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
set gfxmode=1024x768
set gfxpayload=keep
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common $handoff_common nomodeset video=efifb:1024x768 fbcon=map:0 fbcon=font:VGA8x16
initrd ($esp)/EFI/BOOT/rootfs.cpio.gz
}
menuentry "ForgeOS - systemd initramfs default display" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common rdinit=/sbin/init i915.enable_psr=0 i915.fastboot=0
initrd ($esp)/EFI/BOOT/rootfs.cpio.gz
}
menuentry "ForgeOS - systemd initramfs framebuffer safe mode" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common $initrd_common nomodeset
initrd ($esp)/EFI/BOOT/rootfs.cpio.gz
}
menuentry "ForgeOS - systemd initramfs fixed GRUB framebuffer" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
set gfxmode=1024x768
set gfxpayload=keep
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common $initrd_common nomodeset video=efifb:1024x768 fbcon=map:0 fbcon=font:VGA8x16
initrd ($esp)/EFI/BOOT/rootfs.cpio.gz
}
menuentry "ForgeOS - EFI stub chainload" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
chainloader ($esp)/EFI/BOOT/FORGEOS.EFI
}
EOF
elif [[ "$DESKTOP" == "gnome" ]]; then
cat >> "$GRUB_CFG" <<'EOF'
menuentry "ForgeOS GNOME - graphical target" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common systemd.unit=graphical.target
}
menuentry "ForgeOS - EFI stub chainload" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
chainloader ($esp)/EFI/BOOT/FORGEOS.EFI
}
EOF
else
cat >> "$GRUB_CFG" <<'EOF'
menuentry "ForgeOS Openbox desktop" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
linux ($esp)/EFI/BOOT/FORGEOS.EFI $linux_common systemd.unit=multi-user.target
}
menuentry "ForgeOS - EFI stub chainload" {
search --no-floppy --file --set=esp /EFI/BOOT/FORGEOS.EFI
chainloader ($esp)/EFI/BOOT/FORGEOS.EFI
}
EOF
fi
}
prepare_efi_loader() {
case "$BOOTLOADER" in
stub)
"$ROOT_DIR/scripts/sign-efi-loader.sh" "$OUT_DIR/bzImage" "$EFI_LOADER"
install -m 0644 "$OUT_DIR/bzImage" "$EFI_KERNEL"
;;
grub)
if truthy "$SECURE_BOOT"; then
die "BOOTLOADER=grub does not support SECURE_BOOT=1 yet; use BOOTLOADER=stub or disable Secure Boot"
fi
require_cmd grub-mkstandalone
write_grub_config
msg "building GRUB UEFI fallback loader"
grub-mkstandalone \
-O x86_64-efi \
-o "$EFI_LOADER" \
--modules="part_gpt fat search search_fs_file linux chain all_video efi_gop efi_uga gfxterm font video video_fb" \
"boot/grub/grub.cfg=$GRUB_CFG" >/dev/null
install -m 0644 "$OUT_DIR/bzImage" "$EFI_KERNEL"
;;
*)
die "unsupported BOOTLOADER=$BOOTLOADER"
;;
esac
}
msg "preparing EFI loader"
prepare_efi_loader
msg "creating raw image $IMAGE_PATH"
rm -f "$IMAGE_PATH" "$ESP_IMAGE" "$ROOT_IMAGE"
qemu-img create -f raw "$IMAGE_PATH" "${IMAGE_SIZE_MIB}M" >/dev/null
parted -s "$IMAGE_PATH" mklabel gpt
parted -s "$IMAGE_PATH" mkpart ESP fat32 1MiB "${ESP_END_MIB}MiB"
parted -s "$IMAGE_PATH" set 1 esp on
parted -s "$IMAGE_PATH" mkpart root ext4 "${ESP_END_MIB}MiB" 100%
ESP_OFFSET=$(partition_field 1 2)
ESP_SIZE=$(partition_field 1 4)
ROOT_OFFSET=$(partition_field 2 2)
ROOT_SIZE=$(partition_field 2 4)
[[ -n "$ESP_OFFSET" && -n "$ESP_SIZE" && -n "$ROOT_OFFSET" && -n "$ROOT_SIZE" ]] || die "failed to parse partition layout"
msg "building EFI partition image"
truncate -s "$ESP_SIZE" "$ESP_IMAGE"
mkfs.vfat -F 32 -n "$EFI_LABEL" "$ESP_IMAGE" >/dev/null
mmd -i "$ESP_IMAGE" ::/EFI
mmd -i "$ESP_IMAGE" ::/EFI/BOOT
mcopy -i "$ESP_IMAGE" "$EFI_LOADER" ::/EFI/BOOT/BOOTX64.EFI
mcopy -i "$ESP_IMAGE" "$EFI_KERNEL" ::/EFI/BOOT/FORGEOS.EFI
if [[ "$DESKTOP" != "gnome" ]] && ! truthy "$ENABLE_DESKTOP"; then
mcopy -i "$ESP_IMAGE" "$EFI_INITRD" ::/EFI/BOOT/rootfs.cpio.gz
fi
msg "building ext4 root partition image"
truncate -s "$ROOT_SIZE" "$ROOT_IMAGE"
mkfs.ext4 -F -L "$ROOT_LABEL" -d "$ROOTFS_STAGING_DIR" "$ROOT_IMAGE" >/dev/null
msg "embedding partitions into raw disk image"
dd if="$ESP_IMAGE" of="$IMAGE_PATH" bs=4M seek="$ESP_OFFSET" oflag=seek_bytes conv=notrunc status=none
dd if="$ROOT_IMAGE" of="$IMAGE_PATH" bs=4M seek="$ROOT_OFFSET" oflag=seek_bytes conv=notrunc status=none
sync
msg "disk image ready: $IMAGE_PATH"
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd make gcc xz
ensure_dirs
[[ -d "$KERNEL_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh"
msg "configuring Linux ${KERNEL_VERSION}"
rm -rf "$MODULES_STAGING_DIR"
mkdir -p "$KERNEL_BUILD_DIR" "$MODULES_STAGING_DIR"
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" x86_64_defconfig
apply_kconfig_fragment "$KERNEL_BUILD_DIR/.config" "$ROOT_DIR/config/kernel.fragment"
cmdline_fragment=$(mktemp)
printf 'CONFIG_CMDLINE="root=PARTLABEL=root rootfstype=ext4 rootwait rw console=tty0 console=ttyS0,115200n8 loglevel=7 ignore_loglevel i915.enable_psr=0 i915.fastboot=0"\n' > "$cmdline_fragment"
apply_kconfig_fragment "$KERNEL_BUILD_DIR/.config" "$cmdline_fragment"
rm -f "$cmdline_fragment"
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" olddefconfig
msg "building Linux ${KERNEL_VERSION}"
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" CROSS_COMPILE="$CROSS_COMPILE" -j"$JOBS" bzImage modules
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" CROSS_COMPILE="$CROSS_COMPILE" INSTALL_MOD_PATH="$MODULES_STAGING_DIR" modules_install
install -Dm644 "$KERNEL_BUILD_DIR/arch/x86/boot/bzImage" "$OUT_DIR/bzImage"
install -Dm644 "$KERNEL_BUILD_DIR/.config" "$OUT_DIR/kernel.config"
install -Dm644 "$KERNEL_BUILD_DIR/System.map" "$OUT_DIR/System.map"
msg "kernel artifacts are in $OUT_DIR"
+103
View File
@@ -0,0 +1,103 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
if [[ "$DESKTOP" == "gnome" ]]; then
exec "$ROOT_DIR/scripts/build-gnome-rootfs.sh"
fi
require_cmd make rsync cpio gzip
ensure_dirs
[[ -x "$BUSYBOX_BUILD_DIR/busybox" ]] || "$ROOT_DIR/scripts/build-busybox.sh"
[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" && -f "$SYSTEMD_STAGING_DIR/.forgeos-systemd-complete" ]] || "$ROOT_DIR/scripts/build-systemd.sh"
[[ -x "$DBUS_STAGING_DIR/usr/bin/dbus-daemon" && -f "$DBUS_STAGING_DIR/.forgeos-dbus-complete" ]] || "$ROOT_DIR/scripts/build-dbus.sh"
[[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
msg "assembling root filesystem"
rm -rf "$ROOTFS_STAGING_DIR"
mkdir -p "$ROOTFS_STAGING_DIR"
make -C "$BUSYBOX_SRC_DIR" O="$BUSYBOX_BUILD_DIR" CONFIG_PREFIX="$ROOTFS_STAGING_DIR" install
rsync -a "$SYSTEMD_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/
rsync -a "$DBUS_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/
mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,boot,mnt,etc/systemd/system}
rsync -a "$OVERLAY_DIR"/ "$ROOTFS_STAGING_DIR"/
rm -f "$ROOTFS_STAGING_DIR/sbin/init"
ln -s ../usr/lib/systemd/systemd "$ROOTFS_STAGING_DIR/sbin/init"
ln -sfn ../../sbin/modprobe "$ROOTFS_STAGING_DIR/usr/bin/modprobe"
ln -sfn ../run/systemd/resolve/resolv.conf "$ROOTFS_STAGING_DIR/etc/resolv.conf"
mkdir -p \
"$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants" \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants" \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants" \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sysinit.target.wants"
ln -sfn /usr/lib/systemd/system/multi-user.target \
"$ROOTFS_STAGING_DIR/etc/systemd/system/default.target"
ln -sfn /etc/systemd/system/forgeos-shell@.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-shell@tty1.service"
ln -sfn /etc/systemd/system/forgeos-shell@.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-shell@ttyS0.service"
ln -sfn /etc/systemd/system/forgeos-bootdiag.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-bootdiag.service"
ln -sfn /etc/systemd/system/forgeos-console-banner.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-console-banner.service"
ln -sfn /usr/lib/systemd/system/systemd-networkd.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/systemd-networkd.service"
ln -sfn /usr/lib/systemd/system/systemd-resolved.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sysinit.target.wants/systemd-resolved.service"
ln -sfn /usr/lib/systemd/system/systemd-networkd.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-networkd.socket"
ln -sfn /usr/lib/systemd/system/systemd-resolved-monitor.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-resolved-monitor.socket"
ln -sfn /usr/lib/systemd/system/systemd-resolved-varlink.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-resolved-varlink.socket"
ln -sfn /usr/lib/systemd/system/systemd-udevd.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sysinit.target.wants/systemd-udevd.service"
ln -sfn /usr/lib/systemd/system/systemd-udevd-control.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-udevd-control.socket"
ln -sfn /usr/lib/systemd/system/systemd-udevd-kernel.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-udevd-kernel.socket"
ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/autovt@.service"
ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/getty@tty1.service"
ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/serial-getty@ttyS0.service"
if [[ -d "$MODULES_STAGING_DIR/lib/modules" ]]; then
mkdir -p "$ROOTFS_STAGING_DIR/lib"
rsync -a "$MODULES_STAGING_DIR/lib/" "$ROOTFS_STAGING_DIR/lib/"
fi
if truthy "$ENABLE_DESKTOP"; then
"$ROOT_DIR/scripts/stage-openbox-desktop.sh"
fi
chmod 755 \
"$ROOTFS_STAGING_DIR/init" \
"$ROOTFS_STAGING_DIR/sbin/forgeos-bootdiag" \
"$ROOTFS_STAGING_DIR/sbin/forgeos-console-banner" \
"$ROOTFS_STAGING_DIR/sbin/forgeos-switch-root" \
"$ROOTFS_STAGING_DIR/usr/bin/neofetch" \
"$ROOTFS_STAGING_DIR/usr/share/udhcpc/default.script"
find "$ROOTFS_STAGING_DIR" -printf '%P\n' | LC_ALL=C sort > "$OUT_DIR/rootfs.manifest"
if truthy "$ENABLE_DESKTOP"; then
rm -f "$OUT_DIR/rootfs.cpio.gz"
msg "rootfs tree: $ROOTFS_STAGING_DIR"
msg "desktop rootfs uses the ext4 image path; initramfs generation skipped"
else
(
cd "$ROOTFS_STAGING_DIR"
find . -print0 | cpio --null -ov --format=newc --owner 0:0 2>/dev/null | gzip -9 > "$OUT_DIR/rootfs.cpio.gz"
)
msg "rootfs tree: $ROOTFS_STAGING_DIR"
msg "initramfs: $OUT_DIR/rootfs.cpio.gz"
fi
+198
View File
@@ -0,0 +1,198 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd meson ninja pkg-config "$CC" file ldd ldconfig install tar gzip
ensure_dirs
[[ -z "$CROSS_COMPILE" ]] || die "systemd rootfs staging currently requires a native build; CROSS_COMPILE is not supported"
[[ "$ARCH" == "x86_64" ]] || die "systemd rootfs staging currently supports ARCH=x86_64 only"
[[ -d "$SYSTEMD_SRC_DIR" ]] || "$ROOT_DIR/scripts/fetch-sources.sh"
copy_runtime_dep() {
local dep=$1
local dest
[[ -e "$dep" ]] || return 0
dest="$SYSTEMD_STAGING_DIR$dep"
mkdir -p "$(dirname "$dest")"
install -Dm755 "$dep" "$dest"
}
copy_elf_deps() {
local elf=$1
local line dep
ldd "$elf" 2>/dev/null | while IFS= read -r line; do
dep=
case "$line" in
*"=>"*"/"*)
dep=${line#*=> }
dep=${dep%% *}
;;
[[:space:]]/*)
dep=${line#"${line%%[![:space:]]*}"}
dep=${dep%% *}
;;
esac
[[ -n "${dep:-}" && "$dep" = /* ]] || continue
copy_runtime_dep "$dep"
done
}
copy_named_library() {
local soname=$1
local path
path=$(ldconfig -p 2>/dev/null | awk -v soname="$soname" '$1 == soname { print $NF; exit }')
[[ -n "$path" ]] || die "could not locate runtime library: $soname"
copy_runtime_dep "$path"
copy_elf_deps "$path"
}
msg "configuring systemd ${SYSTEMD_VERSION}"
rm -rf "$SYSTEMD_BUILD_DIR" "$SYSTEMD_STAGING_DIR"
mkdir -p "$SYSTEMD_BUILD_DIR" "$SYSTEMD_STAGING_DIR"
meson setup "$SYSTEMD_BUILD_DIR" "$SYSTEMD_SRC_DIR" \
--prefix=/usr \
--libdir=lib \
--sysconfdir=/etc \
--localstatedir=/var \
-Dmode=release \
-Dsplit-bin=true \
-Dinitrd=true \
-Dcompat-sysv-interfaces=false \
-Dquotaon-path=/bin/false \
-Dquotacheck-path=/bin/false \
-Dkmod-path=/sbin/modprobe \
-Dkexec-path=/bin/false \
-Dsulogin-path=/sbin/sulogin \
-Dswapon-path=/sbin/swapon \
-Dswapoff-path=/sbin/swapoff \
-Dagetty-path=/sbin/getty \
-Dmount-path=/bin/mount \
-Dumount-path=/bin/umount \
-Dloadkeys-path=/sbin/loadkmap \
-Dsetfont-path=/usr/sbin/setfont \
-Dnologin-path=/usr/sbin/nologin \
-Dsystemd-network-uid=192 \
-Dsystemd-resolve-uid=193 \
-Dadm-group=false \
-Dwheel-group=false \
-Dtests=false \
-Dslow-tests=false \
-Dfuzz-tests=false \
-Dinstall-tests=false \
-Dman=disabled \
-Dhtml=disabled \
-Dtranslations=false \
-Dfirstboot=false \
-Dbinfmt=false \
-Dhibernate=false \
-Dldconfig=false \
-Dresolve=true \
-Defi=false \
-Dtpm=false \
-Drepart=disabled \
-Dsysupdate=disabled \
-Dsysupdated=disabled \
-Dcoredump=false \
-Dpstore=false \
-Doomd=false \
-Dlogind=false \
-Dhostnamed=false \
-Dlocaled=false \
-Dmachined=false \
-Dportabled=false \
-Dsysext=false \
-Dmountfsd=false \
-Duserdb=false \
-Dhomed=disabled \
-Dnetworkd=true \
-Ddefault-network=false \
-Dtimedated=false \
-Dtimesyncd=false \
-Dremote=disabled \
-Dnsresourced=false \
-Dnss-myhostname=false \
-Dnss-mymachines=disabled \
-Dnss-resolve=disabled \
-Dnss-systemd=false \
-Dsysusers=false \
-Dbacklight=false \
-Dvconsole=false \
-Dquotacheck=false \
-Dhwdb=false \
-Drfkill=false \
-Dxdg-autostart=false \
-Dnspawn=disabled \
-Dvmspawn=disabled \
-Dimportd=disabled \
-Dseccomp=disabled \
-Dselinux=disabled \
-Dapparmor=disabled \
-Dsmack=false \
-Dpolkit=disabled \
-Dima=false \
-Dipe=false \
-Dacl=disabled \
-Daudit=disabled \
-Dfdisk=disabled \
-Dkmod=disabled \
-Dpam=disabled \
-Dpasswdqc=disabled \
-Dpwquality=disabled \
-Dmicrohttpd=disabled \
-Dlibcrypt=disabled \
-Dlibcryptsetup=disabled \
-Dlibcryptsetup-plugins=disabled \
-Dlibcurl=disabled \
-Didn=false \
-Dlibidn2=disabled \
-Dqrencode=disabled \
-Dgcrypt=disabled \
-Dgnutls=disabled \
-Dopenssl=disabled \
-Dp11kit=disabled \
-Dlibfido2=disabled \
-Dtpm2=disabled \
-Delfutils=disabled \
-Dbzip2=disabled \
-Dxz=disabled \
-Dlz4=disabled \
-Dzstd=disabled \
-Dxkbcommon=disabled \
-Dpcre2=disabled \
-Dglib=disabled \
-Ddbus=disabled \
-Dlibarchive=disabled \
-Dbootloader=disabled \
-Dkernel-install=false \
-Dukify=disabled \
-Danalyze=false \
-Dbashcompletiondir=no \
-Dzshcompletiondir=no \
-Ddefault-user-shell=/bin/sh
msg "building systemd ${SYSTEMD_VERSION}"
meson compile -C "$SYSTEMD_BUILD_DIR" -j "$JOBS"
msg "installing systemd ${SYSTEMD_VERSION}"
DESTDIR="$SYSTEMD_STAGING_DIR" meson install -C "$SYSTEMD_BUILD_DIR" --no-rebuild
msg "copying systemd runtime library dependencies"
while IFS= read -r -d '' elf; do
file_type=$(file -b "$elf" 2>/dev/null || true)
case "$file_type" in
*ELF*) copy_elf_deps "$elf" ;;
esac
done < <(find "$SYSTEMD_STAGING_DIR" -type f \( -perm /111 -o -name '*.so' -o -name '*.so.*' \) -print0)
copy_named_library libmount.so.1
[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" ]] || die "systemd binary was not installed"
touch "$SYSTEMD_STAGING_DIR/.forgeos-systemd-complete"
msg "systemd staging tree: $SYSTEMD_STAGING_DIR"
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
rm -rf "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR"
msg "removed build, staging, and output directories"
+191
View File
@@ -0,0 +1,191 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
DOWNLOAD_DIR=${DOWNLOAD_DIR:-"$ROOT_DIR/downloads"}
SOURCE_DIR=${SOURCE_DIR:-"$ROOT_DIR/sources"}
BUILD_DIR=${BUILD_DIR:-"$ROOT_DIR/build"}
STAGING_DIR=${STAGING_DIR:-"$ROOT_DIR/staging"}
OUT_DIR=${OUT_DIR:-"$ROOT_DIR/out"}
OVERLAY_DIR=${OVERLAY_DIR:-"$ROOT_DIR/overlay/rootfs"}
ARCH=${ARCH:-x86_64}
KERNEL_VERSION=${KERNEL_VERSION:-7.1}
BUSYBOX_VERSION=${BUSYBOX_VERSION:-1.38.0}
SYSTEMD_VERSION=${SYSTEMD_VERSION:-260}
DBUS_VERSION=${DBUS_VERSION:-1.16.2}
DESKTOP=${DESKTOP:-console}
ENABLE_DESKTOP=${ENABLE_DESKTOP:-0}
ROOT_LABEL=${ROOT_LABEL:-FORGE_ROOT}
EFI_LABEL=${EFI_LABEL:-FORGE_EFI}
case "$DESKTOP" in
console|gnome) ;;
*)
printf 'error: unsupported DESKTOP=%s\n' "$DESKTOP" >&2
exit 1
;;
esac
if [[ -z "${IMAGE_SIZE_MIB:-}" ]]; then
if [[ "$DESKTOP" == "gnome" ]]; then
IMAGE_SIZE_MIB=12288
elif [[ "$ENABLE_DESKTOP" =~ ^(1|true|TRUE|yes|YES|on|ON)$ ]]; then
IMAGE_SIZE_MIB=4096
else
IMAGE_SIZE_MIB=2048
fi
fi
ESP_SIZE_MIB=${ESP_SIZE_MIB:-256}
BOOTLOADER=${BOOTLOADER:-grub}
SECURE_BOOT=${SECURE_BOOT:-0}
SECURE_BOOT_KEY=${SECURE_BOOT_KEY:-}
SECURE_BOOT_CERT=${SECURE_BOOT_CERT:-}
SECURE_BOOT_KEY_DIR=${SECURE_BOOT_KEY_DIR:-"$OUT_DIR/secure-boot"}
SECURE_BOOT_COMMON_NAME=${SECURE_BOOT_COMMON_NAME:-ForgeOS Secure Boot}
JOBS=${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)}
CROSS_COMPILE=${CROSS_COMPILE:-}
CC=${CC:-${CROSS_COMPILE}gcc}
KERNEL_MAJOR=${KERNEL_VERSION%%.*}
KERNEL_TARBALL="linux-${KERNEL_VERSION}.tar.xz"
KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v${KERNEL_MAJOR}.x/${KERNEL_TARBALL}"
BUSYBOX_TARBALL="busybox-${BUSYBOX_VERSION}.tar.bz2"
BUSYBOX_URL="https://busybox.net/downloads/${BUSYBOX_TARBALL}"
SYSTEMD_TARBALL="systemd-v${SYSTEMD_VERSION}.tar.gz"
SYSTEMD_URL="https://github.com/systemd/systemd/archive/refs/tags/v${SYSTEMD_VERSION}.tar.gz"
DBUS_TARBALL="dbus-${DBUS_VERSION}.tar.xz"
DBUS_URL="https://dbus.freedesktop.org/releases/dbus/${DBUS_TARBALL}"
GNOME_SUITE=${GNOME_SUITE:-trixie}
GNOME_MIRROR=${GNOME_MIRROR:-http://deb.debian.org/debian}
OPENBOX_DESKTOP_PACKAGES=${OPENBOX_DESKTOP_PACKAGES:-openbox tint2 pcmanfm xinit xserver-xorg-core xserver-xorg-input-libinput xserver-xorg-video-fbdev xserver-xorg-video-vesa xserver-xorg-video-vmware lxterminal fonts-dejavu adwaita-icon-theme hicolor-icon-theme shared-mime-info}
OPENBOX_DESKTOP_SKIP_PACKAGES=${OPENBOX_DESKTOP_SKIP_PACKAGES:-base-files dbus dbus-bin dbus-daemon dbus-session-bus-common dbus-system-bus-common dbus-user-session debconf dpkg init-system-helpers keyboard-configuration libpam-systemd mount procps systemd systemd-sysv sysvinit-utils tar tzdata udev}
KERNEL_SRC_DIR="$SOURCE_DIR/linux-${KERNEL_VERSION}"
BUSYBOX_SRC_DIR="$SOURCE_DIR/busybox-${BUSYBOX_VERSION}"
SYSTEMD_SRC_DIR="$SOURCE_DIR/systemd-${SYSTEMD_VERSION}"
DBUS_SRC_DIR="$SOURCE_DIR/dbus-${DBUS_VERSION}"
KERNEL_BUILD_DIR="$BUILD_DIR/linux-${KERNEL_VERSION}"
BUSYBOX_BUILD_DIR="$BUILD_DIR/busybox-${BUSYBOX_VERSION}"
SYSTEMD_BUILD_DIR="$BUILD_DIR/systemd-${SYSTEMD_VERSION}"
DBUS_BUILD_DIR="$BUILD_DIR/dbus-${DBUS_VERSION}"
MODULES_STAGING_DIR="$STAGING_DIR/modules"
SYSTEMD_STAGING_DIR="$STAGING_DIR/systemd"
DBUS_STAGING_DIR="$STAGING_DIR/dbus"
ROOTFS_STAGING_DIR="$STAGING_DIR/rootfs"
OPENBOX_DESKTOP_DEB_DIR=${OPENBOX_DESKTOP_DEB_DIR:-"$DOWNLOAD_DIR/openbox-desktop-debs"}
OPENBOX_DESKTOP_APT_STATE_DIR=${OPENBOX_DESKTOP_APT_STATE_DIR:-"$BUILD_DIR/openbox-desktop-apt-state"}
msg() {
printf '==> %s\n' "$*"
}
die() {
printf 'error: %s\n' "$*" >&2
exit 1
}
require_cmd() {
local tool
for tool in "$@"; do
command -v "$tool" >/dev/null 2>&1 || die "missing required command: $tool"
done
}
truthy() {
case "${1:-0}" in
1|true|TRUE|yes|YES|on|ON)
return 0
;;
0|false|FALSE|no|NO|off|OFF|"")
return 1
;;
*)
die "invalid boolean value: $1"
;;
esac
}
ensure_dirs() {
mkdir -p "$DOWNLOAD_DIR" "$SOURCE_DIR" "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR"
}
download() {
local url=$1
local dest=$2
if [[ -f "$dest" ]]; then
msg "using cached $(basename "$dest")"
return
fi
msg "downloading $(basename "$dest")"
curl -L --fail --retry 3 --output "$dest" "$url"
}
extract_tarball() {
local tarball=$1
local target_dir=$2
if [[ -d "$target_dir" ]]; then
msg "using extracted source $(basename "$target_dir")"
return
fi
msg "extracting $(basename "$tarball")"
tar -C "$SOURCE_DIR" -xf "$tarball"
}
extract_tarball_into() {
local tarball=$1
local target_dir=$2
if [[ -d "$target_dir" ]]; then
msg "using extracted source $(basename "$target_dir")"
return
fi
msg "extracting $(basename "$tarball")"
mkdir -p "$target_dir"
tar -C "$target_dir" --strip-components=1 -xf "$tarball"
}
apply_kconfig_fragment() {
local target_config=$1
local fragment=$2
local line key value
[[ -f "$target_config" ]] || die "missing config: $target_config"
[[ -f "$fragment" ]] || die "missing fragment: $fragment"
while IFS= read -r line || [[ -n "$line" ]]; do
[[ -z "$line" ]] && continue
case "$line" in
\#\ CONFIG_*" is not set")
key=${line#\# }
key=${key% is not set}
if grep -q "^${key}=" "$target_config"; then
sed -i "s|^${key}=.*|# ${key} is not set|" "$target_config"
elif ! grep -q "^# ${key} is not set" "$target_config"; then
printf '# %s is not set\n' "$key" >> "$target_config"
fi
;;
CONFIG_*=*)
key=${line%%=*}
value=${line#*=}
if grep -q "^${key}=" "$target_config"; then
sed -i "s|^${key}=.*|${key}=${value}|" "$target_config"
elif grep -q "^# ${key} is not set" "$target_config"; then
sed -i "s|^# ${key} is not set|${key}=${value}|" "$target_config"
else
printf '%s=%s\n' "$key" "$value" >> "$target_config"
fi
;;
esac
done < "$fragment"
}
cleanup_path() {
local path=$1
[[ -e "$path" ]] && rm -rf "$path"
}
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd curl tar
ensure_dirs
download "$KERNEL_URL" "$DOWNLOAD_DIR/$KERNEL_TARBALL"
download "$BUSYBOX_URL" "$DOWNLOAD_DIR/$BUSYBOX_TARBALL"
download "$SYSTEMD_URL" "$DOWNLOAD_DIR/$SYSTEMD_TARBALL"
download "$DBUS_URL" "$DOWNLOAD_DIR/$DBUS_TARBALL"
extract_tarball "$DOWNLOAD_DIR/$KERNEL_TARBALL" "$KERNEL_SRC_DIR"
extract_tarball "$DOWNLOAD_DIR/$BUSYBOX_TARBALL" "$BUSYBOX_SRC_DIR"
extract_tarball_into "$DOWNLOAD_DIR/$SYSTEMD_TARBALL" "$SYSTEMD_SRC_DIR"
extract_tarball "$DOWNLOAD_DIR/$DBUS_TARBALL" "$DBUS_SRC_DIR"
msg "sources are ready"
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
KEY_DIR=$SECURE_BOOT_KEY_DIR
FORCE=0
usage() {
cat <<'EOF'
Usage:
generate-secure-boot-keys.sh [options]
Options:
--dir PATH Output directory. Defaults to out/secure-boot.
--common-name NAME Certificate common name.
--force Replace existing generated files.
--help Show this help text.
Generated files:
ForgeOS.key Private signing key. Keep this secret.
ForgeOS.crt PEM X.509 certificate for sbsign.
ForgeOS.cer DER X.509 certificate for firmware/MOK import.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--dir)
[[ $# -ge 2 ]] || die "--dir requires a value"
KEY_DIR=$2
shift 2
;;
--common-name)
[[ $# -ge 2 ]] || die "--common-name requires a value"
SECURE_BOOT_COMMON_NAME=$2
shift 2
;;
--force)
FORCE=1
shift
;;
--help|-h)
usage
exit 0
;;
*)
die "unknown option: $1"
;;
esac
done
require_cmd openssl
mkdir -p "$KEY_DIR"
KEY_PATH="$KEY_DIR/ForgeOS.key"
CERT_PEM="$KEY_DIR/ForgeOS.crt"
CERT_DER="$KEY_DIR/ForgeOS.cer"
if [[ "$FORCE" -ne 1 ]]; then
for path in "$KEY_PATH" "$CERT_PEM" "$CERT_DER"; do
[[ ! -e "$path" ]] || die "refusing to overwrite existing file: $path"
done
fi
umask 077
msg "generating Secure Boot signing key"
openssl req \
-new \
-x509 \
-newkey rsa:4096 \
-sha256 \
-nodes \
-days 3650 \
-subj "/CN=${SECURE_BOOT_COMMON_NAME}/" \
-keyout "$KEY_PATH" \
-out "$CERT_PEM" >/dev/null 2>&1
openssl x509 -in "$CERT_PEM" -outform DER -out "$CERT_DER"
chmod 0600 "$KEY_PATH"
chmod 0644 "$CERT_PEM" "$CERT_DER"
msg "Secure Boot key: $KEY_PATH"
msg "Secure Boot certificate: $CERT_PEM"
msg "enrollment certificate: $CERT_DER"
+348
View File
@@ -0,0 +1,348 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
IMAGE_PATH="$OUT_DIR/forgeos-${KERNEL_VERSION}.img"
DEVICE=""
AUTO_CONFIRM=0
EXPAND_ROOT=1
LIST_ONLY=0
RANDOMIZE_ROOT_UUID=1
UNMOUNT_TARGET=0
CUSTOM_IMAGE=0
usage() {
cat <<'EOF'
Usage:
install-to-disk.sh --list
install-to-disk.sh --device /dev/sdX [options]
Options:
--device PATH Target disk to erase and install to.
--image PATH Raw ForgeOS image to install.
--list Show candidate disk devices and exit.
--yes Skip the interactive destruction prompt.
--unmount Unmount non-critical mounted target partitions first.
--no-expand-root Keep the root partition at the image's built size.
--keep-root-uuid Preserve the ext4 root filesystem UUID.
--help Show this help text.
Examples:
./scripts/install-to-disk.sh --list
sudo ./scripts/install-to-disk.sh --device /dev/nvme0n1
sudo ./scripts/install-to-disk.sh --device /dev/sdc --yes --unmount
EOF
}
partition_path() {
local disk=$1
local partition=$2
if [[ "$disk" =~ [0-9]$ ]]; then
printf '%sp%s\n' "$disk" "$partition"
else
printf '%s%s\n' "$disk" "$partition"
fi
}
list_disks() {
local line
local name
local type
local size
local transport
local model
msg "candidate disks"
printf '%-16s %-8s %-8s %-24s %s\n' "DEVICE" "TYPE" "SIZE" "TRANSPORT" "MODEL"
while IFS= read -r line; do
name=${line#*NAME=\"}
name=${name%%\"*}
type=${line#*TYPE=\"}
type=${type%%\"*}
size=${line#*SIZE=\"}
size=${size%%\"*}
transport=${line#*TRAN=\"}
transport=${transport%%\"*}
model=${line#*MODEL=\"}
model=${model%%\"*}
[[ "$type" == "disk" ]] || continue
printf '%-16s %-8s %-8s %-24s %s\n' \
"$name" \
"$type" \
"$size" \
"${transport:--}" \
"${model:--}"
done < <(lsblk -dpP -o NAME,TYPE,SIZE,TRAN,MODEL)
}
require_root() {
[[ "${EUID}" -eq 0 ]] || die "installer must run as root"
}
device_type() {
lsblk -dnpo TYPE "$1" 2>/dev/null | head -n1
}
device_size_bytes() {
blockdev --getsize64 "$1"
}
critical_source_on_target() {
local source=$1
local child
local parent
[[ -n "$source" ]] || return 1
if [[ "$source" == "$DEVICE" ]]; then
return 0
fi
while IFS= read -r child; do
[[ -n "$child" ]] || continue
if [[ "$source" == "$child" ]]; then
return 0
fi
done < <(lsblk -lnpo NAME "$DEVICE")
parent=$(lsblk -dnro PKNAME "$source" 2>/dev/null | tail -n1 || true)
[[ -n "$parent" && "/dev/$parent" == "$DEVICE" ]]
}
ensure_target_is_safe() {
local source
local critical_mount
[[ -b "$DEVICE" ]] || die "target is not a block device: $DEVICE"
case "$(device_type "$DEVICE")" in
disk) ;;
*)
die "refusing to install to non-disk target: $DEVICE"
;;
esac
for critical_mount in / /boot /boot/efi /home; do
source=$(findmnt -nr -o SOURCE "$critical_mount" 2>/dev/null || true)
if critical_source_on_target "$source"; then
die "refusing to overwrite active system storage mounted at $critical_mount"
fi
done
}
collect_mounted_children() {
lsblk -lnpo NAME,MOUNTPOINT "$DEVICE" | awk '$2 != "" {print $1 "|" $2}'
}
unmount_target_children() {
local -a mounts=()
local i
local entry
local part
local mountpoint
mapfile -t mounts < <(collect_mounted_children)
[[ "${#mounts[@]}" -gt 0 ]] || return 0
if [[ "$UNMOUNT_TARGET" -ne 1 ]]; then
printf 'Mounted target partitions detected:\n' >&2
printf ' %s\n' "${mounts[@]//|/ mounted at }" >&2
die "unmount them first or rerun with --unmount"
fi
for entry in "${mounts[@]}"; do
part=${entry%%|*}
mountpoint=${entry#*|}
case "$mountpoint" in
/|/boot|/boot/efi|/home)
die "refusing to unmount critical mountpoint $mountpoint on $part"
;;
esac
done
for ((i=${#mounts[@]} - 1; i>=0; i--)); do
entry=${mounts[$i]}
part=${entry%%|*}
mountpoint=${entry#*|}
msg "unmounting $part from $mountpoint"
umount "$part"
done
}
wait_for_block() {
local path=$1
local attempt
for attempt in $(seq 1 20); do
[[ -b "$path" ]] && return 0
udevadm settle >/dev/null 2>&1 || true
sleep 0.5
done
die "timed out waiting for block device $path"
}
build_default_image_if_needed() {
if [[ "$CUSTOM_IMAGE" -eq 0 && ! -f "$IMAGE_PATH" ]]; then
msg "default image missing, building it first"
"$ROOT_DIR/scripts/build-image.sh"
fi
[[ -f "$IMAGE_PATH" ]] || die "missing image: $IMAGE_PATH"
}
confirm_install() {
msg "target disk"
lsblk -dpno NAME,SIZE,MODEL,TRAN "$DEVICE"
msg "source image"
ls -lh "$IMAGE_PATH"
if [[ "$AUTO_CONFIRM" -eq 1 ]]; then
return
fi
printf 'Type INSTALL to erase %s and continue: ' "$DEVICE"
read -r reply
[[ "$reply" == "INSTALL" ]] || die "installation aborted"
}
write_image() {
msg "writing image to $DEVICE"
dd if="$IMAGE_PATH" of="$DEVICE" bs=16M iflag=fullblock conv=fsync status=progress
sync
}
repair_and_rescan_partitions() {
msg "repairing GPT backup header"
parted -s -f "$DEVICE" print >/dev/null
partprobe "$DEVICE" >/dev/null 2>&1 || true
udevadm settle >/dev/null 2>&1 || true
}
expand_root_partition() {
local image_size
local device_size
local root_part
image_size=$(stat -c %s "$IMAGE_PATH")
device_size=$(device_size_bytes "$DEVICE")
root_part=$(partition_path "$DEVICE" 2)
wait_for_block "$root_part"
if (( device_size <= image_size )) || [[ "$EXPAND_ROOT" -ne 1 ]]; then
msg "leaving root partition at image size"
return
fi
msg "expanding root partition to fill the remaining disk"
parted -s -f "$DEVICE" resizepart 2 100%
partprobe "$DEVICE" >/dev/null 2>&1 || true
udevadm settle >/dev/null 2>&1 || true
wait_for_block "$root_part"
msg "checking ext4 root filesystem"
e2fsck -fy "$root_part" >/dev/null
msg "resizing ext4 root filesystem"
resize2fs "$root_part" >/dev/null
}
randomize_root_uuid() {
local root_part
[[ "$RANDOMIZE_ROOT_UUID" -eq 1 ]] || return 0
root_part=$(partition_path "$DEVICE" 2)
wait_for_block "$root_part"
msg "randomizing ext4 root filesystem UUID"
tune2fs -U random "$root_part" >/dev/null
}
print_summary() {
msg "installed disk layout"
lsblk -o NAME,SIZE,FSTYPE,PARTLABEL,LABEL,UUID,MOUNTPOINT "$DEVICE"
}
while [[ $# -gt 0 ]]; do
case "$1" in
--device)
[[ $# -ge 2 ]] || die "--device requires a value"
DEVICE=$2
shift 2
;;
--image)
[[ $# -ge 2 ]] || die "--image requires a value"
IMAGE_PATH=$2
CUSTOM_IMAGE=1
shift 2
;;
--list)
LIST_ONLY=1
shift
;;
--yes)
AUTO_CONFIRM=1
shift
;;
--unmount)
UNMOUNT_TARGET=1
shift
;;
--no-expand-root)
EXPAND_ROOT=0
shift
;;
--keep-root-uuid)
RANDOMIZE_ROOT_UUID=0
shift
;;
--help|-h)
usage
exit 0
;;
*)
die "unknown option: $1"
;;
esac
done
if [[ "$LIST_ONLY" -eq 1 ]]; then
list_disks
exit 0
fi
[[ -n "$DEVICE" ]] || die "missing required --device argument"
require_cmd lsblk findmnt parted partprobe dd blockdev e2fsck resize2fs tune2fs udevadm flock
require_root
ensure_dirs
exec 9>"/tmp/forgeos-install.lock"
flock -n 9 || die "another ForgeOS installer is already running"
build_default_image_if_needed
ensure_target_is_safe
unmount_target_children
if (( $(device_size_bytes "$DEVICE") < $(stat -c %s "$IMAGE_PATH") )); then
die "target disk is smaller than the ForgeOS image"
fi
confirm_install
write_image
repair_and_rescan_partitions
expand_root_partition
randomize_root_uuid
repair_and_rescan_partitions
print_summary
msg "installation complete"
msg "UEFI boots from EFI/BOOT/BOOTX64.EFI on the target disk"
+150
View File
@@ -0,0 +1,150 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd qemu-system-x86_64
ensure_dirs
MODE=${1:-direct}
MEMORY_MB=${MEMORY_MB:-2048}
SMP_CPUS=${SMP_CPUS:-2}
QEMU_DISPLAY=${QEMU_DISPLAY:-gtk}
find_uefi_mode() {
if [[ -n "${UEFI_FIRMWARE:-}" && -f "${UEFI_FIRMWARE}" ]]; then
printf 'bios:%s\n' "$UEFI_FIRMWARE"
return
fi
if [[ -f "/usr/share/OVMF/OVMF_CODE_4M.fd" && -f "/usr/share/OVMF/OVMF_VARS_4M.fd" ]]; then
printf 'pflash:/usr/share/OVMF/OVMF_CODE_4M.fd:/usr/share/OVMF/OVMF_VARS_4M.fd\n'
return
fi
if [[ -f "/home/joe/QEMU_EFI.fd" ]]; then
printf 'bios:/home/joe/QEMU_EFI.fd\n'
return
fi
return 1
}
case "$MODE" in
direct)
[[ -f "$OUT_DIR/bzImage" ]] || die "missing $OUT_DIR/bzImage"
[[ -f "$OUT_DIR/rootfs.cpio.gz" ]] || die "missing $OUT_DIR/rootfs.cpio.gz"
exec qemu-system-x86_64 \
-m "$MEMORY_MB" \
-smp "$SMP_CPUS" \
-cpu max \
-display none \
-serial mon:stdio \
-kernel "$OUT_DIR/bzImage" \
-initrd "$OUT_DIR/rootfs.cpio.gz" \
-append "console=ttyS0 rdinit=/sbin/init loglevel=4" \
-device virtio-rng-pci
;;
image)
UEFI_MODE=$(find_uefi_mode) || die "no usable UEFI firmware found"
IMAGE_PATH="$OUT_DIR/forgeos-${KERNEL_VERSION}.img"
[[ -f "$IMAGE_PATH" ]] || die "missing $IMAGE_PATH"
case "$UEFI_MODE" in
bios:*)
FIRMWARE=${UEFI_MODE#bios:}
exec qemu-system-x86_64 \
-m "$MEMORY_MB" \
-smp "$SMP_CPUS" \
-cpu max \
-serial mon:stdio \
-display none \
-boot order=c \
-bios "$FIRMWARE" \
-drive file="$IMAGE_PATH",format=raw,if=virtio \
-device virtio-rng-pci
;;
pflash:*)
CODE_FD=${UEFI_MODE#pflash:}
CODE_FD=${CODE_FD%%:*}
VARS_FD=${UEFI_MODE##*:}
VARS_COPY=$(mktemp /tmp/forgeos-ovmf-vars.XXXXXX.fd)
cp "$VARS_FD" "$VARS_COPY"
qemu-system-x86_64 \
-m "$MEMORY_MB" \
-smp "$SMP_CPUS" \
-cpu max \
-serial mon:stdio \
-display none \
-boot order=c \
-drive if=pflash,format=raw,readonly=on,file="$CODE_FD" \
-drive if=pflash,format=raw,file="$VARS_COPY" \
-drive file="$IMAGE_PATH",format=raw,if=virtio \
-device virtio-rng-pci
rm -f "$VARS_COPY"
;;
*)
die "unsupported UEFI mode: $UEFI_MODE"
;;
esac
;;
image-gui)
UEFI_MODE=$(find_uefi_mode) || die "no usable UEFI firmware found"
IMAGE_PATH="$OUT_DIR/forgeos-${KERNEL_VERSION}.img"
[[ -f "$IMAGE_PATH" ]] || "$ROOT_DIR/scripts/build-image.sh"
case "$UEFI_MODE" in
bios:*)
FIRMWARE=${UEFI_MODE#bios:}
exec qemu-system-x86_64 \
-m "$MEMORY_MB" \
-smp "$SMP_CPUS" \
-cpu max \
-serial mon:stdio \
-display "$QEMU_DISPLAY" \
-boot order=c \
-bios "$FIRMWARE" \
-drive file="$IMAGE_PATH",format=raw,if=virtio \
-device virtio-vga \
-device qemu-xhci \
-device usb-tablet \
-device usb-kbd \
-device virtio-rng-pci \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0
;;
pflash:*)
CODE_FD=${UEFI_MODE#pflash:}
CODE_FD=${CODE_FD%%:*}
VARS_FD=${UEFI_MODE##*:}
VARS_COPY=$(mktemp /tmp/forgeos-ovmf-vars.XXXXXX.fd)
cp "$VARS_FD" "$VARS_COPY"
qemu-system-x86_64 \
-m "$MEMORY_MB" \
-smp "$SMP_CPUS" \
-cpu max \
-serial mon:stdio \
-display "$QEMU_DISPLAY" \
-boot order=c \
-drive if=pflash,format=raw,readonly=on,file="$CODE_FD" \
-drive if=pflash,format=raw,file="$VARS_COPY" \
-drive file="$IMAGE_PATH",format=raw,if=virtio \
-device virtio-vga \
-device qemu-xhci \
-device usb-tablet \
-device usb-kbd \
-device virtio-rng-pci \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0
rm -f "$VARS_COPY"
;;
*)
die "unsupported UEFI mode: $UEFI_MODE"
;;
esac
;;
*)
die "usage: $0 {direct|image|image-gui}"
;;
esac
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
usage() {
cat <<'EOF'
Usage:
sign-efi-loader.sh [input-bzImage] [output-efi]
Environment:
SECURE_BOOT=1 Sign the loader instead of copying it unsigned.
SECURE_BOOT_KEY=PATH Private key used by sbsign.
SECURE_BOOT_CERT=PATH X.509 certificate used by sbsign.
The certificate must be enrolled in the target firmware Secure Boot db, or
imported through a trusted shim/MOK flow, before firmware will trust the output.
EOF
}
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
usage
exit 0
fi
INPUT=${1:-"$OUT_DIR/bzImage"}
OUTPUT=${2:-"$OUT_DIR/BOOTX64.EFI"}
[[ -f "$INPUT" ]] || die "missing EFI stub kernel: $INPUT"
mkdir -p "$(dirname "$OUTPUT")"
if ! truthy "$SECURE_BOOT"; then
install -m 0644 "$INPUT" "$OUTPUT"
msg "unsigned EFI loader ready: $OUTPUT"
exit 0
fi
[[ -n "$SECURE_BOOT_KEY" ]] || die "SECURE_BOOT=1 requires SECURE_BOOT_KEY=/path/to/signing.key"
[[ -n "$SECURE_BOOT_CERT" ]] || die "SECURE_BOOT=1 requires SECURE_BOOT_CERT=/path/to/signing.crt"
[[ -f "$SECURE_BOOT_KEY" ]] || die "missing Secure Boot key: $SECURE_BOOT_KEY"
[[ -f "$SECURE_BOOT_CERT" ]] || die "missing Secure Boot certificate: $SECURE_BOOT_CERT"
require_cmd sbsign
TMP_OUTPUT=$(mktemp "$OUTPUT.tmp.XXXXXX")
cleanup() {
rm -f "$TMP_OUTPUT"
}
trap cleanup EXIT
msg "signing EFI loader for Secure Boot"
sbsign \
--key "$SECURE_BOOT_KEY" \
--cert "$SECURE_BOOT_CERT" \
--output "$TMP_OUTPUT" \
"$INPUT" >/dev/null
install -m 0644 "$TMP_OUTPUT" "$OUTPUT"
if command -v sbverify >/dev/null 2>&1; then
sbverify --cert "$SECURE_BOOT_CERT" "$OUTPUT" >/dev/null
fi
msg "signed EFI loader ready: $OUTPUT"
+238
View File
@@ -0,0 +1,238 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd apt-get cat chmod dpkg-deb mkdir rm
ensure_dirs
[[ "$DESKTOP" == "console" ]] || die "Openbox desktop layer is only supported on the normal ForgeOS rootfs"
[[ -d "$ROOTFS_STAGING_DIR" ]] || die "missing rootfs staging tree: $ROOTFS_STAGING_DIR"
desktop_package_array() {
local package
for package in $OPENBOX_DESKTOP_PACKAGES; do
printf '%s\n' "$package"
done
}
is_skipped_package() {
local package=$1
case " $OPENBOX_DESKTOP_SKIP_PACKAGES " in
*" $package "*) return 0 ;;
*) return 1 ;;
esac
}
download_desktop_packages() {
local -a packages=()
local package
local status_file="$OPENBOX_DESKTOP_APT_STATE_DIR/status"
local extended_states_file="$OPENBOX_DESKTOP_APT_STATE_DIR/extended_states"
while IFS= read -r package; do
[[ -n "$package" ]] && packages+=("$package")
done < <(desktop_package_array)
[[ "${#packages[@]}" -gt 0 ]] || die "OPENBOX_DESKTOP_PACKAGES is empty"
mkdir -p \
"$OPENBOX_DESKTOP_DEB_DIR/partial" \
"$OPENBOX_DESKTOP_APT_STATE_DIR"
: > "$status_file"
: > "$extended_states_file"
msg "downloading Openbox desktop package closure"
apt-get \
-o "Dir::State::status=$status_file" \
-o "Dir::State::extended_states=$extended_states_file" \
-o "Dir::Cache::archives=$OPENBOX_DESKTOP_DEB_DIR" \
-o Debug::NoLocking=1 \
--yes \
--download-only \
--no-install-recommends \
install "${packages[@]}"
}
extract_desktop_packages() {
local deb
local package
local extracted_count=0
local skipped_count=0
shopt -s nullglob
for deb in "$OPENBOX_DESKTOP_DEB_DIR"/*.deb; do
package=$(dpkg-deb -f "$deb" Package)
if is_skipped_package "$package"; then
skipped_count=$((skipped_count + 1))
continue
fi
dpkg-deb -x "$deb" "$ROOTFS_STAGING_DIR"
extracted_count=$((extracted_count + 1))
done
shopt -u nullglob
[[ "$extracted_count" -gt 0 ]] || die "no desktop packages were extracted from $OPENBOX_DESKTOP_DEB_DIR"
msg "extracted $extracted_count desktop packages; skipped $skipped_count base packages"
}
write_desktop_config() {
mkdir -p \
"$ROOTFS_STAGING_DIR/etc/X11/xorg.conf.d" \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants" \
"$ROOTFS_STAGING_DIR/root/.config/openbox" \
"$ROOTFS_STAGING_DIR/root/.config/pcmanfm/default" \
"$ROOTFS_STAGING_DIR/root/.config/tint2" \
"$ROOTFS_STAGING_DIR/usr/local/bin" \
"$ROOTFS_STAGING_DIR/var/lib/dbus"
cat > "$ROOTFS_STAGING_DIR/etc/X11/Xwrapper.config" <<'EOF'
allowed_users=anybody
needs_root_rights=yes
EOF
cat > "$ROOTFS_STAGING_DIR/etc/X11/xorg.conf.d/10-forgeos-input.conf" <<'EOF'
Section "InputClass"
Identifier "ForgeOS libinput pointers"
MatchIsPointer "on"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "ForgeOS libinput keyboards"
MatchIsKeyboard "on"
Driver "libinput"
EndSection
EOF
cat > "$ROOTFS_STAGING_DIR/root/.config/openbox/autostart" <<'EOF'
pcmanfm --desktop --profile default &
tint2 &
lxterminal &
EOF
cat > "$ROOTFS_STAGING_DIR/root/.config/pcmanfm/default/desktop-items-0.conf" <<'EOF'
[*]
wallpaper_mode=color
desktop_bg=#1f2933
desktop_fg=#f3f4f6
desktop_shadow=#000000
show_wm_menu=1
sort=mtime;ascending;
show_documents=0
show_trash=0
show_mounts=0
EOF
cat > "$ROOTFS_STAGING_DIR/root/.config/tint2/tint2rc" <<'EOF'
rounded = 0
border_width = 0
background_color = #111827 95
panel_monitor = all
panel_position = bottom center horizontal
panel_size = 100% 32
panel_margin = 0 0
panel_padding = 4 2 4
panel_items = TSC
task_text = 1
task_icon = 1
task_centered = 1
task_padding = 4 2
task_background_id = 0
clock = 1
time1_format = %H:%M
time1_font = DejaVu Sans 10
clock_font_color = #f9fafb 100
systray = 1
systray_padding = 4 0 4
EOF
cat > "$ROOTFS_STAGING_DIR/usr/local/bin/forgeos-openbox-session" <<'EOF'
#!/bin/sh
set -eu
export HOME=/root
export USER=root
export LOGNAME=root
export XDG_RUNTIME_DIR=/run/user/0
export XDG_CONFIG_HOME=/root/.config
export XDG_CACHE_HOME=/root/.cache
mkdir -p "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME"
chmod 0700 "$XDG_RUNTIME_DIR"
if command -v dbus-uuidgen >/dev/null 2>&1 && [ ! -s /var/lib/dbus/machine-id ]; then
dbus-uuidgen --ensure=/var/lib/dbus/machine-id || true
fi
if command -v openbox-session >/dev/null 2>&1; then
exec openbox-session
fi
pcmanfm --desktop --profile default &
tint2 &
lxterminal &
exec openbox
EOF
chmod 0755 "$ROOTFS_STAGING_DIR/usr/local/bin/forgeos-openbox-session"
cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/forgeos-desktop.service" <<'EOF'
[Unit]
Description=ForgeOS Openbox desktop
Wants=dbus.service systemd-udevd.service
After=dbus.service systemd-udevd.service systemd-user-sessions.service
Conflicts=forgeos-shell@tty1.service getty@tty1.service
[Service]
Type=simple
Environment=HOME=/root
Environment=USER=root
Environment=LOGNAME=root
Environment=XDG_RUNTIME_DIR=/run/user/0
ExecStartPre=/bin/mkdir -p /run/user/0
ExecStartPre=/bin/chmod 0700 /run/user/0
ExecStart=/usr/bin/xinit /usr/local/bin/forgeos-openbox-session -- /usr/lib/xorg/Xorg :0 vt1 -keeptty -nolisten tcp
Restart=on-failure
RestartSec=2
StandardInput=tty
StandardOutput=journal
StandardError=journal
TTYPath=/dev/tty1
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
[Install]
WantedBy=multi-user.target
EOF
ln -sfn /etc/systemd/system/forgeos-desktop.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-desktop.service"
rm -f "$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants/forgeos-shell@tty1.service"
if [[ -e "$ROOTFS_STAGING_DIR/usr/lib/systemd/system/dbus.socket" ]]; then
mkdir -p "$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants"
ln -sfn /usr/lib/systemd/system/dbus.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/dbus.socket"
fi
if [[ -e "$ROOTFS_STAGING_DIR/usr/lib/systemd/system/dbus.service" ]]; then
ln -sfn /usr/lib/systemd/system/dbus.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/dbus.service"
fi
cat > "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" <<'EOF'
NAME=Openbox
COMPONENTS=openbox,tint2,pcmanfm,xorg,lxterminal
EOF
}
download_desktop_packages
extract_desktop_packages
write_desktop_config
msg "Openbox desktop layer staged into $ROOTFS_STAGING_DIR"