Recently, we recommended chainsx’s “Raspberry Pi Ubuntu 64-bit System Player Experience Edition”. The author further provides methods for self-compiling the above system and creating an image file, introducing how to cross-compile and compile directly on the Raspberry Pi, teaching you to fish~
You can cross-compile using Ubuntu 16.04 or compile directly on the Raspberry Pi. We follow the official Raspberry Pi kernel compilation guide here, thanks to bamarni for the ideas provided.
Cross-Compiling on a Computer
Building the Kernel You need a 64-bit version of Ubuntu 16.04. Install the cross-compilation environment.
apt-get update
apt-get install -y bc build-essential gcc-aarch64-linux-gnu git unzip
Get the source code.
git clone --depth=1 -b rpi-4.8.y https://github.com/raspberrypi/linux.git
Next, start your build by running the following commands:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
At this point, you can make a cup of tea, watch TV, or play games… because this will take some time. Prepare a System Here, I take Raspbian as an example (some numbers you need to change yourself, don’t be too rigid). First, download Raspbian from the official website (it is recommended to download the lite version). After unzipping, you will get an img file. Then, we review it with the following command:
fdisk -l raspbian-jessie-lite.img
Disk raspbian-jessie-lite.img: 1.3 GiB, 1390411776 bytes, 2715648 sectors
Units: sectors of 1*512=512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x244b8248
Device Boot Start End Sectors Size Id Type
raspbian-jessie-lite.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
raspbian-jessie-lite.img2 137216 2715647 2578432 1.2G 83 Linux
Note, the above two lines are very critical!
We can mount these partitions on our file system (of course, you can also write directly to the SD card), starting from the root partition:
mount -o loop,offset=70254592 raspbian-jessie-lite.img /mnt
The offset depends on the sector size (512): 70254592 = 512 * 137216. Next is the boot partition:
mount -o loop,offset=4194304,sizelimit=66060288 raspbian-jessie-lite.img /mnt/boot
Offset: 4194304 = 512 * 8192, sizelimit: 66060288 = 512 * 129024. Install the Kernel Execute the following commands to copy the compiled kernel and device tree into the system (provided that you have completed the compilation):
cp arch/arm64/boot/Image /mnt/boot/kernel8.img
cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /mnt/boot/
Execute the following command to install the kernel modules.
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu INSTALL_MOD_PATH=/mnt modules_install
Execute the following command to adjust config.txt.
echo kernel=kernel8.img >> /mnt/boot/config.txt
However, to be safe, you should manually modify it. If it does not exist, add kernel=kernel8.img
, if it does, change it to kernel=kernel8.img
. Unmount the Partitions
umount /mnt/boot && umount /mnt
All done!
Compiling on the Raspberry Pi
It is actually quite similar. You just don’t need the cross-compilation tools, but it takes a bit longer. Note, you must use an aarch64 (arm64) system for compilation! However, here are ready-made Debian | Ubuntu (if you use Ubuntu, please change the source to the Chinese Academy of Sciences’ mirrors.opencas.org). Install Dependencies
apt-get update
apt-get install -y bc build-essential
Get the Source Package
git clone https://github.com/raspberrypi/linux.git
Start Compiling
make ARCH=arm64 bcmrpi3_defconfig
make ARCH=arm64
At this point, it is a test of your mentality, it may take more than an hour! If you want multi-core compilation, use the -j4
parameter. Prepare a System to Port. Here are a few recommendations. Ubuntu 15.10 | CentOS. After downloading, mount it according to the above method, or write it directly to the SD card. Install the Kernel Execute the following commands to copy the compiled kernel and device tree into the system (provided that you have completed the compilation).
cp arch/arm64/boot/Image /mnt/boot/kernel8.img
cp arch/arm64/boot/dts/broadcom/bcm2710-rpi-3-b.dtb /mnt/boot/
Execute the following command to install the kernel modules:
make ARCH=arm64 INSTALL_MOD_PATH=/mnt modules_install
Execute the following command to adjust config.txt.
echo kernel=kernel8.img >> /mnt/boot/config.txt
However, to be safe, you should manually modify it. If it does not exist, add kernel=kernel8.img
, if it does, change it to kernel=kernel8.img
. Unmount the Partitions
umount /mnt/boot && umount /mnt
Thus, all done
Creating Your Own System
Here, I will briefly mention the idea of creating a root partition (rootfs). If you are familiar with debootstrap, use it to build your own (this can be tricky because it requires some manual adjustments; its original purpose is to perform chroot on an already running host, not to build a root filesystem for other machines). I recommend using multistrap, here is a great tutorial: http://free-electrons.com/blog/embdebian-with-multistrap/.
Likewise, here are a few compressed files for root partitions. Ubuntu 17.04 | CentOS.
Tip: For first-time users of Raspberry Pi 64-bit Ubuntu, it is recommended to change the source of Ubuntu 15.10 to the Chinese Academy of Sciences’ source mirrors.opencas.org, otherwise, you will not be able to use it. Project GitHub: https://github.com/chainsx/ubuntu64-rpi Maker fun endless project homepage: http://maker.quwj.com/project/28
If you need to discuss and provide feedback, please click the end of the article 【Read Original】 to leave a message.
Submission: [email protected]