Skip to content

Instantly share code, notes, and snippets.

@t-mat
Last active August 29, 2015 14:05
Show Gist options
  • Save t-mat/76827d21996ecb6e4f6e to your computer and use it in GitHub Desktop.
Save t-mat/76827d21996ecb6e4f6e to your computer and use it in GitHub Desktop.
Using lastest QEMU and Raspbian on Windows

Using lastest QEMU and Raspbian on Windows (x64)

Prerequisite

  • Put curl and 7z on your %PATH%

Downloading

I use "%USERPROFILE%\Documents\qemu-raspi" for target directory.

Windows:

curl --version
7z --help
cd /d "%USERPROFILE%\Documents"
mkdir qemu-raspi
cd qemu-raspi
curl -OL http://qemu.weilnetz.de/w64/qemu-w64-setup-20140801.exe
7z x -oqemu qemu-w64-setup-20140801.exe
mkdir raspi
pushd raspi
curl -OL http://xecdesign.com/downloads/linux-qemu/kernel-qemu
curl -OL http://downloads.raspberrypi.org/raspbian_latest
7z x raspbian_latest -so > raspbian_latest.img
popd

Initial boot

Windows:

@cd /d "%USERPROFILE%\Documents\qemu-raspi"
@set QEMU_OPT=-M versatilepb -cpu arm1176 -hda raspi\raspbian_latest.img -kernel raspi\kernel-qemu -m 192 -redir tcp:5022::22
@start "" qemu\qemu-system-armw.exe %QEMU_OPT% -no-reboot -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash"

After you see the following prompt in QEMU window

QEMU:

root@(none):/#

Run the following command (it adds # to the beginning of /etc/ld.so.preload)

QEMU:

sed -i '1s/^/#/' /etc/ld.so.preload

Do exit to close QEMU

QEMU:

exit

Usual Boot

Windows:

@cd /d "%USERPROFILE%\Documents\qemu-raspi"
@set QEMU_OPT=-M versatilepb -cpu arm1176 -hda raspi\raspbian_latest.img -kernel raspi\kernel-qemu -m 256 -redir tcp:5022::22
@start "" qemu\qemu-system-armw.exe %QEMU_OPT% -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw"
  • You may see "Raspberry Pi Software Configuration Tool (raspi-config)", do something you like
    • I recommend go to "4 Internationalisation Options" - "I3 Change Keyboard Layout" and select your keyboard properly.
    • After that, press TAB key to select <Finish>, and press Enter to finish raspi-config.
  • Now, you can use QEMU window or SSH (localhost:5022) to login Raspbian
    • Use username:pi, password:raspberry

Increase storage capacity

  • Close QEMU window
  • Increase disk image capacity with qemu-img (here I add +10 Giga Bytes)

Windows:

@cd /d "%USERPROFILE%\Documents\qemu-raspi"
@qemu\qemu-img resize raspi\raspbian_latest.img +10GB
  • Run QEMU ("Usual Boot"), login
  • Create a file /etc/udev/rules.d/90-qemu.rules

QEMU:

sudo nano /etc/udev/rules.d/90-qemu.rules
  • with the following content

QEMU:

KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
  • Reboot QEMU, login
  • Make symlink and do raspi-config

QEMU:

sudo ln -snf mmcblk0p2 /dev/root
sudo raspi-config
  • Select 1 Expand Filesystem in raspi-config, and reboot
  • Make sure your storage capacity is increased

QEMU:

df -h

/dev/mmcblk0p1 does not exist error

You may have seen the following error message in the boot log:

[....] mounting local filesystems...mount: special device /dev/mmcblk0p1 does not exist
failed

Since in this setup, QEMU does not have any SD card device, it is a proper error.

Kernel and modules mismatch problem (should be resolved)

You can see running kernel version (uname -r) and Raspbian Images required kernel

pi@raspberrypi ~ $ uname -r
3.10.26+
pi@raspberrypi ~ $ ls -1 /lib/modules
3.12.22+

This mismatch causes many related problems. For example, you can see the following error in boot sequence :

[info] Loading kernel module snd-bcm2835
libkmod: ERROR ../libkmod/libkmod.c:554 kmod_search_moddep: could not open moddep file '/lib/modules/3.10.26+/modules.dep.bin'

And lsmod is not working, etc.

See also

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