KernelSU Patch Failed: How to Fix “Hunk #1 FAILED” and .rej Files

TL;DR: A KernelSU patch hunk failed because the patch could not find the expected surrounding code. Use the exact kernel source revision, begin with a clean tree and run a dry check. Inspect every .rej file. If versions differ, port the rejected change by meaning, then rebuild and test.

KernelSU Patch Failed: How to Fix “Hunk #1 FAILED” and .rej Files supporting illustration 1
Higgsfield-generated editorial illustration.

By the PrivacyPortal team

Last updated November 2026

When a KernelSU patch reports Hunk #1 FAILED, no root method has been installed by that hunk. The target file differs from the version expected by the patch. A .rej file records the rejected lines. Deleting it does not apply them. The safest fix is to find the matching kernel commit. If that is impossible, review and port the change manually.

Back up your phone and important account data before building or flashing anything. Keep the complete stock firmware and matching boot images. Unlocking the bootloader normally wipes all user data. A bad kernel can prevent booting, weaken security or require a full restore.

This guide was technically reviewed by PrivacyPortal on 11 November 2026; each patch must still be matched to its exact source commit.

What “KernelSU patch hunk failed” means

A patch is a set of edits rather than a complete replacement file. Each edit is called a hunk. It contains removed lines, added lines and unchanged context. The patch tool uses that context to find the intended location.

Line numbers are only hints. A patch can still apply after code moves by a few lines. It fails when enough surrounding text has changed. The tool then writes the unapplied hunk to a reject file such as fs/exec.c.rej.

A message like Hunk #1 FAILED at 1234 does not explain the cause. It only identifies the first rejected edit and its expected area. Other hunks may already have applied, leaving a dangerous partial integration.

GNU patch writes hunks it cannot apply to a reject file, normally using the target filename followed by .rej.

The GNU documentation on imperfect patches explains offsets, fuzz and reject files in detail.

Caption: A rejected hunk shows expected context beside the kernel code that has changed.

Why KernelSU patches reject kernel source

The kernel revision does not match

Revision mismatch is the most common cause. A patch made for one Android common kernel tag may not fit a vendor branch. Even two kernels with the same Linux version can contain very different vendor changes.

For example, a patch prepared against an Android common kernel commit may expect a function in fs/exec.c. A phone maker may have moved it, renamed it or added security hooks. The version label alone cannot prove compatibility.

Record both sides before changing code:

  • The full commit SHA of the kernel source checkout.
  • The KernelSU release, branch or commit used to create the patch.
  • The device build number and installed security patch level.
  • The patch order if several patches form one integration.

The tree is dirty or partly patched

A KernelSU patch hunk failed message can also mean the change is already present. It may have been applied by an earlier script, cherry-pick or failed attempt. Applying it again reverses the expected context.

Run git status --short before every attempt. An empty result is the safest starting point. Use git apply --reverse --check kernelsu.patch to test whether Git considers the patch already applied.

Do not keep retrying against a partly changed tree. Create a fresh clone or a separate worktree at the recorded source SHA. This preserves useful work and makes each result repeatable.

Patch format, path or line endings differ

A plain unified diff and a Git-formatted patch are related but not identical. The wrong strip level can also select the wrong path. A patch containing a/fs/exec.c and b/fs/exec.c commonly needs -p1 with GNU patch.

Windows CRLF line endings can disrupt older or plain patch workflows. Whitespace cleanup can also change context. Do not start by enabling broad whitespace ignores. They may hide a real source mismatch.

Choose the right patch tool

Patch type Preflight command Best use Main caution
Git diff git apply --check --verbose kernelsu.patch Checking source changes without creating a commit A successful check does not build the kernel
Email patch git am --show-current-patch=diff Applying commits with author and message data A failed git am has its own abort or continue state
Plain unified diff patch --dry-run --fuzz=0 -p1 < kernelsu.patch Older source drops without Git metadata A wrong -p level changes the target path
Git three-way merge git apply --3way --check kernelsu.patch Recovering when matching Git blobs are available May produce conflicts that need review

The commands use options available in Git 2.51.0 and GNU patch 2.7.6. Later output may differ, but the preflight principle remains the same.

Git 2.51.0 documents git apply --check as a check for whether a patch is applicable, without applying it.

How to fix a KernelSU patch hunk failed error

Follow this sequence on your own device source, and stop before flashing if any verification fails.

  1. Back up first. Save personal data, recovery codes and the exact stock firmware. Keep clean copies of boot, init_boot and vendor_boot where your device uses them.
  2. Identify the running build. Record the phone model, build number, kernel version and security patch level. Similar model names may use different kernels.
  3. Pin both revisions. Obtain the matching vendor kernel source and record its full commit SHA. Record the exact KernelSU patch or integration commit too.
  4. Create a clean checkout. Use a fresh clone or git worktree add ../kernel-clean <sha>. Confirm that git status --short returns nothing.
  5. Inspect the patch header. Check its file paths, base commit clues and prerequisites. Apply dependent patches in their stated order.
  6. Run a preflight. Use git apply --check --verbose for a Git diff. Use patch --dry-run --fuzz=0 -p1 for a plain diff.
  7. Apply only after a clean check. Run the matching command without --check or --dry-run. Stop if any hunk rejects.
  8. Review every change. Use git diff --check and inspect the full diff. Search for conflict markers and .rej files.
  9. Build with the branch’s documented toolchain. Use the vendor or Android kernel build instructions. Do not substitute a random compiler or configuration.
  10. Verify before flashing. Confirm the output type, device target and rollback plan. Keep the stock image ready for fastboot or the vendor recovery tool.

Prerequisites and files

You need Git, a suitable shell, the exact device kernel source and its stated build toolchain. You also need the KernelSU integration patch or commit intended for that source family. The KernelSU Manager app alone cannot add KernelSU to an unsupported kernel.

Use the official KernelSU non-GKI integration guide to identify the supported integration route. If this page includes a “Modules, apps & files to try” section, choose only the file matching your recorded branch and device.

Do not treat a Magisk-patched boot image as a KernelSU kernel. Magisk and KernelSU use different integration models. APatch, KernelSU Next and SukiSU Ultra also have separate requirements. Never mix their patches or managers without explicit project guidance.

Verification before flashing

A successful patch command proves only that text matched. It does not prove that the kernel is safe or bootable.

  • git diff --check reports no whitespace errors.
  • No .rej, .orig or conflict-marker files remain.
  • The kernel configuration contains the options required by the chosen integration.
  • The build completes with the documented compiler and branch configuration.
  • The output image matches the device’s expected partition and format.
  • You can restore the exact stock image without relying on the modified phone.

Follow the Android kernel build documentation where it applies to your branch. Vendor trees may use older scripts or their own build wrapper.

Caption: A clean preflight, reviewed diff and successful build form three separate safety gates.

How to read and repair a .rej file

A .rej file contains the hunk that did not apply. Its lines beginning with a minus sign were expected in the old file. Lines beginning with a plus sign are the requested replacement. Unmarked lines provide context.

Use Get-ChildItem -Recurse -Filter *.rej in PowerShell to find rejects. On Linux or macOS, use find . -name '*.rej'. Open each reject beside its target file.

Then review it by meaning:

  • Find the current function, structure or hook instead of trusting the old line number.
  • Check whether the new source already performs the requested operation.
  • Trace renamed arguments, changed return paths and locking rules.
  • Place the change where the same security and lifecycle conditions hold.
  • Compile after each small manual edit.

Do not paste rejected lines blindly. Kernel interfaces can change while code still looks similar. A misplaced hook may compile yet create a security flaw, crash or boot loop.

Deleting .rej merely hides the evidence. It does not repair the source.

When a three-way apply can help

git apply --3way can reconstruct a change when the patch includes usable Git blob identities and those objects exist locally. It may resolve harmless context drift. It can also leave conflict markers for manual review.

Use it only after confirming the intended base revision. Run git apply --3way --check kernelsu.patch first. If the check succeeds, apply it in a clean branch and inspect the result.

The --recount option only repairs incorrect hunk line counts. It does not make a patch semantically compatible. Likewise, --ignore-space-change can bypass formatting differences but should not be a first response to a kernel patch failure.

A KernelSU patch hunk failed result after three-way checking usually needs the correct base or a deliberate manual port.

Build and flash without turning a patch fix into a brick

Kernel builds are device-specific. Some Android common kernel branches use Kleaf and Bazel. Older trees may use build/build.sh. Vendors can add their own configuration, modules, device trees and image assembly.

Do not flash a generic output simply because it compiled. Confirm whether the device expects boot, init_boot, vendor_boot or another packaged image. Preserve the original partition image from the same installed build.

A cautious first test uses temporary booting only where the device and image format explicitly support it. Never assume fastboot boot is safe or supported. Some devices require a direct flash and have anti-rollback rules.

After boot, verify the kernel version, basic radio functions, Wi-Fi, camera and storage. Then open the matching KernelSU Manager and confirm that it recognises the kernel. Test a harmless root command before adding modules.

Caption: Keep the matching stock boot files beside the tested build before touching any partition.

Security, OTA and app compatibility risks

Bootloader unlocking normally wipes the phone. It may change warranty or support options, depending on the seller and local law. An unlocked bootloader also weakens protection against someone with physical access.

Kernel root expands the impact of malicious root apps and unsafe modules. Grant access only to software you trust. Keep source, patches and build logs so you can audit or reproduce the result.

Over-the-air updates may replace the modified kernel or fail their verification checks. Restore the correct stock image before an update if the device instructions require it. Rebuild against the new release rather than reusing an old image.

Banking, streaming and workplace apps may check boot state, Play Integrity or other signals. Results vary by app, device and update. KernelSU, SUSFS and related tools cannot guarantee that a specific app will work. Root hiding can also reduce transparency and create new security trade-offs.

If privacy is the main goal, root may not be needed. Our guide to de-Googling an Android phone covers less invasive options.

Common repair mistakes

  • Using only the Linux version: vendor commits matter as much as the headline kernel version.
  • Applying every good hunk: a partial patch may compile while missing a required security check.
  • Increasing fuzz immediately: loose context matching can place an edit in the wrong function.
  • Deleting reject files: this removes the warning, not the missing change.
  • Mixing root families: Magisk, APatch, KernelSU and its forks are not interchangeable.
  • Reusing an old patched image after an OTA: kernel and vendor components may no longer match.
  • Testing with valuable data: first boots should use a complete backup and proven recovery route.

In practice, the fastest reliable fix is often a fresh checkout at the proper SHA. Manual porting should be reserved for readers who can review the changed kernel path.

Frequently asked questions

Can I ignore Hunk #1 FAILED if the other hunks applied?

No. KernelSU changes can depend on one another. A partly applied patch may fail to build or may produce unsafe behaviour. Return to a clean tree, identify the mismatch and apply the full change coherently.

Can I delete the .rej file and continue?

No. The reject file is only a record of unapplied content. Deleting it does not add the missing code. Inspect the reject, repair the source and verify the complete diff.

Why did the patch work for someone with the same phone?

The phones may use different regional builds, security updates or kernel commits. One person may also have used a custom kernel with KernelSU already integrated. Compare full build identifiers and commit SHAs.

Does “KernelSU patch hunk failed” mean I used the wrong KernelSU version?

Possibly, but the kernel base is often the mismatch. Check the patch’s intended source commit, branch and dependencies. A newer KernelSU release is not automatically compatible with an older vendor tree.

Will using fuzz or ignoring whitespace fix the error?

It may make a textual patch apply, but it cannot prove semantic correctness. Use strict checks first. Review any result line by line, then compile and test it as a manual port.

Will the repaired kernel pass Play Integrity or banking checks?

There is no guarantee. Apps can assess boot state, kernel changes, installed software and server-side signals. Detection changes over time. Never rely on a root setup for access to a specific bank or service.

Can I keep normal OTA updates after installing KernelSU?

It depends on the device and installation route. An update may replace the modified image or reject it. Keep stock files, restore when required and rebuild KernelSU against each new kernel release.

The reliable decision rule

If a KernelSU patch hunk failed, first find the exact intended source revision. Use a clean tree and strict preflight. If the correct base applies cleanly, build and verify it. If no matching base exists, treat the task as a kernel code port rather than a patching trick.

Stop if you cannot explain the rejected change or recover the phone independently. A working stock device is better than an uncertain rooted build. PrivacyPortal’s practical rule is simple: preserve your data, keep a tested rollback path and never mistake a clean patch output for a safe kernel.

Want the private phone without the hassle?
PrivacyPortal sells ready-to-use, de-Googled GrapheneOS Pixels — hardened, kept updated, and shipped with our encrypted Graphite messenger. Browse privacy phones →
Share
Back to blog

Leave a comment