Phase 1: Prepare Kernel (Linux aarch64 Build VM)
-
Download & Extract Kernel:
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.85.tar.xz tar xvJf linux-6.6.85.tar.xz cd linux-6.6.85
-
Configure & Compile Kernel:
make defconfig make kvm_guest.config make -j$(nproc) # Build using all available cores # Kernel image created at: arch/arm64/boot/Image
-
Package Compiled Source & Prepare for Copy:
# Go back to the parent directory cd .. # Create an uncompressed tarball (matches later step) tar cf linux-6.6.85-compiled.tar linux-6.6.85 # Note the location of the kernel Image: linux-6.6.85/arch/arm64/boot/Image # Make sure SSH is running on this Linux VM if using scp: sudo systemctl enable ssh --now # Find this VM's IP address: ip a
Phase 2: Transfer to Host & Prepare Image (Mac Host)
-
Copy Kernel Files from Linux VM to Mac:
- (Run these commands on your Mac Host terminal)
- (Replace
linux_vm_user
andLINUX_VM_IP
with your Linux VM's username and IP address) - (Alternatively, use Shared Folders if your VM software supports it)
# Copy the tarball scp linux_vm_user@LINUX_VM_IP:~/linux-6.6.85-compiled.tar . # Copy the kernel Image file (ensure the path is correct) scp linux_vm_user@LINUX_VM_IP:~/linux-6.6.85/arch/arm64/boot/Image .
-
Resize VM Image: (Ensure the
Image
file andlinux-6.6.85-compiled.tar
are in your current directory on the Mac)qemu-img resize 2024-11-19-raspios-bookworm-arm64-lite.img 16G
Phase 3: Initial VM Setup (Boot to Shell on Mac Host)
- Set Initial Password (Boot to Shell):
(Using the
Image
file copied to your Mac)qemu-system-aarch64 -machine virt -cpu cortex-a72 -smp 6 -m 4G \ -kernel Image \ -append "root=/dev/vda2 rw init=/bin/bash rootfstype=ext4 rw panic=0 console=ttyAMA0" \ -drive format=raw,file=2024-11-19-raspios-bookworm-arm64-lite.img,if=none,id=hd0,cache=writeback \ -device virtio-blk,drive=hd0,bootindex=0 \ -netdev user,id=mynet,hostfwd=tcp::2222-:22 \ -device virtio-net-pci,netdev=mynet \ -monitor telnet:127.0.0.1:5555,server,nowait # --- Inside QEMU Shell --- passwd pi # (Enter and confirm new password) sync exit # --- QEMU will exit ---
Phase 4: Configure Running VM (Boot Normally on Mac Host)
-
Boot VM Normally:
qemu-system-aarch64 -machine virt,accel=hvf -cpu cortex-a72 -smp 6 -m 4G \ -kernel Image \ -append "root=/dev/vda2 rootfstype=ext4 rw panic=0 console=ttyAMA0" \ -drive format=raw,file=2024-11-19-raspios-bookworm-arm64-lite.img,if=none,id=hd0,cache=writeback \ -device virtio-blk,drive=hd0,bootindex=0 \ -netdev user,id=mynet,hostfwd=tcp::2222-:22 \ -device virtio-net-pci,netdev=mynet \ -monitor telnet:127.0.0.1:5555,server,nowait
-
Enable SSH & Connect (Mac Host):
- Inside the VM (via QEMU console), ensure SSH is enabled (
sudo systemctl enable ssh --now
). - From your Mac terminal:
ssh-copy-id -p 2222 pi@localhost ssh -p 2222 pi@localhost # You are now SSH'd into the VM. Run subsequent commands here.
- Inside the VM (via QEMU console), ensure SSH is enabled (
-
Resize Filesystem (Inside VM via SSH):
sudo parted /dev/vda # Then: print -> resizepart 2 100% -> quit sudo resize2fs /dev/vda2
-
Install Dependencies (Inside VM via SSH):
sudo apt update sudo apt install bc bison build-essential fakeroot flex git libelf-dev libssl-dev ncurses-dev rsync wget xz-utils
-
Copy Kernel Archive & Install Modules (Mac -> VM):
- On Mac Host (in a new terminal tab/window, ensure you are in the directory with
linux-6.6.85-compiled.tar
):# Copy the tarball (created earlier) TO the Pi VM scp -P 2222 linux-6.6.85-compiled.tar pi@localhost:~
- Inside VM (via SSH session from step 8):
# Extract the archive tar xf linux-6.6.85-compiled.tar # Navigate into the extracted directory cd linux-6.6.85 # Install the modules sudo make modules_install cd ~ # Go back home # Shutdown VM cleanly before next boot sudo shutdown now
- On Mac Host (in a new terminal tab/window, ensure you are in the directory with
Phase 5: Boot with GPU (on Mac Host)
- Boot with GPU:
(Using the
Image
file on your Mac)qemu-system-aarch64 -machine virt,accel=hvf -cpu cortex-a72 -smp 10 -m 4G \ -kernel Image \ -append "root=/dev/vda2 rootfstype=ext4 rw panic=0 console=ttyAMA0" \ -drive format=raw,file=2024-11-19-raspios-bookworm-arm64-lite.img,if=none,id=hd0,cache=writeback \ -device virtio-blk,drive=hd0,bootindex=0 \ -netdev user,id=mynet,hostfwd=tcp::2222-:22 \ -device virtio-net-pci,netdev=mynet \ -device virtio-gpu-pci \ -device usb-ehci,id=ehci \ -device usb-kbd \ -device usb-mouse \ -monitor telnet:127.0.0.1:5555,server,nowait