2025-02-24 16:13:43 +01:00
|
|
|
set -ex -o pipefail
|
|
|
|
|
|
|
|
mkdir -p $out/repart.d $out/boot
|
|
|
|
pushd $out
|
|
|
|
|
|
|
|
# Don't seem to work just to create a symlink to rootfs derivation?
|
|
|
|
# ln -sf $rootfs rootfs
|
|
|
|
mkdir rootfs
|
|
|
|
cp -prP $rootfs/* rootfs/
|
|
|
|
find rootfs/ -type d -exec chmod 755 {} \;
|
|
|
|
|
2025-02-25 11:40:34 +01:00
|
|
|
# set default target to basic
|
|
|
|
mkdir rootfs/usr/lib/systemd/system/basic.target.wants
|
|
|
|
ln -sf basic.target rootfs/usr/lib/systemd/system/default.target
|
|
|
|
|
2025-02-25 13:39:02 +01:00
|
|
|
# mount patos state
|
|
|
|
cat <<EOF > rootfs/usr/lib/systemd/system/var.mount
|
|
|
|
[Unit]
|
|
|
|
Description=Mount for /var
|
|
|
|
Before=local-fs.target
|
|
|
|
|
|
|
|
[Mount]
|
|
|
|
What=/dev/disk/by-label/patos-state
|
|
|
|
Where=/var
|
|
|
|
Type=ext2
|
|
|
|
Options=defaults
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=basic.target
|
|
|
|
EOF
|
|
|
|
ln -sf ../var.mount rootfs/usr/lib/systemd/system/basic.target.wants/var.mount
|
|
|
|
|
2025-02-25 11:40:34 +01:00
|
|
|
# enable dbus
|
|
|
|
ln -sf ../dbus.service rootfs/usr/lib/systemd/system/basic.target.wants/dbus.service
|
|
|
|
ln -sf ../dbus.socket rootfs/usr/lib/systemd/system/sockets.target.wants/dbus.socket
|
|
|
|
|
2025-02-25 13:39:02 +01:00
|
|
|
# generate a temporary machine id
|
2025-02-25 11:40:34 +01:00
|
|
|
$systemd/usr/bin/systemd-machine-id-setup --root=rootfs/
|
|
|
|
|
|
|
|
cat <<EOF > rootfs/etc/passwd
|
|
|
|
root::0:0:root:/root:/bin/sh
|
|
|
|
bin:x:1:1:bin:/bin:/usr/bin/nologin
|
|
|
|
daemon:x:2:2:daemon:/:/usr/bin/nologin
|
|
|
|
mail:x:8:12:mail:/var/spool/mail:/usr/bin/nologin
|
|
|
|
ftp:x:14:11:ftp:/srv/ftp:/usr/bin/nologin
|
|
|
|
http:x:33:33:http:/srv/http:/usr/bin/nologin
|
|
|
|
uuidd:x:68:68:uuidd:/:/usr/bin/nologin
|
|
|
|
messagebus:x:81:81:messagebus:/:/usr/bin/nologin
|
|
|
|
nobody:x:99:99:nobody:/:/usr/bin/nologin
|
|
|
|
systemd-coredump:x:151:992::/var/empty:/usr/bin/nologin
|
|
|
|
systemd-network:x:152:152::/var/empty:/usr/bin/nologin
|
|
|
|
systemd-resolve:x:153:153::/var/empty:/usr/bin/nologin
|
|
|
|
systemd-timesync:x:154:154::/var/empty:/usr/bin/nologin
|
|
|
|
EOF
|
|
|
|
chmod 644 rootfs/etc/passwd
|
|
|
|
|
|
|
|
cat <<EOF > rootfs/etc/group
|
|
|
|
root:x:0:root
|
|
|
|
bin:x:1:root,bin,daemon
|
|
|
|
daemon:x:2:root,bin,daemon
|
|
|
|
sys:x:3:root,bin
|
|
|
|
adm:x:4:root,daemon
|
|
|
|
tty:x:5:
|
|
|
|
disk:x:6:root
|
|
|
|
lp:x:7:daemon
|
|
|
|
mem:x:8:
|
|
|
|
kmem:x:9:
|
|
|
|
wheel:x:10:root
|
|
|
|
ftp:x:11:
|
|
|
|
mail:x:12:
|
|
|
|
uucp:x:14:
|
|
|
|
log:x:19:root
|
|
|
|
utmp:x:20:
|
|
|
|
locate:x:21:
|
|
|
|
rfkill:x:24:
|
|
|
|
smmsp:x:25:
|
|
|
|
proc:x:26:
|
|
|
|
http:x:33:
|
|
|
|
games:x:50:
|
|
|
|
lock:x:54:
|
|
|
|
uuidd:x:68:
|
|
|
|
messagebus:x:81:
|
|
|
|
systemd-journal:x:62:
|
|
|
|
systemd-network:x:152:
|
|
|
|
systemd-resolve:x:153:
|
|
|
|
systemd-timesync:x:154:
|
|
|
|
systemd-oom:x:991:
|
|
|
|
systemd-coredump:x:992:
|
|
|
|
network:x:90:
|
|
|
|
video:x:91:
|
|
|
|
audio:x:92:
|
|
|
|
optical:x:93:
|
|
|
|
floppy:x:94:
|
|
|
|
storage:x:95:
|
|
|
|
scanner:x:96:
|
|
|
|
input:x:97:
|
|
|
|
power:x:98:
|
|
|
|
nobody:x:99:
|
|
|
|
EOF
|
|
|
|
chmod 644 rootfs/etc/group
|
|
|
|
|
|
|
|
# FIXME: remove this later (just to get a shell in the initramfs)
|
|
|
|
cat <<EOF > rootfs/usr/lib/systemd/system/demo.service
|
|
|
|
[Unit]
|
|
|
|
Description=Debug Shell (/bin/sulogin)
|
|
|
|
Conflicts=shutdown.target
|
|
|
|
Before=shutdown.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Environment=HOME=/root
|
|
|
|
WorkingDirectory=/root
|
|
|
|
ExecStart=/bin/sulogin
|
|
|
|
Type=idle
|
|
|
|
StandardInput=tty-force
|
|
|
|
StandardOutput=inherit
|
|
|
|
StandardError=inherit
|
|
|
|
KillMode=process
|
|
|
|
IgnoreSIGPIPE=no
|
|
|
|
SendSIGHUP=yes
|
|
|
|
Restart=always
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=basic.target
|
|
|
|
EOF
|
|
|
|
ln -sf ../demo.service rootfs/usr/lib/systemd/system/basic.target.wants/demo.service
|
|
|
|
|
|
|
|
|
2025-02-24 16:13:43 +01:00
|
|
|
$systemd/usr/bin/ukify build \
|
|
|
|
--linux $kernel/bzImage \
|
|
|
|
--initrd $initrd/initrd.xz \
|
2025-02-25 11:40:34 +01:00
|
|
|
--os-release rootfs/etc/os-release \
|
|
|
|
--stub $systemd/usr/lib/systemd/boot/efi/linuxx64.efi.stub \
|
|
|
|
--cmdline "$kernelCmdLine" \
|
|
|
|
-o boot/patos.efi
|
2025-02-24 16:13:43 +01:00
|
|
|
|
|
|
|
cp ${systemd}/usr/lib/systemd/boot/efi/systemd-bootx64.efi boot/
|
|
|
|
|
2025-02-24 23:51:46 +01:00
|
|
|
echo "timeout 1" > boot/loader.conf
|
2025-02-25 11:40:34 +01:00
|
|
|
echo -e "title PatOS Platform\nefi /EFI/Linux/patos.efi" > boot/patos.conf
|
2025-02-24 23:51:46 +01:00
|
|
|
|
2025-02-24 16:13:43 +01:00
|
|
|
cat <<EOF > repart.d/10-esp.conf
|
|
|
|
[Partition]
|
|
|
|
Type=esp
|
|
|
|
Format=vfat
|
|
|
|
SizeMinBytes=96M
|
|
|
|
SizeMaxBytes=96M
|
|
|
|
CopyFiles=/boot/systemd-bootx64.efi:/EFI/BOOT/BOOTX64.EFI
|
2025-02-25 11:40:34 +01:00
|
|
|
CopyFiles=/boot/patos.efi:/EFI/Linux/patos.efi
|
2025-02-24 23:51:46 +01:00
|
|
|
CopyFiles=/boot/loader.conf:/loader/loader.conf
|
|
|
|
CopyFiles=/boot/patos.conf:/loader/entries/patos.conf
|
2025-02-24 16:13:43 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF > repart.d/10-root.conf
|
|
|
|
[Partition]
|
|
|
|
Type=root
|
|
|
|
Format=erofs
|
|
|
|
Minimize=best
|
2025-02-25 11:40:34 +01:00
|
|
|
CopyFiles=/rootfs:/
|
2025-02-24 16:13:43 +01:00
|
|
|
SplitName=root
|
|
|
|
EOF
|
|
|
|
|
|
|
|
$systemd/usr/bin/systemd-repart \
|
|
|
|
--no-pager \
|
|
|
|
--empty=create \
|
2025-02-24 23:51:46 +01:00
|
|
|
--size=auto \
|
2025-02-24 16:13:43 +01:00
|
|
|
--definitions=./repart.d \
|
|
|
|
--root=$out \
|
|
|
|
patos-$version.raw
|
|
|
|
|
|
|
|
rm -rf rootfs
|
|
|
|
rm -rf boot
|
|
|
|
|
|
|
|
popd
|