Installing Raspberry PI Desktop OS (also known as Raspbian) on a VirtualBox Virtual Machine (VM) is very useful to run and test some code without needing a real Raspberry PI.
The Raspberry PI Desktop includes an emulated Raspberry PI board that can be used to test some basic scripts and check the most common functionalities of this board.
In addition, using VM snapshots, it is really easy to save the state of the machine and revert all the changes done after that point. In this way, it is possible to run different experiments starting from the same virtual machine state. For additional information about snapshots, please check the official Oracle documentation.
Steps to install Raspberry PI Desktop on a VM
- In order to install VirtualBox from Oracle on your PC, you first need to download it from the official website.
When the installation of VirtualBox is complete, then you can install any Operating System (OS) is needed.
In particular, you can install Raspbian, a Linux OS deriving from Debian.
- Download the Raspberry PI Desktop ISO image from the official website.
- Launch VirtualBox.
- Create a new Linux Virtual Machine indicating Debian 64 bit as Operating System to use. In order to use the same amount of RAM available on a Raspbarry PI 3 (model B+), select 1GB of RAM. After this, when prompted for hard-disk type, select dynamic size and 8-10 GB of available space.
- When prompted, select “Graphical Install”.
- Setup Language and Keyboard layout.
- Choose your partitioning scheme. Choose the default one if you haven’t particular requirements.
- When prompted, select and install GRUB Bootloader (select /dev/sda).
- Wait until the VM boots into the Raspberry PI Desktop.
- When loaded, the OS will check for new updates. Please, wait until all updates have been downloaded and installed.
Install VM Guest Addon for Linux (Debian)
- From the menu, click on Devices > Insert Guest Additions.
- Open a terminal window and type the following command to install the VirtualBox Guest Additions for Linux Debian:
sudo sh /media/cdrom0/VBoxLinuxAdditions.run
- In order to enable the shared folders, please type this command:
sudo adduser pi vboxsf
- Add a shared folder to your VM: for example, a shared folder called “PC” pointing to any location to your host machine.
- When finished, please reboot typing:
- When the OS has finished rebooting, you should have an environment similar to the following one:
On the Desktop, there will be two icons: the used Shared Folder (starting with “sf_” prefix) and the VM Guest Addons folder. If you open the Terminal, you can access both under the media folder; in other words, you need to type:
You can find both folders “cdrom0” and “sf_PC” (or another name, depending on your choice).
In order to eject the VM Guest Addons cdrom, you can also click on the “eject” button on the top-right of the Desktop.