sudo apt install qemu-system-arm
Download from https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit and extract it somewhere.
Resize to 4GB by:
qemu-img resize 2022-09-22-raspios-bullseye-arm64-lite.img 4G
which is needed for qemu, also add a user (since there is no default pi
user anymore!)
First create 2 directories for mount: mkdir ./boot ./rootfs
Then check the starting sector as offset for boot and rootfs with:
file 2022-09-22-raspios-bullseye-arm64-lite.img
The output is like this:
file 2022-09-22-raspios-bullseye-arm64-lite.img
2022-09-22-raspios-bullseye-arm64-lite.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x40,0,1), end-CHS (0x3ff,3,32), startsector 8192, 524288 sectors; partition 2 : ID=0x83, start-CHS (0x3ff,3,32), end-CHS (0x3ff,3,32), startsector 532480, 3391488 sectors
Mount the boot
partition:
sudo mount -o loop,offset=$[512*8192] 2022-09-22-raspios-bullseye-arm64-lite.img ./boot/
Do cd boot
and copy these 2 files: bcm2710-rpi-3-b.dtb
and kernel8.img
.
Now, and Add a user according to raspberry pi official documentation https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user
Unmounting the boot directory, will save the modifications on the image file:
sudo umount ./boot/
- Note: To mount the rootfs on Raspbian image and edit, you need to grab the
startsector
from thefile
command output. In our case it is 532480 and this value should be used as offset inmount
command; e.g.
sudo mount -o loop,offset=$[512*532480] 2022-09-22-raspios-bullseye-arm64-lite.img ./rootfs/
qemu-system-aarch64 -M raspi3b -cpu cortex-a72 -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootdelay=1" -serial stdio -dtb ./bcm2710-rpi-3-b.dtb -sd ./2022-09-22-raspios-bullseye-arm64-lite.img -kernel kernel8.img -m 1G -smp 4
Apped -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::4321-:22
to the end of the command in Run section. When Raspbian is up, start ssh service by sudo systemctl start ssh
. Now, in your host machine type:
ssh -p 4321 pi@localhost
To do scp
(secure copy) you can use the following:
scp -P 4321 [email protected]:/tmp/xyz /tmp
https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user
https://blog.videgro.net/2015/11/modify-disk-image-raspbian/