# Use BuildRoot to build a Raspberry Pi image ## Linux tools comparison 1. BuildRoot i. Easy to use ii. Limited configuration settings iii. Requires full image rebuild ![](https://docs.conan.io/en/1.56/_images/conan-buildroot_logo.png) 2. OpenWrt i. Focused on networking gear(e.g. routers) ii. Package-based updates. ![](https://upload.wikimedia.org/wikipedia/commons/8/84/OpenWrt_Logo.svg) 3. Yocto i. Steep learning curve ii. Customizable iii. Active community ![](https://blog.conan.io/assets/post_images/2019-07-26/conan-yocto.png) --- ## Let start to build the first linux image ### Devices: Host: **Ubuntu 22.04.3 desktop amd64** Target machine: **Raspberry Pi 4b** - #### Install some required packeges ``` sudo apt-get install build-essential sudo apt-get install libncurses5-dev libncursesw5-dev ``` - #### Make a project directory ``` mkdir projects cd projects/ ``` - #### Run the commands below to ensure the all packages are latest ``` sudo apt update sudo apt upgrade ``` - #### Once that's done, we'll need to clone BuildRoot project, and then go into the BuildRoot folder ``` git clone git://git.buildroot.net/buildroot cd buildroot/ ``` - #### Construct .config file ``` make ${your config file} ``` - #### Call a graphical interface to adjust the options for the build ``` make menuconfig ``` This is how you would make changes to things like your kernel or adding packages prior to building the linux image. My configuration is as following: - System configuration -> System hostname -> - ${enter your own host name} - System configuration -> System banner -> - ${enter your own banner} - System configuration -> Root password -> - ${enter your password} - Target packages -> Networking applications - [*] OpenSSH - [*] crda - [*] wpa_supplicand - [*] Enable autoscan - [*] Install wpa_passphrase binary - [*] Enalbe support for the DBus control interface - System configuration -> /bin/sh -> - (select **bash**) - Target packages -> Interpreter languages and scripting -> - [*] python3 - Target packages -> Shell and utilities -> - [*] sudo - Target packages -> System tools -> - [*] htop - Target packages -> Text editors and viewers -> - [*] nano - [*] vim - Filesystem images -> exact size - 200M ``` make ``` It will taka for a while. It could take one or more hours in order to build the image The make command will generally perform the following steps: - download source files (as required); - configure, build and install the cross-compilation toolchain, or simply import an external toolchain; - configure, build and install selected target packages; - build a kernel image, if selected; - build a bootloader image, if selected; - create a root filesystem in selected formats. - #### After that, you can check your output files ``` ls -la output/images/ ``` - #### Next, download Raspberry Pi Imager on your host. Open the app click **Choose Os** and select the **Use custom** option. Subsequently, choose sdcard.img you just builded. ![](https://hackmd.io/_uploads/Hk9WiSWb6.png) ![](https://hackmd.io/_uploads/rJ6fjrW-p.png) ![](https://hackmd.io/_uploads/BkP6pKWb6.png) - #### Then, choose your SD card and start to write in. ![](https://hackmd.io/_uploads/BJf-RFb-p.png) #### After that, you can remove your SD card and try to boot your Raspberry Pi