kernel only option; persistent ccache; single kernel deb; CI support; robust resize2fs; cross compile fixes; custom kernel headers; arch postinstall; amd64 deb

This commit is contained in:
Dan Kluser
2026-05-09 17:31:47 +02:00
parent ad45441d40
commit 861ed9a889
13 changed files with 158 additions and 37 deletions

View File

@@ -13,6 +13,6 @@ jobs:
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.DISPATCH_TOKEN }}
repository: resulknad/ps5-vps-setup
repository: ps5-linux/ps5-linux-updates
event-type: image-builder-updated
client-payload: '{"sha": "${{ github.sha }}"}'

View File

@@ -42,7 +42,7 @@ done
LINUX_REPO="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
LINUX_DEFAULT_DIR="$SCRIPT_DIR/work/linux"
PATCHES_REPO="https://github.com/resulknad/ps5-linux-patches.git"
PATCHES_REPO="https://github.com/ps5-linux/ps5-linux-patches.git"
PATCHES_DIR="$SCRIPT_DIR/work/ps5-linux-patches"
if [ -z "$KERNEL_SRC" ]; then
@@ -235,7 +235,6 @@ else
[ -n "$PATCHES_TOKEN" ] && REPO_URL="${PATCHES_REPO/https:\/\//https:\/\/${PATCHES_TOKEN}@}"
mkdir -p "$PATCHES_DIR"
run_stage "Fetch ps5-linux-patches ($PATCHES_REF)" bash -c '
cd "'"$PATCHES_DIR"'"

View File

@@ -8,6 +8,7 @@ DISK=$(lsblk -ndo PKNAME "$ROOT_DEV")
PART_NUM=$(cat /sys/class/block/$(basename "$ROOT_DEV")/partition)
growpart "/dev/$DISK" "$PART_NUM" || true
partprobe "/dev/$DISK"
resize2fs "$ROOT_DEV" || true
rc-update del grow-rootfs default

View File

@@ -8,6 +8,7 @@ DISK="/dev/$(lsblk -ndo PKNAME "$ROOT_DEV")"
PART_NUM=$(cat /sys/class/block/$(basename "$ROOT_DEV")/partition)
parted -s "$DISK" resizepart "$PART_NUM" 100%
partprobe "$DISK"
resize2fs "$ROOT_DEV"
systemctl disable grow-rootfs.service

View File

@@ -175,7 +175,7 @@ actions:
# Install custom kernel packages
if ls /opt/pkgs/*.pkg.tar.zst 1>/dev/null 2>&1; then
pacman -U --noconfirm /opt/pkgs/*.pkg.tar.zst
pacman -U --noconfirm --ask 4 /opt/pkgs/*.pkg.tar.zst
rm -rf /opt/pkgs
KVER=$(ls -1t /lib/modules | head -1)
# mkinitcpio may warn about missing optional modules; don't fail on those

View File

@@ -7,8 +7,8 @@ ROOT_DEV=$(findmnt -no SOURCE /)
DISK="/dev/$(lsblk -ndo PKNAME "$ROOT_DEV")"
PART_NUM=$(cat /sys/class/block/$(basename "$ROOT_DEV")/partition)
growpart "$DISK" "$PART_NUM"
resize2fs "$ROOT_DEV"
growpart "$DISK" "$PART_NUM" || true
partprobe "$DISK"
resize2fs "$ROOT_DEV" || true
systemctl disable grow-rootfs.service

View File

@@ -1,13 +1,19 @@
#!/bin/bash
# Grows the root partition and filesystem to fill the disk.
# Runs once on first boot, then disables itself.
set -e
# If resize fails, the service stays enabled and retries next boot.
ROOT_DEV=$(findmnt -no SOURCE /)
ROOT_DEV=$(findmnt -no SOURCE /) || { echo "Cannot find root device"; exit 1; }
DISK=$(lsblk -ndo PKNAME "$ROOT_DEV")
PART_NUM=$(cat /sys/class/block/$(basename "$ROOT_DEV")/partition)
PART_NUM=$(cat /sys/class/block/$(basename "$ROOT_DEV")/partition 2>/dev/null)
if [ -z "$DISK" ] || [ -z "$PART_NUM" ]; then
echo "Cannot determine disk layout (DISK=$DISK PART_NUM=$PART_NUM)"
exit 1
fi
growpart "/dev/$DISK" "$PART_NUM" || true
resize2fs "$ROOT_DEV" || true
partprobe "/dev/$DISK"
resize2fs "$ROOT_DEV"
systemctl disable grow-rootfs.service

View File

@@ -1,13 +1,10 @@
[Unit]
Description=Grow root filesystem to fill disk
DefaultDependencies=no
Before=local-fs.target
After=local-fs-pre.target
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/grow-rootfs
RemainAfterExit=yes
[Install]
WantedBy=local-fs.target
WantedBy=multi-user.target

View File

@@ -14,6 +14,7 @@ WORKDIR /out/staging
# Output packages go to /out
COPY docker/kernel-builder-arch/build.sh /build.sh
COPY docker/kernel-builder-arch/install.sh /install.sh
RUN chmod +x /build.sh
CMD ["/build.sh"]

View File

@@ -11,7 +11,7 @@ fi
# Determine version from staged modules directory
KVER=$(ls /out/staging/lib/modules/)
PKGNAME="linux-custom"
PKGNAME="linux-ps5"
VERSION=${KVER%%-*}
echo "==> Packaging kernel $KVER as pacman package"
@@ -24,10 +24,22 @@ cp /out/staging/boot/bzImage "$STAGING/boot/vmlinuz-$KVER"
cp /out/staging/System.map "$STAGING/boot/System.map-$KVER"
cp /out/staging/.config "$STAGING/boot/config-$KVER"
# Copy pre-installed modules (Arch uses /lib -> /usr/lib)
# Copy pre-installed modules (Arch uses /usr/lib/modules)
mkdir -p "$STAGING/usr/lib/modules"
cp -a "/out/staging/lib/modules/$KVER" "$STAGING/usr/lib/modules/"
# Kernel headers (for out-of-tree module builds)
if [ -d /out/staging/headers ]; then
# UAPI headers (/usr/include/linux/, /usr/include/asm/, etc.)
cp -a /out/staging/headers/usr "$STAGING/usr"
# Build headers (/usr/lib/modules/$KVER/build/)
mkdir -p "$STAGING/usr/lib/modules/$KVER"
cp -a /out/staging/headers/lib/modules/$KVER/build "$STAGING/usr/lib/modules/$KVER/build"
fi
# Create .INSTALL from template, baking in KVER
sed "s/__KVER__/$KVER/g" /install.sh > "$STAGING/.INSTALL"
# Create .PKGINFO
BUILDDATE=$(date -u +%s)
INSTALLED_SIZE=$(du -sb "$STAGING" | awk '{print $1}')
@@ -35,24 +47,33 @@ cat > "$STAGING/.PKGINFO" << EOF
pkgname = $PKGNAME
pkgbase = $PKGNAME
pkgver = ${VERSION}-1
pkgdesc = Custom Linux kernel $KVER for PS5
pkgdesc = PS5 Linux kernel $KVER (image + modules + headers)
url = https://kernel.org
builddate = $BUILDDATE
packager = bootstrap_docker
packager = ps5-linux
size = $INSTALLED_SIZE
arch = x86_64
license = GPL-2.0-only
provides = linux=$VERSION
provides = linux-custom=$VERSION
provides = linux-headers=$VERSION
provides = linux-api-headers=$VERSION
conflict = linux
conflict = linux-headers
conflict = linux-api-headers
conflict = linux-custom
replaces = linux
replaces = linux-headers
replaces = linux-api-headers
replaces = linux-custom
EOF
# Create .MTREE (required by newer pacman)
cd "$STAGING"
LANG=C bsdtar -czf .MTREE --format=mtree \
--options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
.PKGINFO *
.PKGINFO .INSTALL *
# Build the package
LANG=C bsdtar -cf - .PKGINFO .MTREE * | zstd -c -T0 > "/out/${PKGNAME}-${VERSION}-1-x86_64.pkg.tar.zst"
LANG=C bsdtar -cf - .PKGINFO .INSTALL .MTREE * | zstd -c -T0 > "/out/${PKGNAME}-${VERSION}-1-x86_64.pkg.tar.zst"
echo "==> Done: /out/${PKGNAME}-${VERSION}-1-x86_64.pkg.tar.zst"

View File

@@ -0,0 +1,35 @@
#!/bin/bash
# Pacman .INSTALL script for linux-ps5.
# KVER is replaced at package build time.
post_install() {
KVER="__KVER__"
echo ">> linux-ps5 post_install: kernel $KVER"
# Rebuild initramfs
if command -v mkinitcpio >/dev/null 2>&1; then
echo ">> Rebuilding initramfs with mkinitcpio for $KVER"
mkinitcpio -k "$KVER" -g "/boot/initrd.img-$KVER"
fi
# Copy kernel + initrd to EFI partition
if [ -d /boot/efi ]; then
OLD_BZ=$(ls -l /boot/efi/bzImage 2>/dev/null | awk '{print $5}') || true
OLD_INITRD=$(ls -l /boot/efi/initrd.img 2>/dev/null | awk '{print $5}') || true
echo ">> Copying /boot/vmlinuz-$KVER -> /boot/efi/bzImage"
cp "/boot/vmlinuz-$KVER" /boot/efi/bzImage
NEW_BZ=$(ls -l /boot/efi/bzImage | awk '{print $5}')
echo ">> bzImage: ${OLD_BZ:-<new>} -> $NEW_BZ bytes"
echo ">> Copying /boot/initrd.img-$KVER -> /boot/efi/initrd.img"
cp "/boot/initrd.img-$KVER" /boot/efi/initrd.img
NEW_INITRD=$(ls -l /boot/efi/initrd.img | awk '{print $5}')
echo ">> initrd.img: ${OLD_INITRD:-<new>} -> $NEW_INITRD bytes"
echo ">> Kernel $KVER deployed to /boot/efi"
else
echo ">> /boot/efi not found, skipping EFI deploy"
fi
}
post_upgrade() {
post_install
}

View File

@@ -25,4 +25,13 @@ KVER=$(make -s kernelrelease)
rm -f "/out/staging/lib/modules/$KVER/build" \
"/out/staging/lib/modules/$KVER/source"
# Stage kernel headers for out-of-tree module builds
echo "=== Staging kernel headers ==="
HDR="/out/staging/headers"
make headers_install INSTALL_HDR_PATH="$HDR/usr"
# Use the kernel's own install-extmod-build script (same as deb-pkg uses)
export srctree=/src SRCARCH=x86
CC="${CROSS_COMPILE}gcc" HOSTCC=gcc MAKE=make /src/scripts/package/install-extmod-build "$HDR/lib/modules/$KVER/build"
echo "=== Build artifacts staged in /out/staging ==="

View File

@@ -1,29 +1,80 @@
#!/bin/bash
# Builds a combined linux-ps5 .deb from the kernel source at /src.
# Builds a combined linux-ps5 .deb from staged artifacts in /out/staging.
# Runs inside the kernel-builder container; output goes to /out.
set -e
make -j$(nproc) DPKG_FLAGS=-d bindeb-pkg
STAGING="/out/staging"
KVER=$(ls -1 "$STAGING/lib/modules" | head -1)
VER="${KVER%%-*}"
ARCH=amd64
VER=$(dpkg-deb -f "$(ls /linux-image-[0-9]*.deb | grep -v dbg | head -1)" Version)
ARCH=$(dpkg-deb -f "$(ls /linux-image-[0-9]*.deb | grep -v dbg | head -1)" Architecture)
KVER=$(ls /src/debian/linux-image-[0-9]*/lib/modules/ 2>/dev/null | head -1)
PKG=$(mktemp -d)
mkdir -p "$PKG/DEBIAN"
mkdir -p "$PKG/boot"
mkdir -p "$PKG/lib/modules"
TMPDIR=$(mktemp -d)
mkdir -p "$TMPDIR/DEBIAN"
for deb in $(ls /linux-image-[0-9]*.deb /linux-headers-*.deb /linux-libc-dev_*.deb 2>/dev/null | grep -v -- '-dbg_'); do
dpkg-deb -x "$deb" "$TMPDIR"
done
cp "$STAGING/boot/bzImage" "$PKG/boot/vmlinuz-$KVER"
cp "$STAGING/System.map" "$PKG/boot/System.map-$KVER"
cp "$STAGING/.config" "$PKG/boot/config-$KVER"
cp -a "$STAGING/lib/modules/$KVER" "$PKG/lib/modules/"
cat > "$TMPDIR/DEBIAN/control" << CTRL
# Kernel headers (for out-of-tree module builds)
if [ -d "$STAGING/headers" ]; then
cp -a "$STAGING/headers/usr" "$PKG/usr"
# Point /lib/modules/$KVER/build at the installed headers
HDR_DEST="/usr/lib/modules/$KVER/build"
mkdir -p "$PKG/usr/lib/modules/$KVER"
cp -a "$STAGING/headers/lib/modules/$KVER/build" "$PKG/usr/lib/modules/$KVER/build"
ln -sf "$HDR_DEST" "$PKG/lib/modules/$KVER/build"
fi
cat > "$PKG/DEBIAN/control" << CTRL
Package: linux-ps5
Version: $VER
Architecture: $ARCH
Maintainer: PS5 Linux
Provides: linux-image, linux-image-$KVER, linux-headers-$KVER, linux-libc-dev
Provides: linux-image-$KVER, linux-headers-$KVER, linux-libc-dev
Conflicts: linux-image-$KVER, linux-headers-$KVER, linux-libc-dev
Replaces: linux-image-$KVER, linux-headers-$KVER, linux-libc-dev
Description: PS5 Linux kernel $KVER (image + headers + libc-dev)
Description: PS5 Linux kernel $KVER (image + modules + headers + libc-dev)
CTRL
dpkg-deb --build --root-owner-group "$TMPDIR" "/out/linux-ps5_${VER}_${ARCH}.deb"
cat > "$PKG/DEBIAN/postinst" << 'POSTINST'
#!/bin/bash
set -e
KVER="$(ls -1t /lib/modules | head -1)"
echo ">> linux-ps5 postinst: kernel $KVER"
# Rebuild initramfs
if command -v update-initramfs >/dev/null 2>&1; then
echo ">> Rebuilding initramfs with update-initramfs for $KVER"
update-initramfs -c -k "$KVER"
elif command -v mkinitcpio >/dev/null 2>&1; then
echo ">> Rebuilding initramfs with mkinitcpio for $KVER"
mkinitcpio -k "$KVER" -g "/boot/initrd.img-$KVER"
elif command -v mkinitfs >/dev/null 2>&1; then
echo ">> Rebuilding initramfs with mkinitfs for $KVER"
mkinitfs -o "/boot/initrd.img-$KVER" "$KVER"
fi
# Copy kernel + initrd to EFI partition
if [ -d /boot/efi ]; then
OLD_BZ=$(ls -l /boot/efi/bzImage 2>/dev/null | awk '{print $5}') || true
OLD_INITRD=$(ls -l /boot/efi/initrd.img 2>/dev/null | awk '{print $5}') || true
echo ">> Copying /boot/vmlinuz-$KVER -> /boot/efi/bzImage"
cp "/boot/vmlinuz-$KVER" /boot/efi/bzImage
NEW_BZ=$(ls -l /boot/efi/bzImage | awk '{print $5}')
echo ">> bzImage: ${OLD_BZ:-<new>} -> $NEW_BZ bytes"
echo ">> Copying /boot/initrd.img-$KVER -> /boot/efi/initrd.img"
cp "/boot/initrd.img-$KVER" /boot/efi/initrd.img
NEW_INITRD=$(ls -l /boot/efi/initrd.img | awk '{print $5}')
echo ">> initrd.img: ${OLD_INITRD:-<new>} -> $NEW_INITRD bytes"
echo ">> Kernel $KVER deployed to /boot/efi"
else
echo ">> /boot/efi not found, skipping EFI deploy"
fi
POSTINST
chmod 755 "$PKG/DEBIAN/postinst"
dpkg-deb --build --root-owner-group "$PKG" "/out/linux-ps5_${VER}_${ARCH}.deb"
rm -rf "$PKG"