The required steps — build as a normal user, escalate with su. Every command has a copy button. Alpine Edge • aarch64 • custom virt-based flavor “virthardened” • kernel 7.3.7 + hardened1 patch • username fro, pkgrel 1.
Alpine's linux-virt kernel (a slim kernel for virtual machines) has no pre-built hardened version, so you rebuild it with the anthraxx linux-hardened patch applied, as your own flavor.
main/linux-lts? Alpine builds the linux-virt kernel from the linux-lts recipe — there is no separate linux-virt folder. One APKBUILD there produces both kernels, and both config files live beside it.su.fro and pkgrel=1 — adjust if yours differ.su -c, which asks for the root password). Commands tagged USER run as your normal user. Never run the abuild commands as root — they only work as your normal user.i to type (insert mode), Esc to leave it. Search: /text then Enter (n = next match). Save & quit: Esc then :wq then Enter. Quit without saving: :q!. Delete one character: x.Install the build tools and add yourself to the abuild group (as root):
su -c 'apk add alpine-sdk'
su -c "addgroup $(whoami) abuild"Log out and back in so the group takes effect, then create your signing key as your normal user:
abuild-keygen -n -aInstall the public half of that key into /etc/apk/keys (as root). Without this, the last stage of the build fails with UNTRUSTED signature / Failed to create index:
su -c 'install -m644 /home/fro/.abuild/*.rsa.pub /etc/apk/keys/'addgroup (or reboot the VM), or the build in Step 7 fails with permission errors.Clone aports, switch to the Edge branch, make a working branch, and enter the kernel directory:
cd ~
git clone --depth=1 https://gitlab.alpinelinux.org/alpine/aports.git
cd aports
git checkout master
git checkout -b hardened-virt
cd main/linux-ltsThe patch only applies to the exact version in the recipe. Expect pkgver=7.3.7:
grep -E '^pkgver|^pkgrel' APKBUILDpkgver is not 7.3.7: download the hardened patch whose version matches what it shows, or check out an aports commit where it is 7.3.7. The patch version and pkgver must be identical.Fetch the patch and its signature into the current directory:
BASE=https://github.com/anthraxx/linux-hardened/releases/download/v7.3.7-hardened1
wget -O 0006-linux-hardened.patch "$BASE/linux-hardened-v7.3.7-hardened1.patch"
wget -O 0007-linux-hardened.patch.sig "$BASE/linux-hardened-v7.3.7-hardened1.patch.sig"Confirm they arrived:
ls -l 0006-linux-hardened.patch 0007-linux-hardened.patch.sigThe patch renames the kernel to end in -hardened1, which breaks Alpine's install hooks. Open the patch:
vi 0006-linux-hardened.patchType /hardened1 then Enter to jump to the line. It edits the kernel's top-level Makefile and looks like this:
reference — what you'll see
--- a/Makefile +++ b/Makefile VERSION = 7 PATCHLEVEL = 3 SUBLEVEL = 7 -EXTRAVERSION = +EXTRAVERSION = -hardened1
Put the cursor on the +EXTRAVERSION = -hardened1 line, press A (capital) to edit at the end of the line, Backspace to delete -hardened1 so it reads exactly +EXTRAVERSION = (keep the leading +). Then Esc, :wq, Enter.
0007-linux-hardened.patch.sig — it is a signature and must stay exactly as downloaded.vi APKBUILD6a. Find pkgrel (type /pkgrel then Enter) and set it to pkgrel=1 (one more than the stock value of 0).
6b. Find the source= block (type /source= then Enter). Add your two filenames on their own lines, before the .config lines (arrows mark the added lines — type only the filenames):
reference — edited source= block
source="https://.../linux-$_kernver.tar.xz 0001-...patch 0006-linux-hardened.patch ← add 0007-linux-hardened.patch.sig ← add lts.aarch64.config virt.aarch64.config "
Indent to match the other entries, then save and quit (Esc, :wq, Enter).
First, a one-time setting so the compile uses all your cores (not one). Set the number to your VM's core count:
echo 'export JOBS=4' >> ~/.abuild/abuild.conf
echo 'export MAKEFLAGS=-j4' >> ~/.abuild/abuild.confCreate your own kernel flavor based on the virt config. You cannot reuse the built-in virt flavor directly (the recipe would add its config twice and abort with “duplicate found in $source”). Copy it to a new name:
cp virt.aarch64.config virthardened.aarch64.configvirthardened.aarch64.config to the source= list. The FLAVOR= prefix below adds it automatically; adding it yourself recreates the duplicate error.Now record checksums and build only your flavor. FLAVOR=virthardened makes it the one and only flavor built (lts and virt are both skipped), and it must be set on both commands:
FLAVOR=virthardened abuild checksum
FLAVOR=virthardened abuild -rtop in another shell — CPU should be near 400% on 4 cores, not 100%.Your package lands here:
ls ~/packages/main/aarch64/linux-virthardened-7.3.7-r1.apk-accel hvf and -cpu host (or enable the hypervisor option in UTM). Without hardware acceleration the aarch64 guest is software-emulated and many times slower. On an Intel Mac an aarch64 guest is always emulated, so a native build is inherently very slow.Install the package you built directly. --allow-untrusted is needed because it is signed by your own key:
su -c 'apk add --allow-untrusted /home/fro/packages/main/aarch64/linux-virthardened-7.3.7-r1.apk'apk add --allow-untrusted:su -c "find / -xdev -name 'linux-virthardened-*.apk' 2>/dev/null"su -c 'apk add linux-lts'Installing the kernel package already rebuilds the initramfs. Regenerate the GRUB menu so the new kernel appears:
su -c 'grub-mkconfig -o /boot/grub/grub.cfg'Check the kernel files are in place — you should see vmlinuz-virthardened and initramfs-virthardened:
ls /bootinitramfs-virthardened is missing: get the exact module name with ls /lib/modules (such as 7.3.7-1-virthardened), build it by hand, then regenerate GRUB again:su -c 'mkinitfs 7.3.7-1-virthardened'su -c 'reboot'When it returns, confirm you are running your kernel (as your normal user):
uname -aIt should show 7.3.7-1-virthardened with no -hardened1 suffix (because you removed EXTRAVERSION in Step 5). If the system does not boot, pick the stock linux-lts fallback entry at the GRUB menu, boot it, and rebuild after fixing the problem.