In this post we are going to see how to emulate a Raspberry Pi with Raspbian in a virtual machine using Oracle VM VirtualBox
Emulating a Raspberry Pi in a virtual machine can be useful, for example, for testing without having a physical Raspberry available, or for experimenting in a controlled environment before deploying it on the real machine.
It should also be said that, although in recent times the virtualization of a Raspberry Pi has been greatly simplified (before it was almost impossible), with the release of Raspberry Pi Desktop, the image still has limitations compared to having a real Raspberry Pi running.
In any case, it is very simple and does not take up much space on the hard drive, so if you are going to work frequently with Raspberry Pi, it is useful to have a virtual machine on the computer for testing and experiments.
Create the virtual machine
First, download and install the latest version of Virtual Box from https://www.virtualbox.org/
On the other hand, download the latest version of Raspberry Pi Desktop from https://www.raspberrypi.org/downloads/raspberry-pi-desktop/.
Launch Virtual Box and add a new machine.
Put a name to our machine, for example “RaspberryPi”, and select type “Linux”, version “Other Linux”.
Increase the memory size to 512 Mb.
Now we have to create a virtual hard disk, where the machine’s files will be stored. Choose “create a new virtual hard disk”.
Leave the default type of hard drive.
Now choose whether you want the size to be dynamically allocated, or fixed size. If it is a dynamic size, the virtual hard disk file will only be the size of the space actually occupied on the virtual machine. But in return, the performance will be lower when it has to expand the size. If we choose a fixed size, the performance will be higher, but the virtual hard disk file will always occupy the maximum size of the virtual hard disk.
We can choose dynamically allocated.
Choose a name for the virtual hard disk file, for example “RaspberryPi”, and choose a size between 8Gb - 16Gb. In general, 8Gb is going to be more than enough.
We already have our virtual machine created. Now, double click to start it.
Installing Rasperry Pi Desktop
The first time we start it, it will ask us to insert an image as a virtual installation CD of the OS. Choose the image we downloaded in the first step.
Choose “Graphic install” and follow the steps of the installer, leaving the options it offers us by default.
At the end of the process our virtual machine with Raspberry Pi will start, and we are ready to start playing and experimenting with it.