mirror of
https://github.com/blazblue547-afk/ForgeOS.git
synced 2026-12-02 14:34:17 -05:00
feat(image): add atomic app layer
Keep the base root read-only and move mutable Nix, home, var, opt, and usr-local state onto a writable FORGE_APPS partition. Normalize ext4 ownership during image creation so forge can manage user profiles through nix-daemon without owning system paths.
This commit is contained in:
1 parent
eb8038ef4c
commit
2e202eae01
17 files changed
+494
-69
No files matched your search
@@ -12,6 +12,8 @@ export DESKTOP ?= console
|
|||||||
export ENABLE_DESKTOP ?= 0
|
export ENABLE_DESKTOP ?= 0
|
||||||
export ROOT_LABEL ?= FORGE_ROOT
|
export ROOT_LABEL ?= FORGE_ROOT
|
||||||
export EFI_LABEL ?= FORGE_EFI
|
export EFI_LABEL ?= FORGE_EFI
|
||||||
|
export APP_LABEL ?= FORGE_APPS
|
||||||
|
export ATOMIC_BASE ?= 1
|
||||||
desktop_enabled := $(filter 1 true TRUE yes YES on ON,$(ENABLE_DESKTOP))
|
desktop_enabled := $(filter 1 true TRUE yes YES on ON,$(ENABLE_DESKTOP))
|
||||||
export IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(desktop_enabled),6144,4096))
|
export IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(desktop_enabled),6144,4096))
|
||||||
export ESP_SIZE_MIB ?= 256
|
export ESP_SIZE_MIB ?= 256
|
||||||
@@ -40,6 +42,7 @@ help:
|
|||||||
' ENABLE_DESKTOP=1 make rootfs - add Openbox/tint2/PCManFM desktop' \
|
' ENABLE_DESKTOP=1 make rootfs - add Openbox/tint2/PCManFM desktop' \
|
||||||
' make gnome-rootfs - assemble a Debian GNOME desktop rootfs' \
|
' make gnome-rootfs - assemble a Debian GNOME desktop rootfs' \
|
||||||
' make image - build a bootable GPT/UEFI disk image' \
|
' make image - build a bootable GPT/UEFI disk image' \
|
||||||
|
' make image builds an atomic read-only base plus writable app/state layer' \
|
||||||
' make gnome-image - build a bootable GPT/UEFI GNOME 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 secure-boot-keys - generate a local Secure Boot signing keypair' \
|
||||||
' make run - boot kernel + initramfs in QEMU' \
|
' make run - boot kernel + initramfs in QEMU' \
|
||||||
@@ -101,7 +104,7 @@ run-image:
|
|||||||
@./scripts/run-qemu.sh image
|
@./scripts/run-qemu.sh image
|
||||||
|
|
||||||
run-desktop: ENABLE_DESKTOP = 1
|
run-desktop: ENABLE_DESKTOP = 1
|
||||||
run-desktop: IMAGE_SIZE_MIB = 4096
|
run-desktop: IMAGE_SIZE_MIB = 6144
|
||||||
run-desktop: MEMORY_MB = 3072
|
run-desktop: MEMORY_MB = 3072
|
||||||
run-desktop: image
|
run-desktop: image
|
||||||
@./scripts/run-qemu.sh image-gui
|
@./scripts/run-qemu.sh image-gui
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ As of `2026-06-17`, the project defaults to:
|
|||||||
- a minimal root filesystem with systemd as `/sbin/init`
|
- a minimal root filesystem with systemd as `/sbin/init`
|
||||||
- a bootable GPT disk image with:
|
- a bootable GPT disk image with:
|
||||||
- an EFI system partition
|
- an EFI system partition
|
||||||
- an ext4 root partition
|
- a read-only ext4 base root partition
|
||||||
|
- a writable ext4 app/state partition
|
||||||
- a faster QEMU smoke-test path using `kernel + initramfs`
|
- a faster QEMU smoke-test path using `kernel + initramfs`
|
||||||
|
|
||||||
## Layout
|
## Layout
|
||||||
@@ -45,11 +46,17 @@ That dependency script is for Debian/Ubuntu hosts and installs only the packages
|
|||||||
|
|
||||||
The default console accounts are `forge` and `root`; both use the password `forge`. Console logins go through BusyBox `login`, Linux-PAM, and `pam_systemd.so`, so `systemd-logind` tracks real per-user sessions.
|
The default console accounts are `forge` and `root`; both use the password `forge`. Console logins go through BusyBox `login`, Linux-PAM, and `pam_systemd.so`, so `systemd-logind` tracks real per-user sessions.
|
||||||
|
|
||||||
Nix is staged into the normal ForgeOS rootfs as the core package manager. On first boot, `forgeos-nix-bootstrap.service` registers the initial `/nix/store` closure, creates the default Nix profile, and starts `nix-daemon`. Log in as `forge` and install packages with the modern profile command:
|
Nix is staged into the writable ForgeOS app layer as the core package manager. Disk images boot a read-only base OS and bind the app layer over `/nix`, `/home`, `/root`, `/var`, `/opt`, and `/usr/local`. On first boot, `forgeos-nix-bootstrap.service` registers the initial `/nix/store` closure, creates the default Nix profile, and starts `nix-daemon`. Log in as `forge` and install apps with the friendly wrapper:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
forgeos-app install hello
|
||||||
|
hello
|
||||||
|
```
|
||||||
|
|
||||||
|
The wrapper uses Nix profiles underneath, so direct Nix commands still work:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
nix profile install nixpkgs#hello
|
nix profile install nixpkgs#hello
|
||||||
hello
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To build a UEFI disk image:
|
To build a UEFI disk image:
|
||||||
@@ -101,9 +108,9 @@ sudo make install DISK=/dev/nvme0n1
|
|||||||
- 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 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.
|
- 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`.
|
- 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.
|
- The host-side installer expands the writable app/state partition to fill larger target disks. The base root partition stays fixed-size and read-only at runtime.
|
||||||
- systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, PAM-backed `/bin/login`, early switch-root support, and emergency command-line tools.
|
- systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, PAM-backed `/bin/login`, early switch-root support, and emergency command-line tools.
|
||||||
- Nix `2.34.0` is staged from the official `x86_64-linux` binary tarball and configured in multi-user daemon mode with `/nix`, `nixbld` build users, `cache.nixos.org`, and `nix-command`/`flakes` enabled. Override `NIX_VERSION` or `NIX_SYSTEM` if you intentionally want a different upstream tarball.
|
- Nix `2.34.0` is staged from the official `x86_64-linux` binary tarball and configured in multi-user daemon mode with `/nix`, `nixbld` build users, `cache.nixos.org`, and `nix-command`/`flakes` enabled. The `/nix` tree lives in the mutable app layer on disk images. Override `NIX_VERSION` or `NIX_SYSTEM` if you intentionally want a different upstream tarball.
|
||||||
- A ForgeOS-native `neofetch` command is included in the overlay with a custom ForgeOS ASCII logo at `/usr/share/neofetch/ascii/distro/forgeos`.
|
- 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 PAM-backed login prompts on `tty1` and `ttyS0` through native systemd units instead of BusyBox `inittab`.
|
- The console starts PAM-backed login prompts 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`.
|
- The system bus is provided by source-built `dbus-daemon` and socket-activated at `/run/dbus/system_bus_socket`.
|
||||||
@@ -146,7 +153,7 @@ Linux-PAM, systemd, and D-Bus are built with Meson/Ninja and staged dynamically.
|
|||||||
- UEFI only for now; BIOS boot is not implemented.
|
- 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.
|
- 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.
|
- Wireless firmware, GPU acceleration, stock Microsoft-trusted Secure Boot/shim integration, audio, and power-management polish are not bundled yet.
|
||||||
- Nix is the package manager for the normal ForgeOS rootfs, but ForgeOS does not yet have a declarative NixOS-style system rebuild/update flow.
|
- Nix is the package manager for the mutable app layer, but ForgeOS does not yet have a declarative NixOS-style base OS rebuild/update flow or rollback selector.
|
||||||
- Account management is limited to the built-in `forge` and `root` accounts.
|
- Account management is limited to the built-in `forge` and `root` accounts.
|
||||||
- The Openbox desktop layer is a staged runtime payload, not an in-OS package manager.
|
- 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.
|
- GNOME support is currently a package-bootstrapped desktop flavor, not a source-built ForgeOS desktop stack.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
|
|||||||
CONFIG_ASH_BASH_COMPAT=y
|
CONFIG_ASH_BASH_COMPAT=y
|
||||||
CONFIG_ASH_JOB_CONTROL=y
|
CONFIG_ASH_JOB_CONTROL=y
|
||||||
CONFIG_ASH_ALIAS=y
|
CONFIG_ASH_ALIAS=y
|
||||||
|
CONFIG_AWK=y
|
||||||
CONFIG_CAT=y
|
CONFIG_CAT=y
|
||||||
CONFIG_CHMOD=y
|
CONFIG_CHMOD=y
|
||||||
CONFIG_CHOWN=y
|
CONFIG_CHOWN=y
|
||||||
|
|||||||
@@ -88,5 +88,5 @@ CONFIG_IGB=y
|
|||||||
CONFIG_IGC=y
|
CONFIG_IGC=y
|
||||||
CONFIG_TG3=y
|
CONFIG_TG3=y
|
||||||
CONFIG_CMDLINE_BOOL=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="root=PARTLABEL=root rootfstype=ext4 rootwait ro console=tty0 console=ttyS0,115200n8 loglevel=7 ignore_loglevel i915.enable_psr=0 i915.fastboot=0"
|
||||||
# CONFIG_CMDLINE_OVERRIDE is not set
|
# CONFIG_CMDLINE_OVERRIDE is not set
|
||||||
+18
-8
@@ -22,15 +22,17 @@ ForgeOS currently targets UEFI systems.
|
|||||||
|
|
||||||
1. The disk image contains a GPT.
|
1. The disk image contains a GPT.
|
||||||
2. Partition 1 is a FAT32 EFI System Partition labeled `FORGE_EFI`.
|
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.
|
3. Partition 2 is an ext4 base OS partition labeled `FORGE_ROOT` with GPT partition label `root`.
|
||||||
4. The built kernel EFI stub is copied to `EFI/BOOT/FORGEOS.EFI`.
|
4. Partition 3 is an ext4 writable app/state partition labeled `FORGE_APPS` with GPT partition label `apps`.
|
||||||
5. UEFI firmware executes GRUB from `EFI/BOOT/BOOTX64.EFI`, and GRUB starts the kernel.
|
5. By default, `out/BOOTX64.EFI` is a standalone GRUB UEFI fallback loader with a small debug boot menu.
|
||||||
6. The built-in kernel command line mounts `PARTLABEL=root` as the real root filesystem.
|
6. The built kernel EFI stub is copied to `EFI/BOOT/FORGEOS.EFI`.
|
||||||
7. systemd starts as `/sbin/init`, activates the D-Bus system bus, starts `systemd-logind`, `systemd-resolved`, and `systemd-networkd`, reaches `multi-user.target`, and launches PAM-backed login prompts on `tty1` and `ttyS0`.
|
7. UEFI firmware executes GRUB from `EFI/BOOT/BOOTX64.EFI`, and GRUB starts the kernel.
|
||||||
|
8. The kernel mounts `PARTLABEL=root` as the real root filesystem with `ro` so the base OS stays atomic.
|
||||||
|
9. systemd starts as `/sbin/init`, mounts the app layer at `/forge`, bind-mounts mutable paths from it, activates the D-Bus system bus, starts `systemd-logind`, `systemd-resolved`, and `systemd-networkd`, reaches `multi-user.target`, and launches PAM-backed login prompts on `tty1` and `ttyS0`.
|
||||||
|
|
||||||
## Root Filesystem Model
|
## Root Filesystem Model
|
||||||
|
|
||||||
The root filesystem is assembled in `staging/rootfs` from:
|
The canonical root filesystem is assembled in `staging/rootfs` from:
|
||||||
|
|
||||||
- systemd install output from `staging/systemd`
|
- systemd install output from `staging/systemd`
|
||||||
- D-Bus install output from `staging/dbus`
|
- D-Bus install output from `staging/dbus`
|
||||||
@@ -41,11 +43,18 @@ The root filesystem is assembled in `staging/rootfs` from:
|
|||||||
- kernel modules from the kernel build
|
- kernel modules from the kernel build
|
||||||
- the repository overlay in `overlay/rootfs`
|
- the repository overlay in `overlay/rootfs`
|
||||||
|
|
||||||
|
For normal ForgeOS disk images, `scripts/build-image.sh` derives two trees from `staging/rootfs`:
|
||||||
|
|
||||||
|
- `staging/rootfs-base`: the read-only base OS used for partition 2
|
||||||
|
- `staging/appfs`: the writable app/state layer used for partition 3
|
||||||
|
|
||||||
|
The base tree keeps the source-built OS, boot-critical tools, systemd units, configuration, and symlinks into `/nix/store`. The app/state tree owns `/nix`, `/home`, `/root`, `/var`, `/opt`, and `/usr/local`. The image builder writes an `/etc/fstab` into `staging/rootfs-base` that mounts `LABEL=FORGE_APPS` at `/forge` and bind-mounts those paths back into the normal filesystem layout. `/tmp` is a tmpfs. The canonical `staging/rootfs` used for `rootfs.cpio.gz` does not include those app-layer fstab entries, so the direct initramfs smoke-test path stays monolithic and does not wait for a disk app partition.
|
||||||
|
|
||||||
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 source-built systemd layer also includes `systemd-logind`, `loginctl`, `pam_systemd.so`, the `org.freedesktop.login1` system-bus policy, and the logind varlink socket. Console login uses BusyBox `getty` and `login`; `/etc/pam.d/login` authenticates against `/etc/shadow` with `pam_unix.so` and registers sessions with `pam_systemd.so`.
|
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 source-built systemd layer also includes `systemd-logind`, `loginctl`, `pam_systemd.so`, the `org.freedesktop.login1` system-bus policy, and the logind varlink socket. Console login uses BusyBox `getty` and `login`; `/etc/pam.d/login` authenticates against `/etc/shadow` with `pam_unix.so` and registers sessions with `pam_systemd.so`.
|
||||||
|
|
||||||
Nix is integrated as a multi-user daemon package manager in the normal ForgeOS rootfs. `scripts/stage-nix.sh` copies the official Nix store closure into `/nix/store`, stages `nix.conf`, adds `nixbld` build accounts, enables `forgeos-nix-bootstrap.service`, and exposes `nix-daemon.service` plus `nix-daemon.socket`. On first boot, the bootstrap service fixes `/nix` ownership, loads the bundled `.reginfo` into the Nix database, and creates the default profile with Nix, Nix manual pages, and the bundled CA certificate package. ForgeOS enables `nix-command` and `flakes`, uses `cache.nixos.org`, and leaves Nix build sandboxing disabled until the OS has a verified sandbox policy.
|
Nix is integrated as a multi-user daemon package manager in the normal ForgeOS app layer. `scripts/stage-nix.sh` copies the official Nix store closure into `/nix/store`, stages `nix.conf`, adds `nixbld` build accounts, enables `forgeos-nix-bootstrap.service`, and exposes `nix-daemon.service` plus `nix-daemon.socket`. On disk images, the image builder moves that `/nix` tree into `staging/appfs` so package installs and Nix state mutate the app partition, not the base OS. On first boot, the bootstrap service fixes `/nix` ownership, loads the bundled `.reginfo` into the Nix database, and creates the default profile with Nix, Nix manual pages, and the bundled CA certificate package. ForgeOS enables `nix-command` and `flakes`, uses `cache.nixos.org`, and leaves Nix build sandboxing disabled until the OS has a verified sandbox policy.
|
||||||
|
|
||||||
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.
|
The default console build also generates `out/rootfs.cpio.gz` for quick QEMU smoke tests. That direct initramfs path is intentionally monolithic and writable because it has no persistent app partition. Desktop-enabled rootfs builds skip the initramfs artifact and boot through the ext4 disk image path.
|
||||||
|
|
||||||
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 `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.
|
||||||
|
|
||||||
@@ -96,6 +105,7 @@ This is enough for a first CLI OS image and a development boot path, but not yet
|
|||||||
- source-built dependency closure for systemd and D-Bus runtime libraries
|
- source-built dependency closure for systemd and D-Bus runtime libraries
|
||||||
- account management beyond the built-in `forge` and `root` users
|
- account management beyond the built-in `forge` and `root` users
|
||||||
- in-OS guided installer and update system
|
- in-OS guided installer and update system
|
||||||
|
- base OS rollback selection across multiple base deployments
|
||||||
- hardening review of the kernel and userspace defaults
|
- hardening review of the kernel and userspace defaults
|
||||||
|
|
||||||
## Suggested Next Steps
|
## Suggested Next Steps
|
||||||
|
|||||||
+9
-6
@@ -13,8 +13,8 @@ It installs the built raw ForgeOS image to a real block device from an existing
|
|||||||
3. optionally unmounts non-critical target partitions
|
3. optionally unmounts non-critical target partitions
|
||||||
4. writes the ForgeOS raw image to the target disk
|
4. writes the ForgeOS raw image to the target disk
|
||||||
5. repairs the GPT backup header on larger disks
|
5. repairs the GPT backup header on larger disks
|
||||||
6. expands partition `2` and the ext4 root filesystem to fill the device
|
6. expands the writable app/state partition to fill the device
|
||||||
7. randomizes the ext4 root filesystem UUID by default
|
7. randomizes ext4 filesystem UUIDs by default
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
@@ -39,11 +39,11 @@ cd /home/joe/forgeos
|
|||||||
sudo make install DISK=/dev/sdc INSTALL_ARGS="--yes --unmount"
|
sudo make install DISK=/dev/sdc INSTALL_ARGS="--yes --unmount"
|
||||||
```
|
```
|
||||||
|
|
||||||
Install without expanding the root filesystem:
|
Install without expanding the writable app/state filesystem:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /home/joe/forgeos
|
cd /home/joe/forgeos
|
||||||
sudo make install DISK=/dev/sdc INSTALL_ARGS="--no-expand-root"
|
sudo make install DISK=/dev/sdc INSTALL_ARGS="--no-expand-apps"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Direct Script Usage
|
## Direct Script Usage
|
||||||
@@ -57,8 +57,10 @@ Optional arguments:
|
|||||||
- `--image /path/to/forgeos.img`
|
- `--image /path/to/forgeos.img`
|
||||||
- `--yes`
|
- `--yes`
|
||||||
- `--unmount`
|
- `--unmount`
|
||||||
- `--no-expand-root`
|
- `--no-expand-apps`
|
||||||
- `--keep-root-uuid`
|
- `--no-expand-root` as a legacy alias for `--no-expand-apps`
|
||||||
|
- `--keep-uuids`
|
||||||
|
- `--keep-root-uuid` as a legacy alias for `--keep-uuids`
|
||||||
|
|
||||||
## Secure Boot Images
|
## Secure Boot Images
|
||||||
|
|
||||||
@@ -81,6 +83,7 @@ Enroll `out/secure-boot/ForgeOS.cer` in the target firmware Secure Boot database
|
|||||||
- The installer is destructive. It erases the target disk.
|
- The installer is destructive. It erases the target disk.
|
||||||
- Run it from a Linux host, not from the disk you are installing over.
|
- 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`.
|
- The current boot model uses a built-in kernel command line with `root=PARTLABEL=root`.
|
||||||
|
- Normal ForgeOS images use partition `2` for the read-only base OS and partition `3` for mutable apps and state.
|
||||||
- Avoid leaving multiple ForgeOS installations attached during early testing, because multiple disks with the same GPT partition label can confuse root selection.
|
- 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.
|
- Secure Boot trust is tied to the enrolled signing certificate. Protect the generated private key.
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Before=systemd-user-sessions.service getty.target forgeos-login@tty1.service for
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/bin/sh -c 'if [ -d /home/forge ]; then chown -R 1000:1000 /home/forge && chmod 700 /home/forge; fi'
|
ExecStart=/bin/sh -c 'if [ -d /home/forge ]; then chown -R 1000:1000 /home/forge 2>/dev/null || true; chmod 700 /home/forge 2>/dev/null || true; fi'
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
@@ -106,7 +106,6 @@ console_note "ForgeOS initramfs: locating real root filesystem..."
|
|||||||
ROOTDEV=$(wait_for_root_device) || drop_to_rescue "root partition not found" || exit 1
|
ROOTDEV=$(wait_for_root_device) || drop_to_rescue "root partition not found" || exit 1
|
||||||
|
|
||||||
mkdir -p "$NEWROOT"
|
mkdir -p "$NEWROOT"
|
||||||
mount -t ext4 -o rw "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
|
|
||||||
mount -t ext4 -o ro "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
|
mount -t ext4 -o ro "$ROOTDEV" "$NEWROOT" 2>/dev/null || \
|
||||||
drop_to_rescue "could not mount $ROOTDEV" || exit 1
|
drop_to_rescue "could not mount $ROOTDEV" || exit 1
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
PATH=/usr/bin:/usr/sbin:/bin:/sbin
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<'EOF'
|
||||||
|
Usage:
|
||||||
|
forgeos-app status
|
||||||
|
forgeos-app install NAME|FLAKE...
|
||||||
|
forgeos-app remove PACKAGE...
|
||||||
|
forgeos-app list
|
||||||
|
forgeos-app search TERMS...
|
||||||
|
forgeos-app upgrade [PACKAGE...]
|
||||||
|
forgeos-app rollback
|
||||||
|
forgeos-app shell NAME|FLAKE...
|
||||||
|
forgeos-app gc
|
||||||
|
|
||||||
|
Short names are expanded to nixpkgs#NAME for install and shell.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
need_nix() {
|
||||||
|
command -v nix >/dev/null 2>&1 || {
|
||||||
|
echo "nix is unavailable; is the ForgeOS app layer mounted?" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
as_installable() {
|
||||||
|
case "$1" in
|
||||||
|
*#*|/*|git+*|http://*|https://*)
|
||||||
|
printf '%s\n' "$1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf 'nixpkgs#%s\n' "$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
show_mount() {
|
||||||
|
awk -v target="$1" '
|
||||||
|
$2 == target {
|
||||||
|
printf "%-12s <- %s (%s, %s)\n", target, $1, $3, $4
|
||||||
|
found = 1
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
if (!found) {
|
||||||
|
printf "%-12s <- not mounted\n", target
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' /proc/mounts
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd=${1:-}
|
||||||
|
if [ -z "$cmd" ]; then
|
||||||
|
usage
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
shift || true
|
||||||
|
|
||||||
|
case "$cmd" in
|
||||||
|
status)
|
||||||
|
show_mount /
|
||||||
|
show_mount /forge
|
||||||
|
show_mount /nix
|
||||||
|
show_mount /home
|
||||||
|
show_mount /root
|
||||||
|
show_mount /var
|
||||||
|
show_mount /opt
|
||||||
|
show_mount /usr/local
|
||||||
|
df -h /forge /nix /home 2>/dev/null || true
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
[ "$#" -gt 0 ] || {
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
need_nix
|
||||||
|
for item in "$@"; do
|
||||||
|
nix profile install "$(as_installable "$item")"
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
remove)
|
||||||
|
[ "$#" -gt 0 ] || {
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
need_nix
|
||||||
|
nix profile remove "$@"
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
need_nix
|
||||||
|
nix profile list
|
||||||
|
;;
|
||||||
|
search)
|
||||||
|
[ "$#" -gt 0 ] || {
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
need_nix
|
||||||
|
nix search nixpkgs "$@"
|
||||||
|
;;
|
||||||
|
upgrade)
|
||||||
|
need_nix
|
||||||
|
if [ "$#" -eq 0 ]; then
|
||||||
|
nix profile upgrade '.*'
|
||||||
|
else
|
||||||
|
nix profile upgrade "$@"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
rollback)
|
||||||
|
need_nix
|
||||||
|
nix profile rollback
|
||||||
|
;;
|
||||||
|
shell)
|
||||||
|
[ "$#" -gt 0 ] || {
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
need_nix
|
||||||
|
set -- "$@"
|
||||||
|
expanded=
|
||||||
|
for item in "$@"; do
|
||||||
|
expanded="${expanded}${expanded:+ }$(as_installable "$item")"
|
||||||
|
done
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
exec nix shell $expanded
|
||||||
|
;;
|
||||||
|
gc)
|
||||||
|
need_nix
|
||||||
|
nix store gc
|
||||||
|
;;
|
||||||
|
help|--help|-h)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
d /home/forge 0700 forge forge -
|
d /home/forge 0700 forge forge -
|
||||||
z /home/forge 0700 forge forge -
|
z /home/forge 0700 forge forge -
|
||||||
z /root 0700 root root -
|
z /root 0700 root root -
|
||||||
z /etc/shadow 0600 root root -
|
|
||||||
z /etc/gshadow 0600 root root -
|
|
||||||
+186
-5
@@ -4,12 +4,15 @@ set -euo pipefail
|
|||||||
|
|
||||||
source "$(dirname "$0")/common.sh"
|
source "$(dirname "$0")/common.sh"
|
||||||
|
|
||||||
require_cmd qemu-img parted mkfs.vfat mkfs.ext4 mcopy mmd dd awk truncate
|
require_cmd qemu-img parted mkfs.vfat mkfs.ext4 mcopy mmd dd awk sed truncate rsync du find fakeroot
|
||||||
ensure_dirs
|
ensure_dirs
|
||||||
|
|
||||||
normal_rootfs_matches() {
|
normal_rootfs_matches() {
|
||||||
[[ -d "$ROOTFS_STAGING_DIR" ]] || return 1
|
[[ -d "$ROOTFS_STAGING_DIR" ]] || return 1
|
||||||
[[ -f "$ROOTFS_STAGING_DIR/etc/forgeos-nix" ]] || return 1
|
[[ -f "$ROOTFS_STAGING_DIR/etc/forgeos-nix" ]] || return 1
|
||||||
|
[[ -x "$ROOTFS_STAGING_DIR/usr/bin/forgeos-app" ]] || return 1
|
||||||
|
[[ -f "$ROOTFS_STAGING_DIR/etc/machine-id" ]] || return 1
|
||||||
|
[[ ! -f "$ROOTFS_STAGING_DIR/etc/fstab" ]] || return 1
|
||||||
|
|
||||||
if truthy "$ENABLE_DESKTOP"; then
|
if truthy "$ENABLE_DESKTOP"; then
|
||||||
[[ -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" ]] || return 1
|
[[ -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" ]] || return 1
|
||||||
@@ -39,6 +42,9 @@ GRUB_CFG="$OUT_DIR/grub.cfg"
|
|||||||
ESP_END_MIB=$((1 + ESP_SIZE_MIB))
|
ESP_END_MIB=$((1 + ESP_SIZE_MIB))
|
||||||
ESP_IMAGE="$OUT_DIR/forgeos-esp.img"
|
ESP_IMAGE="$OUT_DIR/forgeos-esp.img"
|
||||||
ROOT_IMAGE="$OUT_DIR/forgeos-root.img"
|
ROOT_IMAGE="$OUT_DIR/forgeos-root.img"
|
||||||
|
APP_IMAGE="$OUT_DIR/forgeos-apps.img"
|
||||||
|
IMAGE_ROOTFS_DIR="$ROOTFS_STAGING_DIR"
|
||||||
|
APP_IMAGE_NEEDED=0
|
||||||
|
|
||||||
partition_field() {
|
partition_field() {
|
||||||
local partition=$1
|
local partition=$1
|
||||||
@@ -51,7 +57,139 @@ partition_field() {
|
|||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reset_staging_tree() {
|
||||||
|
local path=$1
|
||||||
|
|
||||||
|
if [[ -d "$path" ]]; then
|
||||||
|
chmod -R u+w "$path" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
rm -rf "$path"
|
||||||
|
mkdir -p "$path"
|
||||||
|
}
|
||||||
|
|
||||||
|
copy_app_path() {
|
||||||
|
local rel=$1
|
||||||
|
local app_rel=$2
|
||||||
|
local src="$ROOTFS_STAGING_DIR/$rel"
|
||||||
|
local dest="$APPFS_STAGING_DIR/$app_rel"
|
||||||
|
|
||||||
|
mkdir -p "$dest"
|
||||||
|
if [[ -d "$src" ]]; then
|
||||||
|
rsync -a "$src"/ "$dest"/
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_base_mountpoint() {
|
||||||
|
local rel=$1
|
||||||
|
local path="$BASE_ROOTFS_STAGING_DIR/$rel"
|
||||||
|
|
||||||
|
if [[ -e "$path" || -L "$path" ]]; then
|
||||||
|
chmod -R u+w "$path" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
rm -rf "$path"
|
||||||
|
mkdir -p "$path"
|
||||||
|
}
|
||||||
|
|
||||||
|
dir_size_mib() {
|
||||||
|
du -sm "$1" | awk '{ print $1 }'
|
||||||
|
}
|
||||||
|
|
||||||
|
build_ext4_image() {
|
||||||
|
local label=$1
|
||||||
|
local tree=$2
|
||||||
|
local image=$3
|
||||||
|
local size=$4
|
||||||
|
|
||||||
|
truncate -s "$size" "$image"
|
||||||
|
fakeroot -- bash -euo pipefail -c '
|
||||||
|
tree=$1
|
||||||
|
label=$2
|
||||||
|
image=$3
|
||||||
|
|
||||||
|
find "$tree" -xdev -exec chown -h 0:0 {} + 2>/dev/null || true
|
||||||
|
|
||||||
|
if [[ -d "$tree/home/forge" ]]; then
|
||||||
|
find "$tree/home/forge" -xdev -exec chown -h 1000:1000 {} + 2>/dev/null || true
|
||||||
|
chmod 0700 "$tree/home/forge"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ ! -d "$tree/root" ]] || chmod 0700 "$tree/root"
|
||||||
|
|
||||||
|
if [[ -d "$tree/nix/store" ]]; then
|
||||||
|
find "$tree/nix/store" -xdev -exec chown -h 0:30000 {} + 2>/dev/null || true
|
||||||
|
chmod 1775 "$tree/nix/store"
|
||||||
|
chmod -R ugo-w "$tree/nix/store"/* 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkfs.ext4 -F -L "$label" -d "$tree" "$image" >/dev/null
|
||||||
|
' bash "$tree" "$label" "$image"
|
||||||
|
}
|
||||||
|
|
||||||
|
write_atomic_fstab() {
|
||||||
|
cat > "$BASE_ROOTFS_STAGING_DIR/etc/fstab" <<EOF
|
||||||
|
# ForgeOS keeps the base OS read-only in disk images and mounts mutable
|
||||||
|
# applications and state from the app layer.
|
||||||
|
LABEL=$APP_LABEL /forge ext4 rw,relatime,nofail,x-systemd.device-timeout=5s 0 2
|
||||||
|
/forge/nix /nix none bind,nofail,x-systemd.after=forge.mount 0 0
|
||||||
|
/forge/home /home none bind,nofail,x-systemd.after=forge.mount 0 0
|
||||||
|
/forge/root /root none bind,nofail,x-systemd.after=forge.mount 0 0
|
||||||
|
/forge/var /var none bind,nofail,x-systemd.after=forge.mount 0 0
|
||||||
|
/forge/opt /opt none bind,nofail,x-systemd.after=forge.mount 0 0
|
||||||
|
/forge/usr-local /usr/local none bind,nofail,x-systemd.after=forge.mount 0 0
|
||||||
|
tmpfs /tmp tmpfs rw,nosuid,nodev,mode=1777 0 0
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_atomic_image_trees() {
|
||||||
|
msg "deriving atomic base and writable app layer trees"
|
||||||
|
|
||||||
|
reset_staging_tree "$BASE_ROOTFS_STAGING_DIR"
|
||||||
|
reset_staging_tree "$APPFS_STAGING_DIR"
|
||||||
|
|
||||||
|
rsync -a "$ROOTFS_STAGING_DIR"/ "$BASE_ROOTFS_STAGING_DIR"/
|
||||||
|
|
||||||
|
copy_app_path nix nix
|
||||||
|
copy_app_path home home
|
||||||
|
copy_app_path root root
|
||||||
|
copy_app_path var var
|
||||||
|
copy_app_path opt opt
|
||||||
|
copy_app_path usr/local usr-local
|
||||||
|
|
||||||
|
empty_base_mountpoint nix
|
||||||
|
empty_base_mountpoint home
|
||||||
|
empty_base_mountpoint root
|
||||||
|
empty_base_mountpoint var
|
||||||
|
empty_base_mountpoint opt
|
||||||
|
empty_base_mountpoint usr/local
|
||||||
|
mkdir -p "$BASE_ROOTFS_STAGING_DIR/forge"
|
||||||
|
write_atomic_fstab
|
||||||
|
|
||||||
|
chmod 0755 \
|
||||||
|
"$BASE_ROOTFS_STAGING_DIR/nix" \
|
||||||
|
"$BASE_ROOTFS_STAGING_DIR/home" \
|
||||||
|
"$BASE_ROOTFS_STAGING_DIR/var" \
|
||||||
|
"$BASE_ROOTFS_STAGING_DIR/opt" \
|
||||||
|
"$BASE_ROOTFS_STAGING_DIR/usr/local" \
|
||||||
|
"$BASE_ROOTFS_STAGING_DIR/forge" \
|
||||||
|
"$APPFS_STAGING_DIR"
|
||||||
|
chmod 0700 "$BASE_ROOTFS_STAGING_DIR/root"
|
||||||
|
[[ ! -d "$APPFS_STAGING_DIR/root" ]] || chmod 0700 "$APPFS_STAGING_DIR/root"
|
||||||
|
[[ ! -d "$APPFS_STAGING_DIR/home/forge" ]] || chmod 0700 "$APPFS_STAGING_DIR/home/forge"
|
||||||
|
|
||||||
|
find "$BASE_ROOTFS_STAGING_DIR" -printf '%P\n' | LC_ALL=C sort > "$OUT_DIR/base-rootfs.manifest"
|
||||||
|
find "$APPFS_STAGING_DIR" -printf '%P\n' | LC_ALL=C sort > "$OUT_DIR/appfs.manifest"
|
||||||
|
|
||||||
|
IMAGE_ROOTFS_DIR="$BASE_ROOTFS_STAGING_DIR"
|
||||||
|
APP_IMAGE_NEEDED=1
|
||||||
|
}
|
||||||
|
|
||||||
write_grub_config() {
|
write_grub_config() {
|
||||||
|
local root_mode=rw
|
||||||
|
|
||||||
|
if atomic_base_enabled; then
|
||||||
|
root_mode=ro
|
||||||
|
fi
|
||||||
|
|
||||||
cat > "$GRUB_CFG" <<'EOF'
|
cat > "$GRUB_CFG" <<'EOF'
|
||||||
set timeout=10
|
set timeout=10
|
||||||
set default=0
|
set default=0
|
||||||
@@ -63,7 +201,7 @@ set gfxpayload=keep
|
|||||||
insmod all_video
|
insmod all_video
|
||||||
insmod gfxterm
|
insmod gfxterm
|
||||||
terminal_output gfxterm console
|
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 linux_common="__LINUX_COMMON__"
|
||||||
set initrd_common="rdinit=/sbin/init"
|
set initrd_common="rdinit=/sbin/init"
|
||||||
set handoff_common="rdinit=/init forgeos.switch_root=1"
|
set handoff_common="rdinit=/init forgeos.switch_root=1"
|
||||||
|
|
||||||
@@ -88,6 +226,8 @@ menuentry "ForgeOS - firmware framebuffer safe mode" {
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
sed -i "s|__LINUX_COMMON__|root=PARTLABEL=root rootfstype=ext4 rootwait $root_mode console=tty0 loglevel=7 ignore_loglevel earlyprintk=efi,keep vt.global_cursor_default=1|" "$GRUB_CFG"
|
||||||
|
|
||||||
if [[ "$DESKTOP" != "gnome" ]] && ! truthy "$ENABLE_DESKTOP"; then
|
if [[ "$DESKTOP" != "gnome" ]] && ! truthy "$ENABLE_DESKTOP"; then
|
||||||
cat >> "$GRUB_CFG" <<'EOF'
|
cat >> "$GRUB_CFG" <<'EOF'
|
||||||
|
|
||||||
@@ -188,20 +328,54 @@ prepare_efi_loader() {
|
|||||||
msg "preparing EFI loader"
|
msg "preparing EFI loader"
|
||||||
prepare_efi_loader
|
prepare_efi_loader
|
||||||
|
|
||||||
|
if atomic_base_enabled; then
|
||||||
|
prepare_atomic_image_trees
|
||||||
|
|
||||||
|
BASE_USED_MIB=$(dir_size_mib "$BASE_ROOTFS_STAGING_DIR")
|
||||||
|
APP_USED_MIB=$(dir_size_mib "$APPFS_STAGING_DIR")
|
||||||
|
BASE_HEADROOM_MIB=${BASE_HEADROOM_MIB:-256}
|
||||||
|
APP_HEADROOM_MIB=${APP_HEADROOM_MIB:-1024}
|
||||||
|
BASE_SIZE_MIB=${BASE_SIZE_MIB:-$((BASE_USED_MIB + BASE_HEADROOM_MIB))}
|
||||||
|
BASE_MIN_MIB=$((BASE_USED_MIB + 64))
|
||||||
|
APP_MIN_MIB=$((APP_USED_MIB + APP_HEADROOM_MIB))
|
||||||
|
BASE_END_MIB=$((ESP_END_MIB + BASE_SIZE_MIB))
|
||||||
|
APP_SIZE_MIB=$((IMAGE_SIZE_MIB - BASE_END_MIB))
|
||||||
|
|
||||||
|
(( BASE_SIZE_MIB >= BASE_MIN_MIB )) || die "BASE_SIZE_MIB=$BASE_SIZE_MIB is too small; need at least ${BASE_MIN_MIB}MiB"
|
||||||
|
(( APP_SIZE_MIB >= APP_MIN_MIB )) || die "IMAGE_SIZE_MIB=$IMAGE_SIZE_MIB leaves ${APP_SIZE_MIB}MiB for apps; need at least ${APP_MIN_MIB}MiB"
|
||||||
|
|
||||||
|
msg "atomic layout: ${BASE_SIZE_MIB}MiB base root, ${APP_SIZE_MIB}MiB writable app/state layer"
|
||||||
|
fi
|
||||||
|
|
||||||
msg "creating raw image $IMAGE_PATH"
|
msg "creating raw image $IMAGE_PATH"
|
||||||
rm -f "$IMAGE_PATH" "$ESP_IMAGE" "$ROOT_IMAGE"
|
rm -f "$IMAGE_PATH" "$ESP_IMAGE" "$ROOT_IMAGE" "$APP_IMAGE"
|
||||||
qemu-img create -f raw "$IMAGE_PATH" "${IMAGE_SIZE_MIB}M" >/dev/null
|
qemu-img create -f raw "$IMAGE_PATH" "${IMAGE_SIZE_MIB}M" >/dev/null
|
||||||
parted -s "$IMAGE_PATH" mklabel gpt
|
parted -s "$IMAGE_PATH" mklabel gpt
|
||||||
parted -s "$IMAGE_PATH" mkpart ESP fat32 1MiB "${ESP_END_MIB}MiB"
|
parted -s "$IMAGE_PATH" mkpart ESP fat32 1MiB "${ESP_END_MIB}MiB"
|
||||||
parted -s "$IMAGE_PATH" set 1 esp on
|
parted -s "$IMAGE_PATH" set 1 esp on
|
||||||
|
if [[ "$APP_IMAGE_NEEDED" -eq 1 ]]; then
|
||||||
|
parted -s "$IMAGE_PATH" mkpart root ext4 "${ESP_END_MIB}MiB" "${BASE_END_MIB}MiB"
|
||||||
|
parted -s "$IMAGE_PATH" mkpart apps ext4 "${BASE_END_MIB}MiB" 100%
|
||||||
|
else
|
||||||
parted -s "$IMAGE_PATH" mkpart root ext4 "${ESP_END_MIB}MiB" 100%
|
parted -s "$IMAGE_PATH" mkpart root ext4 "${ESP_END_MIB}MiB" 100%
|
||||||
|
fi
|
||||||
|
|
||||||
ESP_OFFSET=$(partition_field 1 2)
|
ESP_OFFSET=$(partition_field 1 2)
|
||||||
ESP_SIZE=$(partition_field 1 4)
|
ESP_SIZE=$(partition_field 1 4)
|
||||||
ROOT_OFFSET=$(partition_field 2 2)
|
ROOT_OFFSET=$(partition_field 2 2)
|
||||||
ROOT_SIZE=$(partition_field 2 4)
|
ROOT_SIZE=$(partition_field 2 4)
|
||||||
|
if [[ "$APP_IMAGE_NEEDED" -eq 1 ]]; then
|
||||||
|
APP_OFFSET=$(partition_field 3 2)
|
||||||
|
APP_SIZE=$(partition_field 3 4)
|
||||||
|
else
|
||||||
|
APP_OFFSET=
|
||||||
|
APP_SIZE=
|
||||||
|
fi
|
||||||
|
|
||||||
[[ -n "$ESP_OFFSET" && -n "$ESP_SIZE" && -n "$ROOT_OFFSET" && -n "$ROOT_SIZE" ]] || die "failed to parse partition layout"
|
[[ -n "$ESP_OFFSET" && -n "$ESP_SIZE" && -n "$ROOT_OFFSET" && -n "$ROOT_SIZE" ]] || die "failed to parse partition layout"
|
||||||
|
if [[ "$APP_IMAGE_NEEDED" -eq 1 ]]; then
|
||||||
|
[[ -n "$APP_OFFSET" && -n "$APP_SIZE" ]] || die "failed to parse app partition layout"
|
||||||
|
fi
|
||||||
|
|
||||||
msg "building EFI partition image"
|
msg "building EFI partition image"
|
||||||
truncate -s "$ESP_SIZE" "$ESP_IMAGE"
|
truncate -s "$ESP_SIZE" "$ESP_IMAGE"
|
||||||
@@ -215,12 +389,19 @@ if [[ "$DESKTOP" != "gnome" ]] && ! truthy "$ENABLE_DESKTOP"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
msg "building ext4 root partition image"
|
msg "building ext4 root partition image"
|
||||||
truncate -s "$ROOT_SIZE" "$ROOT_IMAGE"
|
build_ext4_image "$ROOT_LABEL" "$IMAGE_ROOTFS_DIR" "$ROOT_IMAGE" "$ROOT_SIZE"
|
||||||
mkfs.ext4 -F -L "$ROOT_LABEL" -d "$ROOTFS_STAGING_DIR" "$ROOT_IMAGE" >/dev/null
|
|
||||||
|
if [[ "$APP_IMAGE_NEEDED" -eq 1 ]]; then
|
||||||
|
msg "building ext4 app/state partition image"
|
||||||
|
build_ext4_image "$APP_LABEL" "$APPFS_STAGING_DIR" "$APP_IMAGE" "$APP_SIZE"
|
||||||
|
fi
|
||||||
|
|
||||||
msg "embedding partitions into raw disk image"
|
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="$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
|
dd if="$ROOT_IMAGE" of="$IMAGE_PATH" bs=4M seek="$ROOT_OFFSET" oflag=seek_bytes conv=notrunc status=none
|
||||||
|
if [[ "$APP_IMAGE_NEEDED" -eq 1 ]]; then
|
||||||
|
dd if="$APP_IMAGE" of="$IMAGE_PATH" bs=4M seek="$APP_OFFSET" oflag=seek_bytes conv=notrunc status=none
|
||||||
|
fi
|
||||||
|
|
||||||
sync
|
sync
|
||||||
msg "disk image ready: $IMAGE_PATH"
|
msg "disk image ready: $IMAGE_PATH"
|
||||||
@@ -16,7 +16,7 @@ mkdir -p "$KERNEL_BUILD_DIR" "$MODULES_STAGING_DIR"
|
|||||||
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" x86_64_defconfig
|
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"
|
apply_kconfig_fragment "$KERNEL_BUILD_DIR/.config" "$ROOT_DIR/config/kernel.fragment"
|
||||||
cmdline_fragment=$(mktemp)
|
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"
|
printf 'CONFIG_CMDLINE="root=PARTLABEL=root rootfstype=ext4 rootwait ro 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"
|
apply_kconfig_fragment "$KERNEL_BUILD_DIR/.config" "$cmdline_fragment"
|
||||||
rm -f "$cmdline_fragment"
|
rm -f "$cmdline_fragment"
|
||||||
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" olddefconfig
|
make -C "$KERNEL_SRC_DIR" O="$KERNEL_BUILD_DIR" ARCH="$ARCH" olddefconfig
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ ensure_dirs
|
|||||||
[[ -x "$BUSYBOX_BUILD_DIR/busybox" && -f "$OUT_DIR/busybox.config" ]] || "$ROOT_DIR/scripts/build-busybox.sh"
|
[[ -x "$BUSYBOX_BUILD_DIR/busybox" && -f "$OUT_DIR/busybox.config" ]] || "$ROOT_DIR/scripts/build-busybox.sh"
|
||||||
grep -qx 'CONFIG_PAM=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh"
|
grep -qx 'CONFIG_PAM=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh"
|
||||||
grep -qx 'CONFIG_LOGIN_SESSION_AS_CHILD=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh"
|
grep -qx 'CONFIG_LOGIN_SESSION_AS_CHILD=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh"
|
||||||
|
grep -qx 'CONFIG_AWK=y' "$OUT_DIR/busybox.config" || "$ROOT_DIR/scripts/build-busybox.sh"
|
||||||
[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" && -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd-logind" && -f "$SYSTEMD_STAGING_DIR/usr/lib/security/pam_systemd.so" && -f "$SYSTEMD_STAGING_DIR/.forgeos-systemd-complete" ]] || "$ROOT_DIR/scripts/build-systemd.sh"
|
[[ -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd" && -x "$SYSTEMD_STAGING_DIR/usr/lib/systemd/systemd-logind" && -f "$SYSTEMD_STAGING_DIR/usr/lib/security/pam_systemd.so" && -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"
|
[[ -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"
|
[[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
|
||||||
@@ -84,7 +85,7 @@ rsync -a "$SYSTEMD_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/
|
|||||||
rsync -a "$DBUS_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/
|
rsync -a "$DBUS_STAGING_DIR"/ "$ROOTFS_STAGING_DIR"/
|
||||||
copy_busybox_deps
|
copy_busybox_deps
|
||||||
|
|
||||||
mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,home/forge,boot,mnt,etc/systemd/system}
|
mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,home/forge,boot,mnt,forge,opt,usr/local,etc/systemd/system}
|
||||||
rsync -a "$OVERLAY_DIR"/ "$ROOTFS_STAGING_DIR"/
|
rsync -a "$OVERLAY_DIR"/ "$ROOTFS_STAGING_DIR"/
|
||||||
"$ROOT_DIR/scripts/stage-nix.sh"
|
"$ROOT_DIR/scripts/stage-nix.sh"
|
||||||
|
|
||||||
@@ -93,6 +94,8 @@ ln -s ../usr/lib/systemd/systemd "$ROOTFS_STAGING_DIR/sbin/init"
|
|||||||
ln -sfn ../../sbin/modprobe "$ROOTFS_STAGING_DIR/usr/bin/modprobe"
|
ln -sfn ../../sbin/modprobe "$ROOTFS_STAGING_DIR/usr/bin/modprobe"
|
||||||
ln -sfn ../run/systemd/resolve/resolv.conf "$ROOTFS_STAGING_DIR/etc/resolv.conf"
|
ln -sfn ../run/systemd/resolve/resolv.conf "$ROOTFS_STAGING_DIR/etc/resolv.conf"
|
||||||
ln -sfn ../run "$ROOTFS_STAGING_DIR/var/run"
|
ln -sfn ../run "$ROOTFS_STAGING_DIR/var/run"
|
||||||
|
: > "$ROOTFS_STAGING_DIR/etc/machine-id"
|
||||||
|
chmod 0444 "$ROOTFS_STAGING_DIR/etc/machine-id"
|
||||||
|
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
"$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants" \
|
"$ROOTFS_STAGING_DIR/etc/systemd/system/getty.target.wants" \
|
||||||
@@ -164,6 +167,7 @@ chmod 755 \
|
|||||||
"$ROOTFS_STAGING_DIR/sbin/forgeos-console-banner" \
|
"$ROOTFS_STAGING_DIR/sbin/forgeos-console-banner" \
|
||||||
"$ROOTFS_STAGING_DIR/sbin/forgeos-switch-root" \
|
"$ROOTFS_STAGING_DIR/sbin/forgeos-switch-root" \
|
||||||
"$ROOTFS_STAGING_DIR/usr/lib/forgeos/nix-bootstrap" \
|
"$ROOTFS_STAGING_DIR/usr/lib/forgeos/nix-bootstrap" \
|
||||||
|
"$ROOTFS_STAGING_DIR/usr/bin/forgeos-app" \
|
||||||
"$ROOTFS_STAGING_DIR/usr/bin/neofetch" \
|
"$ROOTFS_STAGING_DIR/usr/bin/neofetch" \
|
||||||
"$ROOTFS_STAGING_DIR/usr/share/udhcpc/default.script"
|
"$ROOTFS_STAGING_DIR/usr/share/udhcpc/default.script"
|
||||||
chmod 700 "$ROOTFS_STAGING_DIR/root" "$ROOTFS_STAGING_DIR/home/forge"
|
chmod 700 "$ROOTFS_STAGING_DIR/root" "$ROOTFS_STAGING_DIR/home/forge"
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ DESKTOP=${DESKTOP:-console}
|
|||||||
ENABLE_DESKTOP=${ENABLE_DESKTOP:-0}
|
ENABLE_DESKTOP=${ENABLE_DESKTOP:-0}
|
||||||
ROOT_LABEL=${ROOT_LABEL:-FORGE_ROOT}
|
ROOT_LABEL=${ROOT_LABEL:-FORGE_ROOT}
|
||||||
EFI_LABEL=${EFI_LABEL:-FORGE_EFI}
|
EFI_LABEL=${EFI_LABEL:-FORGE_EFI}
|
||||||
|
APP_LABEL=${APP_LABEL:-FORGE_APPS}
|
||||||
|
ATOMIC_BASE=${ATOMIC_BASE:-1}
|
||||||
case "$DESKTOP" in
|
case "$DESKTOP" in
|
||||||
console|gnome) ;;
|
console|gnome) ;;
|
||||||
*)
|
*)
|
||||||
@@ -83,6 +85,8 @@ SYSTEMD_STAGING_DIR="$STAGING_DIR/systemd"
|
|||||||
DBUS_STAGING_DIR="$STAGING_DIR/dbus"
|
DBUS_STAGING_DIR="$STAGING_DIR/dbus"
|
||||||
PAM_STAGING_DIR="$STAGING_DIR/pam"
|
PAM_STAGING_DIR="$STAGING_DIR/pam"
|
||||||
ROOTFS_STAGING_DIR="$STAGING_DIR/rootfs"
|
ROOTFS_STAGING_DIR="$STAGING_DIR/rootfs"
|
||||||
|
BASE_ROOTFS_STAGING_DIR="$STAGING_DIR/rootfs-base"
|
||||||
|
APPFS_STAGING_DIR="$STAGING_DIR/appfs"
|
||||||
OPENBOX_DESKTOP_DEB_DIR=${OPENBOX_DESKTOP_DEB_DIR:-"$DOWNLOAD_DIR/openbox-desktop-debs"}
|
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"}
|
OPENBOX_DESKTOP_APT_STATE_DIR=${OPENBOX_DESKTOP_APT_STATE_DIR:-"$BUILD_DIR/openbox-desktop-apt-state"}
|
||||||
|
|
||||||
@@ -116,6 +120,10 @@ truthy() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atomic_base_enabled() {
|
||||||
|
[[ "$DESKTOP" != "gnome" ]] && truthy "$ATOMIC_BASE"
|
||||||
|
}
|
||||||
|
|
||||||
ensure_dirs() {
|
ensure_dirs() {
|
||||||
mkdir -p "$DOWNLOAD_DIR" "$SOURCE_DIR" "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR"
|
mkdir -p "$DOWNLOAD_DIR" "$SOURCE_DIR" "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ image_packages=(
|
|||||||
grub-common
|
grub-common
|
||||||
grub-efi-amd64-bin
|
grub-efi-amd64-bin
|
||||||
ovmf
|
ovmf
|
||||||
|
fakeroot
|
||||||
)
|
)
|
||||||
|
|
||||||
required_commands=(
|
required_commands=(
|
||||||
@@ -31,6 +32,7 @@ required_commands=(
|
|||||||
awk
|
awk
|
||||||
truncate
|
truncate
|
||||||
qemu-system-x86_64
|
qemu-system-x86_64
|
||||||
|
fakeroot
|
||||||
)
|
)
|
||||||
|
|
||||||
required_paths=(
|
required_paths=(
|
||||||
|
|||||||
+63
-32
@@ -7,9 +7,9 @@ source "$(dirname "$0")/common.sh"
|
|||||||
IMAGE_PATH="$OUT_DIR/forgeos-${KERNEL_VERSION}.img"
|
IMAGE_PATH="$OUT_DIR/forgeos-${KERNEL_VERSION}.img"
|
||||||
DEVICE=""
|
DEVICE=""
|
||||||
AUTO_CONFIRM=0
|
AUTO_CONFIRM=0
|
||||||
EXPAND_ROOT=1
|
EXPAND_WRITABLE=1
|
||||||
LIST_ONLY=0
|
LIST_ONLY=0
|
||||||
RANDOMIZE_ROOT_UUID=1
|
RANDOMIZE_FS_UUIDS=1
|
||||||
UNMOUNT_TARGET=0
|
UNMOUNT_TARGET=0
|
||||||
CUSTOM_IMAGE=0
|
CUSTOM_IMAGE=0
|
||||||
|
|
||||||
@@ -25,8 +25,10 @@ Options:
|
|||||||
--list Show candidate disk devices and exit.
|
--list Show candidate disk devices and exit.
|
||||||
--yes Skip the interactive destruction prompt.
|
--yes Skip the interactive destruction prompt.
|
||||||
--unmount Unmount non-critical mounted target partitions first.
|
--unmount Unmount non-critical mounted target partitions first.
|
||||||
--no-expand-root Keep the root partition at the image's built size.
|
--no-expand-apps Keep the writable app/state partition at the image's built size.
|
||||||
--keep-root-uuid Preserve the ext4 root filesystem UUID.
|
--no-expand-root Legacy alias for --no-expand-apps.
|
||||||
|
--keep-uuids Preserve ext4 filesystem UUIDs.
|
||||||
|
--keep-root-uuid Legacy alias for --keep-uuids.
|
||||||
--help Show this help text.
|
--help Show this help text.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
@@ -128,7 +130,7 @@ ensure_target_is_safe() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
for critical_mount in / /boot /boot/efi /home; do
|
for critical_mount in / /boot /boot/efi /home /nix /var /forge /opt /usr/local; do
|
||||||
source=$(findmnt -nr -o SOURCE "$critical_mount" 2>/dev/null || true)
|
source=$(findmnt -nr -o SOURCE "$critical_mount" 2>/dev/null || true)
|
||||||
if critical_source_on_target "$source"; then
|
if critical_source_on_target "$source"; then
|
||||||
die "refusing to overwrite active system storage mounted at $critical_mount"
|
die "refusing to overwrite active system storage mounted at $critical_mount"
|
||||||
@@ -160,7 +162,7 @@ unmount_target_children() {
|
|||||||
part=${entry%%|*}
|
part=${entry%%|*}
|
||||||
mountpoint=${entry#*|}
|
mountpoint=${entry#*|}
|
||||||
case "$mountpoint" in
|
case "$mountpoint" in
|
||||||
/|/boot|/boot/efi|/home)
|
/|/boot|/boot/efi|/home|/nix|/var|/forge|/opt|/usr/local)
|
||||||
die "refusing to unmount critical mountpoint $mountpoint on $part"
|
die "refusing to unmount critical mountpoint $mountpoint on $part"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -225,45 +227,74 @@ repair_and_rescan_partitions() {
|
|||||||
udevadm settle >/dev/null 2>&1 || true
|
udevadm settle >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_root_partition() {
|
partition_fstype() {
|
||||||
|
lsblk -dnro FSTYPE "$1" 2>/dev/null | head -n1
|
||||||
|
}
|
||||||
|
|
||||||
|
writable_partition_number() {
|
||||||
|
local apps_part
|
||||||
|
|
||||||
|
apps_part=$(partition_path "$DEVICE" 3)
|
||||||
|
if [[ -b "$apps_part" ]]; then
|
||||||
|
printf '3\n'
|
||||||
|
else
|
||||||
|
printf '2\n'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
expand_writable_partition() {
|
||||||
local image_size
|
local image_size
|
||||||
local device_size
|
local device_size
|
||||||
local root_part
|
local part_num
|
||||||
|
local target_part
|
||||||
|
local target_name
|
||||||
|
|
||||||
image_size=$(stat -c %s "$IMAGE_PATH")
|
image_size=$(stat -c %s "$IMAGE_PATH")
|
||||||
device_size=$(device_size_bytes "$DEVICE")
|
device_size=$(device_size_bytes "$DEVICE")
|
||||||
root_part=$(partition_path "$DEVICE" 2)
|
part_num=$(writable_partition_number)
|
||||||
|
target_part=$(partition_path "$DEVICE" "$part_num")
|
||||||
|
if [[ "$part_num" == "3" ]]; then
|
||||||
|
target_name="app/state"
|
||||||
|
else
|
||||||
|
target_name="root"
|
||||||
|
fi
|
||||||
|
|
||||||
wait_for_block "$root_part"
|
wait_for_block "$target_part"
|
||||||
|
|
||||||
if (( device_size <= image_size )) || [[ "$EXPAND_ROOT" -ne 1 ]]; then
|
if (( device_size <= image_size )) || [[ "$EXPAND_WRITABLE" -ne 1 ]]; then
|
||||||
msg "leaving root partition at image size"
|
msg "leaving $target_name partition at image size"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg "expanding root partition to fill the remaining disk"
|
msg "expanding $target_name partition to fill the remaining disk"
|
||||||
parted -s -f "$DEVICE" resizepart 2 100%
|
parted -s -f "$DEVICE" resizepart "$part_num" 100%
|
||||||
partprobe "$DEVICE" >/dev/null 2>&1 || true
|
partprobe "$DEVICE" >/dev/null 2>&1 || true
|
||||||
udevadm settle >/dev/null 2>&1 || true
|
udevadm settle >/dev/null 2>&1 || true
|
||||||
wait_for_block "$root_part"
|
wait_for_block "$target_part"
|
||||||
|
|
||||||
msg "checking ext4 root filesystem"
|
msg "checking ext4 $target_name filesystem"
|
||||||
e2fsck -fy "$root_part" >/dev/null
|
e2fsck -fy "$target_part" >/dev/null
|
||||||
|
|
||||||
msg "resizing ext4 root filesystem"
|
msg "resizing ext4 $target_name filesystem"
|
||||||
resize2fs "$root_part" >/dev/null
|
resize2fs "$target_part" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
randomize_root_uuid() {
|
randomize_ext4_uuids() {
|
||||||
local root_part
|
local part_num
|
||||||
|
local part
|
||||||
|
local fs_type
|
||||||
|
|
||||||
[[ "$RANDOMIZE_ROOT_UUID" -eq 1 ]] || return 0
|
[[ "$RANDOMIZE_FS_UUIDS" -eq 1 ]] || return 0
|
||||||
|
|
||||||
root_part=$(partition_path "$DEVICE" 2)
|
for part_num in 2 3; do
|
||||||
wait_for_block "$root_part"
|
part=$(partition_path "$DEVICE" "$part_num")
|
||||||
|
[[ -b "$part" ]] || continue
|
||||||
|
fs_type=$(partition_fstype "$part")
|
||||||
|
[[ "$fs_type" == "ext4" ]] || continue
|
||||||
|
|
||||||
msg "randomizing ext4 root filesystem UUID"
|
msg "randomizing ext4 filesystem UUID on $part"
|
||||||
tune2fs -U random "$root_part" >/dev/null
|
tune2fs -U random "$part" >/dev/null
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
print_summary() {
|
print_summary() {
|
||||||
@@ -296,12 +327,12 @@ while [[ $# -gt 0 ]]; do
|
|||||||
UNMOUNT_TARGET=1
|
UNMOUNT_TARGET=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--no-expand-root)
|
--no-expand-apps|--no-expand-root)
|
||||||
EXPAND_ROOT=0
|
EXPAND_WRITABLE=0
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--keep-root-uuid)
|
--keep-uuids|--keep-root-uuid)
|
||||||
RANDOMIZE_ROOT_UUID=0
|
RANDOMIZE_FS_UUIDS=0
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--help|-h)
|
--help|-h)
|
||||||
@@ -339,8 +370,8 @@ fi
|
|||||||
confirm_install
|
confirm_install
|
||||||
write_image
|
write_image
|
||||||
repair_and_rescan_partitions
|
repair_and_rescan_partitions
|
||||||
expand_root_partition
|
expand_writable_partition
|
||||||
randomize_root_uuid
|
randomize_ext4_uuids
|
||||||
repair_and_rescan_partitions
|
repair_and_rescan_partitions
|
||||||
print_summary
|
print_summary
|
||||||
|
|
||||||
|
|||||||
+39
-4
@@ -119,11 +119,41 @@ mkdir -p \\
|
|||||||
"\$NIX_STATE/daemon-socket" \\
|
"\$NIX_STATE/daemon-socket" \\
|
||||||
/root
|
/root
|
||||||
|
|
||||||
chown root:root /nix /nix/var /nix/var/nix /nix/var/log /nix/var/log/nix /nix/var/log/nix/drvs 2>/dev/null || true
|
chown root:root \\
|
||||||
|
/nix \\
|
||||||
|
/nix/var \\
|
||||||
|
/nix/var/log \\
|
||||||
|
/nix/var/log/nix \\
|
||||||
|
/nix/var/log/nix/drvs \\
|
||||||
|
"\$NIX_STATE" \\
|
||||||
|
"\$NIX_STATE/bootstrap" \\
|
||||||
|
"\$NIX_STATE/db" \\
|
||||||
|
"\$NIX_STATE/gcroots" \\
|
||||||
|
"\$NIX_STATE/gcroots/per-user" \\
|
||||||
|
"\$NIX_STATE/profiles" \\
|
||||||
|
"\$NIX_STATE/profiles/per-user" \\
|
||||||
|
"\$NIX_STATE/temproots" \\
|
||||||
|
"\$NIX_STATE/userpool" \\
|
||||||
|
"\$NIX_STATE/daemon-socket" 2>/dev/null || true
|
||||||
chown -R root:nixbld /nix/store 2>/dev/null || true
|
chown -R root:nixbld /nix/store 2>/dev/null || true
|
||||||
chmod 1775 /nix/store
|
chmod 1775 /nix/store
|
||||||
chmod -R ugo-w /nix/store/* 2>/dev/null || true
|
chmod -R ugo-w /nix/store/* 2>/dev/null || true
|
||||||
chmod 0755 "\$NIX_STATE" "\$NIX_STATE/bootstrap" "\$NIX_STATE/daemon-socket"
|
chmod 0755 \\
|
||||||
|
/nix \\
|
||||||
|
/nix/var \\
|
||||||
|
/nix/var/log \\
|
||||||
|
/nix/var/log/nix \\
|
||||||
|
/nix/var/log/nix/drvs \\
|
||||||
|
"\$NIX_STATE" \\
|
||||||
|
"\$NIX_STATE/bootstrap" \\
|
||||||
|
"\$NIX_STATE/db" \\
|
||||||
|
"\$NIX_STATE/gcroots" \\
|
||||||
|
"\$NIX_STATE/gcroots/per-user" \\
|
||||||
|
"\$NIX_STATE/profiles" \\
|
||||||
|
"\$NIX_STATE/profiles/per-user" \\
|
||||||
|
"\$NIX_STATE/temproots" \\
|
||||||
|
"\$NIX_STATE/userpool" \\
|
||||||
|
"\$NIX_STATE/daemon-socket"
|
||||||
|
|
||||||
if [ -e "\$MARKER" ]; then
|
if [ -e "\$MARKER" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
@@ -151,9 +181,11 @@ cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/forgeos-nix-bootstrap.service" <<'
|
|||||||
Description=Bootstrap ForgeOS Nix store
|
Description=Bootstrap ForgeOS Nix store
|
||||||
DefaultDependencies=no
|
DefaultDependencies=no
|
||||||
After=local-fs.target
|
After=local-fs.target
|
||||||
Before=sockets.target multi-user.target
|
Before=nix-daemon.socket nix-daemon.service sockets.target multi-user.target
|
||||||
|
RequiresMountsFor=/nix/store
|
||||||
|
RequiresMountsFor=/nix/var/nix/bootstrap
|
||||||
|
RequiresMountsFor=/nix/var/nix/db
|
||||||
ConditionPathExists=/nix/var/nix/bootstrap/reginfo
|
ConditionPathExists=/nix/var/nix/bootstrap/reginfo
|
||||||
ConditionPathExists=!/nix/var/nix/forgeos-bootstrap-complete
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
@@ -169,6 +201,7 @@ cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/nix-daemon.service" <<EOF
|
|||||||
Description=Nix package manager daemon
|
Description=Nix package manager daemon
|
||||||
Documentation=man:nix-daemon https://nixos.org/manual
|
Documentation=man:nix-daemon https://nixos.org/manual
|
||||||
After=forgeos-nix-bootstrap.service
|
After=forgeos-nix-bootstrap.service
|
||||||
|
Requires=forgeos-nix-bootstrap.service
|
||||||
RequiresMountsFor=/nix/store
|
RequiresMountsFor=/nix/store
|
||||||
RequiresMountsFor=/nix/var
|
RequiresMountsFor=/nix/var
|
||||||
RequiresMountsFor=/nix/var/nix/db
|
RequiresMountsFor=/nix/var/nix/db
|
||||||
@@ -188,7 +221,9 @@ EOF
|
|||||||
cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/nix-daemon.socket" <<'EOF'
|
cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/nix-daemon.socket" <<'EOF'
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Nix package manager daemon socket
|
Description=Nix package manager daemon socket
|
||||||
|
After=forgeos-nix-bootstrap.service
|
||||||
Before=multi-user.target
|
Before=multi-user.target
|
||||||
|
Requires=forgeos-nix-bootstrap.service
|
||||||
RequiresMountsFor=/nix/store
|
RequiresMountsFor=/nix/store
|
||||||
ConditionPathIsReadWrite=/nix/var/nix/daemon-socket
|
ConditionPathIsReadWrite=/nix/var/nix/daemon-socket
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user