Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build Ubuntu 19.10 image with KVM for Raspberry Pi 4 ARM64
(Note: tested on Ubuntu 19.10 host/x86_64 machine)
~~
Install dependencies:
apt-get install binutils-aarch64-linux-gnu gcc-9-aarch64-linux-gnu bison flex build-essential kpartx
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev
cd /usr/bin
sudo ln -s aarch64-linux-gnu-gcc-9 aarch64-linux-gnu-gcc
# Build armstubs:
git clone https://github.com/raspberrypi/tools.git rpi-tools
cd rpi-tools/armstubs
git checkout 7f4a937e1bacbc111a22552169bc890b4bb26a94
make armstub8-gic.bin
cd ../../
# Build kernel:
git clone https://github.com/raspberrypi/linux.git rpi-linux
cd rpi-linux
git checkout origin/rpi-4.19.y # change the branch name for newer versions
mkdir kernel-build
make O=./kernel-build/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
make -j4 O=./kernel-build/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
export KERNEL_VERSION=`cat ./kernel-build/include/generated/utsrelease.h | sed -e 's/.*"\(.*\)".*/\1/'`
make -j4 O=./kernel-build/ DEPMOD=echo MODLIB=./kernel-install/lib/modules/${KERNEL_VERSION} INSTALL_FW_PATH=./kernel-install/lib/firmware modules_install
Download base image:
http://cdimage.ubuntu.com/ubuntu/releases/19.10/release/ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz
# Patch-up the base image:
xzcat ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz > ubuntu-19.10-preinstalled-server-arm64+raspi3.img
sudo kpartx -av ubuntu-19.10-preinstalled-server-arm64+raspi3.img
# this will create: /dev/mapper/loop32p1 /dev/mapper/loop32p2
# cd to root/top folder
mkdir mount-img
sudo mount /dev/mapper/loop32p2 mount-img
sudo mount /dev/mapper/loop32p1 mount-img/boot/firmware
# Copy armstub
sudo cp rpi-tools/armstubs/armstub8-gic.bin mount-img/boot/firmware/
# Copy kernel and modules
sudo cp rpi-linux/kernel-build/arch/arm64/boot/Image mount-img/boot/firmware/kernel8.img
sudo cp -avf rpi-linux/kernel-build/kernel-install/lib/modules/${KERNEL_VERSION} mount-img/lib/modules/
# Copy non-free firmware
git clone https://github.com/RPi-Distro/firmware-nonfree firmware-nonfree
cp -avf firmware-nonfree/* mount-img/lib/firmware/
# Edit mount-img/boot/firmware/config.txt and check/add:
armstub=armstub8-gic.bin
enable_gic=1
arm_64bit=1
# Close, unmount
References:
https://blog.cloudkernels.net/posts/rpi4-64bit-image/
https://andrei.gherzan.ro/linux/raspbian-rpi-64/
https://andrei.gherzan.ro/linux/raspbian-rpi4-64/
~~
### UPDATES ###
- Tried above based references, did not work
- Recompiling ubuntu kernel (debs) linux-raspi2_5.3.0 source package in progress with KVM/VIRTUALIZATION enabled in kernel config
- Recompiled kernel deb pkg here: http://dl.rohityadav.cloud/cloudstack-rpi/kernel-19.10/
- Simply use the custom deb linux-image packages on upstream Ubuntu 19.10 base image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment