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 21:02:35 +01:00
|
|
|
# set default target to multi-user
|
|
|
|
ln -sf multi-user.target rootfs/usr/lib/systemd/system/default.target
|
2025-02-25 11:40:34 +01:00
|
|
|
|
2025-02-25 13:39:02 +01:00
|
|
|
# mount patos state
|
2025-02-25 21:02:35 +01:00
|
|
|
ln -sf ../var.mount rootfs/usr/lib/systemd/system/sysinit.target.wants/var.mount
|
2025-02-25 13:39:02 +01:00
|
|
|
|
2025-02-25 11:40:34 +01:00
|
|
|
# enable dbus
|
2025-02-25 21:02:35 +01:00
|
|
|
ln -sf ../dbus.service rootfs/usr/lib/systemd/system/multi-user.target.wants/dbus.service
|
2025-02-25 11:40:34 +01:00
|
|
|
ln -sf ../dbus.socket rootfs/usr/lib/systemd/system/sockets.target.wants/dbus.socket
|
|
|
|
|
2025-02-25 21:02:35 +01:00
|
|
|
# enable systemd-networkd
|
|
|
|
ln -sf ../systemd-networkd.service rootfs/usr/lib/systemd/system/sysinit.target.wants/systemd-networkd.service
|
|
|
|
|
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/
|
|
|
|
|
|
|
|
# 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]
|
2025-02-25 21:02:35 +01:00
|
|
|
WantedBy=multi-user.target
|
2025-02-25 11:40:34 +01:00
|
|
|
EOF
|
2025-02-25 21:02:35 +01:00
|
|
|
ln -sf ../demo.service rootfs/usr/lib/systemd/system/multi-user.target.wants/demo.service
|
2025-02-25 11:40:34 +01:00
|
|
|
|
|
|
|
|
2025-02-24 16:13:43 +01:00
|
|
|
$systemd/usr/bin/ukify build \
|
|
|
|
--linux $kernel/bzImage \
|
|
|
|
--initrd $initrd/initrd.xz \
|
2025-02-25 18:01:44 +01:00
|
|
|
--os-release @rootfs/etc/os-release \
|
2025-02-25 11:40:34 +01:00
|
|
|
--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-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
|
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
|