How to Rebuild and Install RISC-V Kernel Cross Compile

Abstract: Rebuild and install a cross-compiled RISC-V Linux kernel on a host machine.

Created: 2026-10-02 by
To rebuild and install a RISC-V kernel cross-compiled on a Linux host, you must first configure the correct architecture, specify the cross-compilation toolchain prefix, and select an appropriate defconfig for your target hardware. After generating the configuration menu, you compile the kernel image using make with the specified jobs flag, then use make modules_install to deploy the kernel and modules to the target root filesystem or emulated environment.

Preparing the Cross-Compilation Environment

The foundation of any successful embedded Linux build is a properly configured toolchain. For RISC-V, you generally need a GCC compiler that targets the specific ISA extension (such as RV64GC) and supports the target’s ABI. Most modern distributions provide these packages in their repositories. On Debian-based systems like Ubuntu, you can install the necessary tools by running:
sudo apt update
sudo apt install gcc-riscv64-linux-gnu make bison flex libssl-dev bc
Ensure that the installed compiler matches the bit-width of your target system. If you are targeting a 32-bit RISC-V core, you would use gcc-riscv32-linux-gnu instead. Verify the installation by checking the version string of the compiler binary. The output should clearly indicate it is targeting the RISC-V architecture. This step prevents subtle linking errors later during the compilation phase.

Acquiring and Extracting the Kernel Source

You should obtain the Linux kernel source code from the official repository. Using Git allows you to track updates and switch between stable branches easily. Clone the mainline kernel tree into a dedicated directory:
git clone https://github.com/torvalds/linux.git
cd linux
Navigate to the root of the extracted source tree. It is crucial to clean any previous build artifacts if you are switching configurations frequently. Run make mrproper to remove all generated files, including configuration backups and object files. This ensures a pristine starting point for your new build. Without this cleanup, residual files from previous builds might interfere with dependency tracking, leading to incorrect binaries.

Configuring the Kernel Build

Configuration is the most critical step where you define what features are included in the kernel. For cross-compilation, you must explicitly set the architecture variable. Instead of relying on auto-detection, which assumes the host architecture, you force the build system to target RISC-V by exporting the ARCH variable.
export ARCH=riscv
export CROSS_COMPILE=riscv64-linux-gnu-
Note that the CROSS_COMPILE variable must include the trailing hyphen. This prefix is appended to standard commands like gcc, resulting in riscv64-linux-gnu-gcc. Once exported, you can launch the configuration interface. Running make defconfig generates a default configuration suitable for generic RISC-V hardware. However, for specific boards, you might prefer a board-specific defconfig located in arch/riscv/configs/. You can list available configs by running make list-defconfigs. If you need to tweak settings, such as enabling specific drivers or adjusting memory limits, use make menuconfig. This text-based interface allows you to navigate through subsystems. Ensure that the "Kernel Features" section has the correct page size and virtual memory layout for your target. Save the configuration when finished. The resulting .config file will be used in subsequent build steps.

Compiling the Kernel Image

With the configuration finalized, you can initiate the compilation process. Use the make command with the -j flag to parallelize the build across multiple CPU cores, significantly reducing build time. Replace N with the number of cores available on your machine plus one.
make -j$(nproc)
This command compiles the kernel modules and links the final kernel image. For RISC-V, the primary bootable image is typically Image.gz or Image located in arch/riscv/boot/. The exact filename depends on whether you enabled compression options in the configuration. Monitor the build log for any warnings or errors. Common issues often stem from missing dependencies or incompatible toolchain versions. If the build succeeds, you will see a summary indicating the location of the generated image.

Installing Modules and Deploying

After compiling the kernel, you usually need to install the loadable kernel modules. These modules contain drivers for hardware components that are not built directly into the kernel image. Run the following command to install them into a designated directory:
make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=/path/to/target/rootfs modules_install
The INSTALL_MOD_PATH variable directs the installer to place modules into your target root filesystem rather than the host system. This is essential for embedded deployments where the target device has its own separate filesystem structure. The INSTALL_MOD_STRIP=1 option removes debug symbols from the modules, reducing their size and storage footprint. Finally, copy the compiled kernel image to your deployment medium. Whether you are flashing an SD card, uploading to a QEMU emulator, or transferring via TFTP, ensure the image is placed in the expected boot partition. Update your bootloader configuration (such as GRUB or U-Boot) to point to the new kernel image. Reboot the target system to verify that the new kernel loads correctly and initializes the hardware as expected.

Frequently Asked Questions

What happens if I forget the trailing hyphen in CROSS_COMPILE?

The build system will fail to find the compiler because it will look for a binary named exactly "riscv64-linux-gnu" without the expected suffix. This results in immediate errors stating that the cross-compiler was not found. Always double-check the variable definition before starting the build.

How do I know which defconfig to use for my specific board?

You should consult the documentation provided by your board manufacturer or look for a matching config in the arch/riscv/configs/ directory. Generic defconfigs may lack specific driver support required for your hardware peripherals. Using the wrong config can lead to a kernel that boots but cannot access essential devices.

Can I use the same toolchain for both 32-bit and 64-bit RISC-V?

No, you must use distinct toolchains tailored to the specific instruction set architecture and ABI of your target. A 64-bit toolchain cannot generate valid binaries for a 32-bit core due to differences in register sizes and calling conventions. Mixing them up will result in runtime crashes or illegal instruction exceptions.

Why does the build fail with "cannot find linker script"?

This error typically occurs when the configuration is incomplete or corrupted, causing the build system to miss critical assembly files. Running make mrproper followed by regenerating the configuration usually resolves the issue. Ensure that your toolchain is fully installed and accessible in your PATH.

Is it safe to strip debug symbols from the kernel image?

Stripping debug symbols reduces the kernel size and speeds up loading times, which is beneficial for embedded systems with limited storage. However, it makes debugging difficult if the system crashes or behaves unexpectedly. You should only enable stripping in production environments where diagnostic capabilities are handled externally.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More