---
# System prepended metadata

title: Build kernel of Raspberry PI
tags: [OS, Linux, Ubuntu, Embedded System]

---

# Build kernel of Raspberry PI
***

### 1. Install Git and the build dependencies:
```
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
```

### 2. Install 64-bit ToolChain for a 64-bit kernel
```
sudo apt install crossbuild-essential-arm64
```

### 3. Get the source code of Raspberry Pi's kernel
```
git clone --depth=1 https://github.com/raspberrypi/linux
```
Omitting the --depth=1 will download the entire repository, including the full history of all branches, but this takes much longer and occupies much more storage.

### 4. Go into linux folder and build default configs
```
cd linux
KERNEL=kernel8
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
```
**P.S. The above commands are for 64-bit Raspberry Pi 4. For other Raspberry Pi, the instructions as following:**

- For Raspberry Pi 1, Zero and Zero W, and Raspberry Pi Compute Module 1 default (32-bit only) build configuration
```
cd linux
KERNEL=kernel
make bcmrpi_defconfig
```

- For Raspberry Pi 2, 3, 3+ and Zero 2 W, and Raspberry Pi Compute Modules 3 and 3+ default 32-bit build configuration
```
cd linux
KERNEL=kernel7
make bcm2709_defconfig
```

- For Raspberry Pi 4 and 400, and Raspberry Pi Compute Module 4 default 32-bit build configuration
```
cd linux
KERNEL=kernel7l
make bcm2711_defconfig
```

**P.S. you can run the below command if you would like to customize your image configs.**
```
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
```
The graphical interface will appear and you can adjust the options for the build.

### 5. Build the image
```
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
```
The build process could take one or more hours.

