update: shrink down built module size with localmodconfig (~8G -> ~450MB)
This commit is contained in:
1 parent
4a36d85ef3
commit
4dff0249bb
2 files changed
+43
-48
No files matched your search
@@ -3,8 +3,8 @@
|
||||
# kernel requires: gcc flex bison make openssl-devel elfutils-libelf-devel bc perl-devel double-conversion-devel qt5-qtbase-devel libXi-devel rpm-build
|
||||
|
||||
DISTRO_VERSION="44"
|
||||
LOCAL_VERSION=${KERNEL_VERSION:=6.19.10}-300.fc${DISTRO_VERSION}.ms-r1
|
||||
HEADERS=/usr/src/kernels/$LOCAL_VERSION
|
||||
BUILD_VERSION=${KERNEL_VERSION:=6.19.10}-300.fc${DISTRO_VERSION}.ms-r1
|
||||
HEADERS=/usr/src/kernels/$BUILD_VERSION
|
||||
JOBS=$(nproc)
|
||||
BUILD=$(pwd)
|
||||
CROSS="aarch64-linux-gnu-"
|
||||
@@ -19,19 +19,19 @@ CMDLINE="pcie_aspm=off $CMDLINE_COMMON"
|
||||
|
||||
log() { printf '[%s] %s\n' "$(date '+%H:%M:%S')" "$*"; }
|
||||
die() { printf '[%s] ERROR: %s\n' "$(date '+%H:%M:%S')" "$*"; exit 1; }
|
||||
run() { "$@" 2>&1 > "/tmp/$1.error.log" || die "failed: $(cat /tmp/$1.error.log | tail -n 1)"; }
|
||||
get() { local dl=/tmp/$1; [ -f "$dl" ] || { run wget -q -O $dl "$2/$1"; cat $dl; return; }; log "using cached file $dl" >&2; cat $dl; }
|
||||
sub() { local sh=/tmp/$LOCAL_VERSION.build.sub.sh; echo "$(declare -p); $(declare -f)" > $sh; echo "source $sh 2>/dev/null && $1"; }
|
||||
run() { local l=/tmp/$BUILD_VERSION.build.run.log; "$@" 2>&1 > "$l" || die "failed: $(cat $l | tail -n 1)"; }
|
||||
sub() { local s=/tmp/$BUILD_VERSION.build.sub.sh; echo "$(declare -p); $(declare -f)" > $s; echo "source $s 2>/dev/null && $1"; }
|
||||
get() { local d=/tmp/$1; [ -f "$d" ] || { run wget -q -O $d "$2/$1"; cat $d; return; }; log "using cached file $d" >&2; cat $d; }
|
||||
|
||||
purge() {
|
||||
log "removing modules"
|
||||
rm -rf "/lib/modules/$LOCAL_VERSION" "$HEADERS" || die "failed"
|
||||
rm -rf "/lib/modules/$BUILD_VERSION" "$HEADERS" || die "failed"
|
||||
log "removing boot images and config files"
|
||||
find /boot -name "*-$LOCAL_VERSION*" -delete || die "failed"
|
||||
find /boot -name "*-$BUILD_VERSION*" -delete || die "failed"
|
||||
}
|
||||
|
||||
setup() {
|
||||
log "uninstalling (if exists) legacy kernel ${LOCAL_VERSION} from previous build(s)"
|
||||
log "uninstalling (if exists) legacy kernel ${BUILD_VERSION} from previous build(s)"
|
||||
purge
|
||||
log "copying header files"
|
||||
cp -r "$KERNEL_TREE" "$HEADERS" || die "failed"
|
||||
@@ -39,7 +39,7 @@ setup() {
|
||||
make -C "$HEADERS" ARCH=arm64 -j"$JOBS" modules_install install clean </dev/null >"$LOGS/install.log" 2>&1 || die "failed (see logs/install.log)"
|
||||
|
||||
log "updating bootloader configuration"
|
||||
run grubby --update-kernel=/boot/vmlinuz-$LOCAL_VERSION --args="$CMDLINE"
|
||||
grubby --update-kernel=/boot/vmlinuz-$BUILD_VERSION --args="$CMDLINE"
|
||||
|
||||
local id="$(grubby --info=$(grubby --default-index) | grep 'id=' | awk -F'\"' '{print $2}')"
|
||||
local conf=/boot/loader/entries/$id.powersave.conf
|
||||
@@ -48,7 +48,7 @@ setup() {
|
||||
sed -i "/^title/s/$/ Powersave Mode/" $conf
|
||||
}
|
||||
|
||||
[ -z "$UNINSTALL" ] || { pkexec bash -c "$(sub purge)"; exit 0; }
|
||||
[ -z "$UNINSTALL" ] || { pkexec bash -c "$(sub purge)" && log "done"; exit 0; }
|
||||
[ -z "$CLEAN" ] || rm -rf $KERNEL_TREE $KERNEL_PATCHES $LOGS; mkdir -p "$LOGS"
|
||||
log "building linux kernel ${KERNEL_VERSION} (arm64) for Fedora ${DISTRO_VERSION} with sky1-${TAG:=latest} patches"
|
||||
|
||||
@@ -87,42 +87,44 @@ fi
|
||||
|
||||
if [ ! -d "$KERNEL_TREE" ]; then
|
||||
log "downloading linux kernel source tree"
|
||||
get "linux-${KERNEL_VERSION}.tar.xz" "https://www.kernel.org/pub/linux/kernel/v${KERNEL_VERSION:0:1}.x/" | tar -xf - -C $BUILD --xz
|
||||
get "linux-${KERNEL_VERSION}.tar.xz" "https://www.kernel.org/pub/linux/kernel/v${KERNEL_VERSION:0:1}.x/" \
|
||||
| tar -xf - --xz -C $BUILD
|
||||
fi
|
||||
|
||||
if [ ! -f "$KERNEL_TREE/.config-fedora" ]; then
|
||||
cd $KERNEL_TREE
|
||||
log "downloading fedora kernel core"
|
||||
get "kernel-core-${KERNEL_VERSION}-300.fc${DISTRO_VERSION}.aarch64.rpm" "https://download.fedoraproject.org/pub/fedora/linux/releases/${DISTRO_VERSION}/Everything/aarch64/os/Packages/k/" \
|
||||
| rpm2cpio - \
|
||||
| cpio -i --quiet --to-stdout "./lib/modules/*/config" \
|
||||
> .config
|
||||
[ -z "$LOCAL" ] || { yes "" | make -C "$KERNEL_TREE" localmodconfig >/dev/null 2>&1; sed -i '/is not set/d' .config; }
|
||||
mv .config .config-fedora
|
||||
fi
|
||||
|
||||
if [ ! -f "$KERNEL_TREE/.patches-sky1" ]; then
|
||||
log "applying patches"
|
||||
output="$LOGS/patches.log"; echo "" >$output
|
||||
for p in "$KERNEL_PATCHES/patches-${TAG}"/*.patch; do
|
||||
patch -d "$KERNEL_TREE" -p1 --forward --batch -s <"$p" >>$output || die "could not apply patch: $p (see logs/patches.log)"
|
||||
done
|
||||
find "$KERNEL_TREE" \( -name '*.orig' -o -name '*.rej' \) -delete
|
||||
fi
|
||||
|
||||
if [ ! -f "$KERNEL_TREE/.config-fedora" ]; then
|
||||
log "downloading fedora kernel core"
|
||||
get "kernel-core-${KERNEL_VERSION}-300.fc${DISTRO_VERSION}.aarch64.rpm" "https://download.fedoraproject.org/pub/fedora/linux/releases/${DISTRO_VERSION}/Everything/aarch64/os/Packages/k/" \
|
||||
| rpm2cpio - \
|
||||
| cpio -i --quiet --to-stdout "./lib/modules/*/config" \
|
||||
> $KERNEL_TREE/.config-fedora
|
||||
touch "$KERNEL_TREE/.patches-sky1"
|
||||
fi
|
||||
|
||||
if [ ! -f "$KERNEL_TREE/.config.ms-r1" ] || [ -n "$REBUILD" ]; then
|
||||
log "configuring kernel"
|
||||
cd $KERNEL_TREE
|
||||
make mrproper >/dev/null
|
||||
cp $KERNEL_PATCHES/config/config.sky1-${TAG} .config-sky1
|
||||
./scripts/kconfig/merge_config.sh -m -O . .config-sky1 .config-fedora >/dev/null
|
||||
./scripts/kconfig/merge_config.sh -m -O . .config "$BUILD/config/ms-r1.fragment" >/dev/null
|
||||
make ARCH=arm64 CROSS_COMPILE=$CROSS olddefconfig >/dev/null
|
||||
cp $KERNEL_PATCHES/config/config.sky1-${TAG} ".config-sky1"
|
||||
run ./scripts/kconfig/merge_config.sh -m -O . .config-sky1 .config-fedora
|
||||
run ./scripts/kconfig/merge_config.sh -m -O . .config "$BUILD/config/ms-r1.fragment"
|
||||
make olddefconfig >/dev/null 2>&1
|
||||
cp .config .config.ms-r1
|
||||
fi
|
||||
|
||||
log "compiling kernel"
|
||||
make -C "$KERNEL_TREE" ARCH=arm64 CROSS_COMPILE=$CROSS -j"$JOBS" </dev/null >"$LOGS/build.log" 2>&1 || die "failed (see logs/build.log)"
|
||||
|
||||
if [ -z "$INSTALL" ]; then
|
||||
log "done"
|
||||
log "note: run this script with INSTALL=1 to trigger kernel install (requires root privileges)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
pkexec bash -c "$(sub setup)"
|
||||
[ -z "$INSTALL" ] || { pkexec bash -c "$(sub setup)" && log "done"; exit 0; }
|
||||
log "done"
|
||||
log "note: run this script with INSTALL=1 to trigger kernel install (requires root privileges)"
|
||||
Reference in new issue
Block a user