Raspberry Pi in a virtual machine (Raspbian)

3 ways to run Raspberry Pi Desktop on a virtual machine

For once, we won’t do anything on the Raspberry Pi directly, but we will instead see how to do without it.

Is it possible to virtualize the Raspberry Pi to use Raspbian on Windows, Linux or Mac?
Yes, it is possible to create a virtual machine that runs Raspbian, to emulate a Raspberry Pi, in 3 different ways:

  1. With a virtual machine in VirtualBox
  2. By emulating it with QEMU
  3. Or with VMWare Workstation

And here we’ll see how to do it with these three tools, from your favorite operating system

This softwares can be very useful if you are a developer, if you don’t have your Raspberry Pi with you, or if you want to test something without breaking your installation on the SD card

Download Raspbian image

I think that’s probably the main problem you’ve encountered, where to find an image compatible with the main hypervisors?

Indeed, the default image offered on the official website, which is an .img format, can not work on VirtualBox for example
Looking for this image, I came across a lot of forums that said it was not possible to emulate a Raspberry Pi on PC, because it turns on ARM architecture, unlike a PC …

And finally, I ended up finding this image, directly on the official website, just above the main download
So you can download the image of Raspian in iso format before continuing this guide
I advise you to use a Torrent client to download it. It’s much faster

Run Raspberry Pi on VirtualBox

Introduction

VirtualBox is an open-source hypervisor, developed by Oracle
It is available for most operating systems: Windows, Linux, Mac OS, Solaris, …
It allows you to create virtual machines on your computer and supports a large number of operating systems to virtualize

Installation

You can find download links for Windows, Mac, and Linux on this page: https://www.virtualbox.org/wiki/Downloads

In any case, the installation is straightforward:

  • Download the installer corresponding to your environment
  • Launch the installer and keep the default options

Create the virtual machine

Launch Oracle VirtualBox now on your computer, and we will create the virtual machine:

  • Click on New in the top bar
  • Choose a Name
  • Type: Linux
  • Version: Anyone
  • Memory size: 1Gb is enough, but you can set more depending on your computer memory available
  • Hard disk: You can keep the default options (10GB)

Our new virtual machine is available, but now you have to tell it to start on the previously downloaded iso file

  • Click on Settings in the top bar
  • Select Storage in the left menu
  • Below the first controller, click on Empty
  • On the right panel, click on the Disc icon to choose the file
  • Select Choose Virtual Optical Disk File
  • Browse to the location of the image and validate

Ok, you should have something like this :

Now we can start the virtual machine and install the Raspberry Pi Desktop :

  • Click on Start in the top bar
  • Choose Install in the first menu
  • Select your Keyboard layout
  • For partition disks, you can keep the default options (use entire disk > all files in one partition > finish > yes)
  • Installation starts
  • After a few minutes, the installation wizard resumes
  • Confirm the bootloader installation to the master boot record
  • Select /dev/sda
  • Continue to reboot your new operating system

Once the reboot is done, you will come to a first start wizard like this one:

Raspberry Pi running in Virtualbox

Choose the settings that best suits you
Change the default password
Update your system and reboot one last time

Your Raspberry Pi Desktop virtual machine running in VirtualBox is finally operational!

Create a virtual machine in QEMU

Introduction

QEMU is another great open source machine emulator and virtualizer, developed by Fabrice Bellard under GPL License
It can run a lot of guest systems and it also can be used with KVM to increase virtual machines speed
QEMU is available for Linux, Mac OS, and Windows

Installation

The installation is not quite the same depending on your operating system, so I quickly explain how to do

Linux installation:

For Debian/Ubuntu, QEMU is available in the repository so that you can install it with:

apt-get install qemu

For other distributions, it is usually available as easily via the basic commands:

RedHat/CentOS: yum install qemu-kvm
SUSE: zypper install qemu
Arch: pacman -S qemu

 

Mac OS installation:

QEMU is available via Homebrew or MacPorts

HomeBrew:

brew install qemu

MacPorts:

port install qemu

Windows installation:

You can get the last installer version following this link

Then launch the .exe file and follow instructions

Create the virtual machine

QEMU is a command line tool
So whatever your system you will have to do this 🙂
I give instructions for Linux; it may need to be slightly adapted if you are on another system
In Windows, for example, you need to start the cmd tool, and change to QEMU directory (cd “C:\Program Files\Qemu”)

First, create a folder for your VMs and move the image in

sudo mkdir ~/qemu/
mv ~/Downloads/IMAGE.iso ~/qemu/
cd ~/qemu

Now let’s launch the image in qemu with the following command:

qemu-system-x86_64 -hda IMAGE.iso -m 1024 -net nic -net user
  • Choose Install in the first menu
  • Select your Keyboard layout
  • For partition disks, you can keep the default options (use entire disk > all files in one partition > finish > yes)
  • Installation starts
  • After a few minutes, the installation wizard resumes
  • Confirm the bootloader installation to the master boot record
  • Select /dev/sda
  • Continue to reboot your new operating system

Once the reboot is done, Raspberry Pi Desktop is starting :

Raspberry Pi in QEMU

A wizard will start on first boot

Choose the settings that best suits you
Change the default password
Update your system and reboot one last time

Your Raspberry Pi Desktop virtual machine running in QEMU is now operational!

Run Raspbian with WMWare Workstation

Introduction

VMWare Workstation is a proprietary hypervisor distributed by VMWare, a subsidiary of Dell
There is a free version, VMWare Workstation Player, for non-commercial use
Workstation can emulate most operating systems

VMWare also develops many other professional tools, which can allow you to use virtual machines on a large scale, but this is not the subject of the day 🙂

Installation

You can download VMWare Workstation Player on the official website
There is a Linux and Windows version, not sure about Mac OS

On Windows just run the .exe file to start the setup

On Linux you have to start the wizard like this :

sudo sh VMware-Player-VERSION.x86_64.bundle

You can keep default options, and no key is needed for the moment

On the first start, choose that you want to use Workstation Player for non-commercial use, and we are ready 🙂

(I had problems with Linux at first start, I had to take a newer version than the one given on the site because the modules did not install, if it happens to you, you know what to do)

Create the virtual machine

We will now create our virtual machine

  • Select “Create a New Virtual Machine”
  • Choose “Use ISO image” and Browse to your Raspbian iso file
  • On the next screen, select Linux and Debian 64 bits for example
  • Name your virtual machine and change installation folder if you want
  • For the disk space, you can let 20GB or decrease it to 10GB to save disk space on your computer
  • Finally, click on Finish and Close

Virtual Machine will start directly after the wizard ends

  • Click on Start in the top bar
  • Choose Install in the first menu
  • Select your Keyboard layout
  • For partition disks, you can keep the default options (use entire disk > all files in one partition > finish > yes)
  • Installation starts
  • After a few minutes, the installation wizard resumes
  • Confirm the bootloader installation to the master boot record
  • Select /dev/sda
  • Continue to reboot your new operating system

You can choose to Download and install VMWare Tools if you want (not mandatory)

A wizard will start on first boot

Choose the settings that best suits you
Change the default password
Update your system and reboot one last time

raspberry vmware workstation player

Your Raspberry Pi Desktop virtual machine running in VMWare Workstation is now operational!

What to do next?

Once your virtual machine is installed, and no matter what hypervisor you choose, I invite you to follow the various tutorials of this website to set up the necessary software (ssh, vnc, …), as if you were on a Raspberry Pi

There are probably other things that are more dependent on the fact that your Raspbian is on a virtual machine:

  • network card: by default, I had network and Internet in the 3 installation cases, but maybe depending on your environment, it will not work on first boot. Or maybe you will need the opposite: isolate the virtual machine of the network
  • file sharing: it can be interesting to have a shared folder between your virtual machine and your computer (especially for developers, to work on your computer, and launch the application on the virtual machine)
  • adjust the hardware: you may have to adjust the screen resolution, disk size or RAM to suit your needs

I will not go into detail about all this because it depends on everyone
But be aware that once Raspberry Pi is virtualized and functional, you can follow any tutorial about the chosen hypervisor to help you, it does not depend on Raspbian most of the time

Why do I need a virtual machine?

The following will depend on why you created this virtual machine, but I can give you some ideas

Not (yet) a Raspberry Pi

If you do not have a Raspberry Pi, but you plan to buy one, testing its capabilities on a virtual machine can be a good idea
This allows you to have a good vision of what you will be able to do. Maybe to test, to install, or to program the software which you would like to use, and to do to the purchase only when you’re sure

Moving

You are addicted to Raspberry Pi, but you can not take it everywhere?
A virtual machine on your usual computer will allow you to continue your projects, even without having the Raspberry Pi with you

More powerful

Whether you’re a tester, developer, or just curious, running your Raspberry Pi desktop on a virtual machine will help you increase power and efficiency by taking advantage of your computer’s resources.
This can save you a lot of time on some applications

Snapshots

Obviously who says virtual machine says you can create snapshots
A snapshot and a complete image of the virtual machine at a time T
So it becomes possible to test something, and go back if it does not happen as expected (instead of having to recreate an SD card, reinstall everything needed, etc … if we work directly on the Raspberry Pi)

Conclusion

So we saw how to create a Raspbian virtual machine on three different hypervisors:
– VirtualBox
– QEMU
– VMWare Workstation

We also saw what the benefits of virtualization could be when talking about Raspberry Pi

It’s up to you now to launch your projects on this, good luck!

 

Leave a Comment