Skip to content

Instantly share code, notes, and snippets.

@KarolPWr
Created May 11, 2024 10:53
Show Gist options
  • Save KarolPWr/b8a507a61d3cf95f3ba48df7592b80e1 to your computer and use it in GitHub Desktop.
Save KarolPWr/b8a507a61d3cf95f3ba48df7592b80e1 to your computer and use it in GitHub Desktop.
QEMU dla Raspberry Pi 4
#!/bin/bash
set -x
if [ $# -lt 1 ]; then
RPI_DIR=$(pwd)
else
RPI_DIR=$1
fi
cd "$RPI_DIR" || exit
# Budowanie kernela
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.34.tar.xz
tar xvJf linux-6.1.34.tar.xz
cd linux-6.1.34 || exit
# Tworzymy domyślny config
ARCH=arm64 CROSS_COMPILE=/bin/aarch64-linux-gnu- make defconfig
# Dodajemy do domyślnego configu opcje umożliwiające wirtualizację
ARCH=arm64 CROSS_COMPILE=/bin/aarch64-linux-gnu- make kvm_guest.config
# Budujemy kernel
ARCH=arm64 CROSS_COMPILE=/bin/aarch64-linux-gnu- make -j4
cp arch/arm64/boot/Image ..
# Ściąganie obrazu
cd ..
# Ściągamy obraz dla Raspberry Pi 4
wget https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2023-05-03/2023-05-03-raspios-bullseye-arm64.img.xz
xz -d 2023-05-03-raspios-bullseye-arm64.img.xz
sudo mkdir -p /mnt/image
sudo mount -o loop,offset=4194304 "$RPI_DIR"/2023-05-03-raspios-bullseye-arm64.img /mnt/image/
qemu-img resize "$RPI_DIR"/2023-05-03-raspios-bullseye-arm64.img 8G
# Generujemy hasło
PASSWORD="malina"
PASSWORD_HASH=$(echo "$PASSWORD" | openssl passwd -6 -stdin)
echo pi:"$PASSWORD_HASH" | tee /mnt/image/userconf
# Odpalamy QEMU
qemu-system-aarch64 -machine virt -cpu cortex-a72 -smp 6 -m 4G \
-kernel Image -append "root=/dev/vda2 rootfstype=ext4 rw panic=0 console=ttyAMA0" \
-drive format=raw,file=2023-05-03-raspios-bullseye-arm64.img,if=none,id=hd0,cache=writeback \
-device virtio-blk,drive=hd0,bootindex=0 \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment