Skip to content

Commit c8f4084

Browse files
committed
New systemd prototype
1 parent 4eb5a63 commit c8f4084

36 files changed

+518
-258
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ mkosi.cache/
66
mkosi.builddir/
77
*.qcow2
88
.claudesync/
9-
.claudeignore
9+
.claudeignore
10+
tmp/

base/base.conf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[Distribution]
2+
Distribution=debian
3+
Release=trixie
4+
5+
[Output]
6+
Format=uki
7+
ImageId=tdx-debian
8+
OutputDirectory=build
9+
PackageCacheDirectory=mkosi.cache
10+
Seed=630b5f72-a36a-4e83-b23d-6ef47c82fd9c
11+
12+
[Host]
13+
# Incremental=true
14+
15+
[Content]
16+
SourceDateEpoch=0
17+
KernelCommandLine=console=tty0 console=ttyS0,115200n8 mitigations=auto,nosmt spec_store_bypass_disable=on nospectre_v2
18+
Environment=KERNEL_IMAGE KERNEL_VERSION
19+
SkeletonTrees=base/mkosi.skeleton
20+
FinalizeScripts=base/debloat.sh
21+
PostInstallationScripts=base/debloat-systemd.sh
22+
BuildScripts=base/mkosi.build
23+
PrepareScripts=base/export-packages.sh
24+
25+
CleanPackageMetadata=true
26+
Packages=kmod
27+
systemd
28+
systemd-boot-efi
29+
busybox
30+
util-linux
31+
iproute2
32+
udhcpc
33+
e2fsprogs
34+
BuildPackages=build-essential
35+
git
36+
curl
37+
cmake
38+
pkg-config
39+
clang
40+
cargo

base/debloat-systemd.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Core systemd units to keep
5+
systemd_svc_whitelist=(
6+
"minimal.target"
7+
"basic.target"
8+
"sysinit.target"
9+
"sockets.target"
10+
"local-fs.target"
11+
"local-fs-pre.target"
12+
"slices.target"
13+
"systemd-journald.service"
14+
"systemd-journald.socket"
15+
"systemd-journald-dev-log.socket"
16+
"systemd-remount-fs.service"
17+
"systemd-sysctl.service"
18+
)
19+
20+
# Keep only essential systemd binaries
21+
systemd_bin_whitelist=(
22+
"systemctl"
23+
"journalctl"
24+
"systemd"
25+
)
26+
27+
mkosi-chroot dpkg-query -L systemd | grep -E '^/usr/bin/' | while read -r bin_path; do
28+
bin_name=$(basename "$bin_path")
29+
if ! printf '%s\n' "${systemd_bin_whitelist[@]}" | grep -qx "$bin_name"; then
30+
rm -f "$BUILDROOT$bin_path"
31+
fi
32+
done
33+
34+
# Get all systemd units and mask those not in service whitelist
35+
SYSTEMD_DIR="$BUILDROOT/etc/systemd/system"
36+
mkosi-chroot dpkg-query -L systemd | grep -E '\.service$|\.socket$|\.timer$|\.target$|\.mount$' | sed 's|.*/||' | while read -r unit; do
37+
if ! printf '%s\n' "${systemd_svc_whitelist[@]}" | grep -qx "$unit"; then
38+
ln -sf /dev/null "$SYSTEMD_DIR/$unit"
39+
fi
40+
done
41+
42+
# Set default target
43+
ln -sf minimal.target "$SYSTEMD_DIR/default.target"

base/debloat.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Remove all logs and cache, but keep directory structure intact
5+
find "$BUILDROOT/var/log" -type f -delete
6+
find "$BUILDROOT/var/cache" -type f -delete
7+
8+
debloat_paths=(
9+
"/etc/machine-id"
10+
"/etc/*-"
11+
"/usr/share/doc"
12+
"/usr/share/man"
13+
"/usr/share/info"
14+
"/usr/share/locale"
15+
"/usr/share/gcc"
16+
"/usr/share/gdb"
17+
"/usr/share/lintian"
18+
"/usr/share/perl5/debconf"
19+
"/usr/share/debconf"
20+
"/usr/share/initramfs-tools"
21+
"/usr/share/polkit-1"
22+
"/usr/share/bug"
23+
"/usr/share/menu"
24+
"/usr/share/systemd"
25+
"/usr/share/bash-completion"
26+
"/usr/share/zsh"
27+
"/usr/share/mime"
28+
"/usr/lib/modules"
29+
"/usr/lib/udev/hwdb.d"
30+
"/usr/lib/systemd/catalog"
31+
"/usr/lib/systemd/user"
32+
"/usr/lib/systemd/user-generators"
33+
"/usr/lib/systemd/network"
34+
"/usr/lib/pcrlock.d"
35+
"/usr/lib/tmpfiles.d"
36+
"/etc/systemd/network"
37+
"/etc/credstore"
38+
"/usr/lib/x86_64-linux-gnu/security"
39+
)
40+
41+
for p in "${debloat_paths[@]}"; do rm -rf "$BUILDROOT$p"; done

base/export-packages.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
if [ "$1" == "final" ]; then
4+
dpkg-query -W -f='${Package},${Architecture},${Version}\n' > $SRCDIR/build/packages.csv
5+
fi

mkosi.prepare renamed to base/mkosi.build

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ if [ -z "$KERNEL_IMAGE" ] || [ -z "$KERNEL_VERSION" ]; then
77
fi
88

99
# Copy kernel and config to a place where mkosi can find it
10-
mkdir -p "$BUILDROOT/usr/lib/modules/$KERNEL_VERSION"
11-
cp "$KERNEL_IMAGE" "$BUILDROOT/usr/lib/modules/$KERNEL_VERSION/vmlinuz"
12-
cp ./kernel-yocto.config "$BUILDROOT/boot/config-$KERNEL_VERSION"
10+
mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_VERSION"
11+
cp "$KERNEL_IMAGE" "$DESTDIR/usr/lib/modules/$KERNEL_VERSION/vmlinuz"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nameserver 8.8.8.8
2+
nameserver 8.8.4.4
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Minimal System
3+
Requires=basic.target
4+
Conflicts=rescue.service rescue.target
5+
After=basic.target rescue.service rescue.target
6+
AllowIsolate=yes
7+
8+
[Install]
9+
WantedBy=default.target
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Basic Network Setup
3+
DefaultDependencies=no
4+
Before=network.target
5+
Wants=network.target
6+
7+
[Service]
8+
Type=oneshot
9+
ExecStart=ip link set lo up
10+
ExecStart=ip link set eth0 up
11+
ExecStart=chattr +i /etc/resolv.conf
12+
ExecStart=/usr/sbin/udhcpc -i eth0 -n
13+
RemainAfterExit=yes
14+
15+
[Install]
16+
WantedBy=sysinit.target
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Setup Persistent Storage
3+
DefaultDependencies=no
4+
After=local-fs-pre.target
5+
Before=local-fs.target
6+
7+
[Service]
8+
Type=oneshot
9+
ExecStart=/bin/sh -c "if [ -e /dev/vda ] && ! blkid /dev/vda | grep -q 'TYPE=\"ext4\"'; then mkfs.ext4 -F /dev/vda; fi"
10+
ExecStart=/bin/sh -c "mkdir -p /persistent"
11+
ExecStart=/bin/sh -c "mount /dev/vda /persistent || echo 'Failed to mount persistent storage'"
12+
RemainAfterExit=yes
13+
14+
[Install]
15+
WantedBy=sysinit.target

0 commit comments

Comments
 (0)