raspbian as a vm using qemu

Upload: alexandru-barbovschi

Post on 02-Jun-2018

246 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Raspbian as a VM using Qemu

    1/19

    Howto setup Raspberry Pi Emulation with Qemu on Linux or Windows

    by

    http://blog.pcfreak.de [http://blog.pcfreak.de]Der PCFreak - Hardware - Software - Repair

    Get Qemu

    Download and/or install Qemu on your system (Linux or Windows). We need to emulate an ARM1176 CPU with Qemu, but some older versions of Qemu can notemulate this CPU and will not work. To check (on Linux) if your Qemu supports the ARM1176 or at lease the ARM1136-R2 execute the following command:

    qemu-arm -cpu ?

    The Qemu provided by your Linux distribution should just work (tested on latest Linux Mint - apt-get install qemu-syst em-arm)

    For Windows, just use the latest Qemu which you can get here [http://lassauge.free.fr/qemu/]or here[http://www.omledom.com/].

    It is possible, that you need this additional files in the Qemu folder when using Windows.

    intl.dll

    libglib-2.0-0.dll

    libgthread-2.0-0.dll

    libpng14-14.dll

    libssp-0.dll

    SDL.dll

    zlib1.dll

    This DLLs can be downloaded here [http://qemu.weilnetz.de/w32/dll/].

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-001.pnghttp://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-001.pnghttp://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-001.pnghttp://qemu.weilnetz.de/w32/dll/http://www.omledom.com/http://lassauge.free.fr/qemu/http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-001.pnghttp://blog.pcfreak.de/http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=public:l0g0.gif
  • 8/10/2019 Raspbian as a VM using Qemu

    2/19

    Get a Raspberry image

    Download your favourite Raspberry Pi image (linux based) and save it to your harddrive. This documentation used Raspbian

    2013-07-26-wheezy-raspbian.img

    based on Debian Wheezy downloaded from here[http://www.raspberrypi.org/downloads ].

    Get a kernel

    To be able t o boot the Raspberry image, you need a kernel. You can download a working kernel from here [http://xecdesign.com/downloads/linux-qemu/kernel-qemu].

    You should now have the file

    kernel-qemu

    on your harddrive.

    Verify prerequisites

    You should now have the following files on your system. Best practize would be t o keep them in the same folder.

    2013-07-26-wheezy-raspbian.img

    kernel-qemu

    On my Linux machine the folder looks like this:

    On my Windows machine I additionally have a subfolder where my Qemu lives:

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-003.pnghttp://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-002.pnghttp://xecdesign.com/downloads/linux-qemu/kernel-qemuhttp://www.raspberrypi.org/downloads
  • 8/10/2019 Raspbian as a VM using Qemu

    3/19

    Resize the image to have more space

    A realRaspberry Pi uses an SD-Card and you have to copy the image to this card. We do an emulation of this, so we need to resize the image to the size wewant t o use later. To add 2Gb more space to the Raspbian image we have to execute the following Qemu command.

    qemu-img resize 2013-07-26-wheezy-raspbian.img +2G

    This should add additional 2Gb to 2013-07-26-wheezy-raspbian.img.

    On Linux it looks like this:

    And on Windows it should look similar:

    Boot to root shell and fix some stuff

    Before we can do a real boot with the Raspbian image, we need to modify some files to make it work. Some other documentations you can find on the nettell you to mount the image and then do the c hanges - which is easy under Linux - but when using Windows you cannot easily mount the image for modificat ions.An easier way is to boot Raspberrian into a root shell and do the changes there

    Therefore fire-up Qemu with the following command (Don't forget the'init=/bin/sh rw' part)

    qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -append "root=/dev/sda2 panic=1 init=/bin/sh rw" -hda 2013-07-26-wheezy-raspbian.img

    When the system has bootet into a /bin/sh root shell in read/write mode, it should look like this:

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-005.pnghttp://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-004.png
  • 8/10/2019 Raspbian as a VM using Qemu

    4/19

    Fix endless boot loop

    At the root prompt open /etc/ld.so.preload with nano (remember you have an english keyboard)

    nano /etc/ld.so.preload

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-006.png
  • 8/10/2019 Raspbian as a VM using Qemu

    5/19

    A file will open. It contains exact ly one line.

    /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so

    Add a # (SHIFT+3 on german keyboard) at the beginning of the line, so it looks now

    #/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so

    Now press Ctrl+O to write the file and then Ctrl+Xto exit the editor

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-007.png
  • 8/10/2019 Raspbian as a VM using Qemu

    6/19

    This change will make sure, that libcofi_rpi.so will not be loaded. This change was necessary to avoid an endless boot loop.

    Fix disks for later use

    Still at the root prompt create the file

    /etc/udev/rules.d/90-qemu.rules

    by executing the nano editor again:

    nano /etc/udev/rules.d/90-qemu.rules

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-008.png
  • 8/10/2019 Raspbian as a VM using Qemu

    7/19

    Enter the following lines into the file

    KERNEL=="sda", SYMLINK+="mmcblk0"

    KERNEL=="sda?", SYMLINK+="mmcblk0p%n",

    Then press Ctrl+O to write the file and then Ctrl+Xto exit the editor.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-009.png
  • 8/10/2019 Raspbian as a VM using Qemu

    8/19

    Finally enter the command

    sync

    to make sure everything is written to disk.

    Now just c lose Qemu to stop the virtual machine.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-011.pnghttp://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-010.png
  • 8/10/2019 Raspbian as a VM using Qemu

    9/19

    Now we have applied all needed fixes to make the emulation boot without problems and being able to resize the root partition with raspi-config.

    First run

    To f ire-up your machine just execute the following command (pointing to the correct files).

    qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -append "root=/dev/sda2 panic=1" -hda 2013-07-26-wheezy-raspbian.img

    If Qemu automatically prompts you with a root shell asking for a fsckto fix the expanded file system execute the following

    fsck /dev/sda2

    Then reboot the emulation with

    shutdown -r now

    At the next boot Raspbian should automatically boot into raspi-config. Immediately quit raspi-configby selecting .

  • 8/10/2019 Raspbian as a VM using Qemu

    10/19

    Then c reate a link with the following command

    sudo ln -snf mmcblk0p2 /dev/root

    Then manually restart raspi-c onfig with

    sudo raspi-config

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-012.png
  • 8/10/2019 Raspbian as a VM using Qemu

    11/19

    and select

    1 Expand Filesystem Ensures that all of the SD card s...

    The following screen should tell you that everything went fine.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-014.pnghttp://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-013.png
  • 8/10/2019 Raspbian as a VM using Qemu

    12/19

    Accept the message by pressing ENTER and exit raspi-config afterwards by selecting FINISH.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-015.png
  • 8/10/2019 Raspbian as a VM using Qemu

    13/19

    You will get asked if you like to reboot. Select YES to initiate the reboot.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-012.png
  • 8/10/2019 Raspbian as a VM using Qemu

    14/19

    During the reboot the disk well be resized and at t he end you should arrive at the login prompt.

    You can then login with the following credentials:

    username: pi

    password: raspberry

    Please keep in mind, that the keyboard layout is english by default, make sure you type the ycorrectly.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-016.png
  • 8/10/2019 Raspbian as a VM using Qemu

    15/19

    Fixes inside the emulation

    /etc/X11/xorg.conf

    To be able to run X with 800600 we need to manually create an xorg.conf by executing

    sudo nano /etc/X11/xorg.conf

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-017.png
  • 8/10/2019 Raspbian as a VM using Qemu

    16/19

  • 8/10/2019 Raspbian as a VM using Qemu

    17/19

    Just for testing you can now start the X server with

    startx

    It should present you the desktop with a resolution of 800600 pixels as shown in this image.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-019.png
  • 8/10/2019 Raspbian as a VM using Qemu

    18/19

    Additonal Notes

    Memory

    Don' try to use more than 256MB memory within the qemu command line. The value is hard-coded in the emulated arm-chip, so you cannot change it!

    Graphics

    At the moment it seems, that the maximum resolution you can emulate is 800600 with a depth of 16bit.

    http://dokuwiki.pcfreak.de/lib/exe/detail.php?id=nonpublic%3Alinux%3Araspiemu&media=nonpublic:linux:raspbian-020.png
  • 8/10/2019 Raspbian as a VM using Qemu

    19/19