Skip to content

Instantly share code, notes, and snippets.

@rnagarajanmca
Last active February 18, 2025 23:54
Show Gist options
  • Save rnagarajanmca/c8d1a086d3b0546575be0811b9a863c3 to your computer and use it in GitHub Desktop.
Save rnagarajanmca/c8d1a086d3b0546575be0811b9a863c3 to your computer and use it in GitHub Desktop.
Raspberry pi emulator for windows

Emulate Raspberry pi on windows

Following files required to emulate raspberry pi on windows

  • QEMU Emulator
  • Raspberry pi kernel
  • Raspberry pi OS image

QEMU emulator

  • QEMU is an emulator
  • Can be downloaded from the link QEMU
  • Download 32 bit the latest version of exe, 64-bit version has some issues
  • When it's executed files will be extracted and available in the same folder
  • Rename the folder into qemu (Which ever you like)

Raspberry pi kernel

  • QEMU requires kernel to emulate the guest OS
  • It will vary between OS and architecture
  • Kernel for Raspberry pi can be downloaded from the link Rpi kernel
  • Download the latest version of the kernel
  • Once downloaded copy the kernel into qemu folder

Raspberry pi OS image

  • Raspberry pi OS(Raspbian) can be downloaded from the following URL Rasbian
  • Once downloaded extract the img file into qemu folder

Booting Raspbian

  • Create a start.bat file under qemu folder
  • put following lines into it
    qemu-system-arm -kernel kernel-qemu-4.4.34-jessie -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -drive "file=2017-07-05-raspbian-jessie.img,index=0,media=disk,format=raw" -net nic -net user,hostfwd=tcp::2222-:22
    • 'kernel-qemu-4.4.34-jessie' is kernel file name
    • '2017-07-05-raspbian-jessie.img' is raspberry pi OS
    • 'hostfwd=tcp::2222-:22' will forward port from guest to host OS. Here we are forwarding port 22 into 2222 .Guest OS can be sshed through 2222 port
    • 'init=/bin/bash' Will boot the OS and launch bash instead displaying GUI
  • Boot the OS by double click on start.bat file
  • Once terminal displayed we need to use followng command to add quemu rules
  • Create a rule file by typing following command
    sudo nano /etc/udev/rules.d/90-qemu.rules
  • Once file opened type following in that file
    KERNEL=="sda", SYMLINK+="mmcblk0"
    KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
    KERNEL=="sda2", SYMLINK+="root"
  • Save the file by pressing ctl+x
  • Shutdown the OS by typing sudo shutdown now If shutdown not working just close the emulator
  • Now open the start.bat file and do the following change to boot into GUI
    • Remove "init=/bin/bash" text which will be displayed after rw Save the file and double click to launch Rasbian with GUI

Increase the partition size

Disk size of the OS can be increased by using the following command from the host machine, Make sure guest OS turned off before increasing the disk size

qemu-img.exe resize 2017-07-05-raspbian-jessie.img +4G

Above command will add 4 GB storage of the guest OS. Once successfully increased the disk size we should expand the partition in guest OS, Follow the steps to expanding partition

  • Launch the rasbian by double click start.bat
  • Once successfully launched open terminal
  • Type sudo fdisk /dev/sda
  • Delete the partition
    • Type p to display the list of partitions
    • Note the partition 2 details this will help us to increase the partition, especially first sector number
    • Delete the partition 2 by typing d and when its asks for the partition number provide 2, this will delete the partition 2
  • Create a new partition
    • Now create new partition by typing n
    • Choose partition type as primary by providing p
    • When position number requested provide 2
    • System will ask for the first sector, provide the first sector number which we noted from the deleted 2nd partition and press enter
    • When system ask for the last sector just type enter it will calculate the last sector and choose by default
    • Once above steps completed type w to commit the changes
  • Now reboot the OS, after successful boot launch terminal again and provide the following command
    sudo resize2fs /dev/sda2
  • After that reboot the OS, Now you have expanded the partition

Increase the swap file size

  • Type following command in terminal sudo nano /etc/dphys-swapfile to open swap file
  • Goto CONF_SWAPSIZE and change that from 100 to 1024
  • Stop the swap file and start again by using following command sudo /etc/init.d/dphys-swapfile stop and sudo /etc/init.d/dphys-swapfile start
@bukyapavankumar
Copy link

where can i contact you?

@rnagarajanmca
Copy link
Author

where can i contact you?

Hi send out a mail to rnagarajanmca@gmail.com

@amongas44
Copy link

ааааааааааааааааааааа

@wutiejun
Copy link

I'm doing something like that too. But I would like to be able to use graphical emulation, this is my startup parameters:

#!/bin/bash

QEMU=/ucrt64/bin/qemu-system-arm.exe
NET_DEV="vont-lan"

function qemu_option_add()
{
    qemu_option+=" "
    qemu_option+="$1"
}

KER_IMAGE_FILE=zImage-6.78.bin

qemu_option_add "-drive if=none,file=2023-12-05-raspios-bookworm-armhf.img/2023-12-05-raspios-bookworm-armhf.img,format=raw,id=ont,index=0 -device virtio-blk-device,drive=ont"

${QEMU} \
 -M virt -cpu cortex-a7 -smp 4 -m 1024 \
 -device virtio-net-device,netdev=net0,mac=52:54:00:12:34:02 \
 -netdev tap,id=net0,ifname=${NET_DEV},script=no,downscript=no \
 -device qemu-xhci -device usb-tablet \
 -device VGA \
 -device usb-kbd \
 ${qemu_option} \
 -serial mon:stdio -serial null \
 -kernel ${KER_IMAGE_FILE} \
 -append "console=ttyS0 mem=1024M ip=192.168.7.2::192.168.7.1:255.255.255.0 console=ttyAMA0 root=/dev/vda2 rw hardware=qemu.arm.linux sn=12345678" \
 -nic user,hostfwd=tcp::5022-:22

I can run the Qemu console correctlly, but the Qemu screen shows:

Guest has not initialized the display(yes).

And nothing else related to graphics is shown.

I've tried to look up some information, but so far I haven't found the cause or solution.
I wonder if you have any ideas to solve this problem.

@grimfervor36
Copy link

https://downloads.raspberrypi.org/raspbian/images/raspbian-2017-07-05/
For Jessie Direct copy the Bat & instructions

@aayes89
Copy link

aayes89 commented Jan 24, 2025

It work for me, but i'm not able to get network working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment