Wed. Nov 29th, 2023

Key Takeaways

  • To create a virtual machine running the Raspberry Pi OS, you’ll need to:
  1. Download the Raspberry Pi OS image.
  2. Launch VirtualBox and create a new virtual machine.
  3. Boot the virtual machine using the Raspberry Pi OS image.
  4. Install the Raspberry Pi OS, then perform any final tweaks, such as setting the screen resolution.

Running a Raspberry Pi in a virtual machine is a useful hack for developers, hobbyists, and anyone who wants to try before they buy. Here’s how to do that in VirtualBox.

Why You Might Need a Virtual Raspberry Pi

The Raspberry Pi is a single board computer about the size of a credit card. It’s a fully-functioning tiny PC at a budget price and with a great specification. There are many models in the product line up, ranging from the minimalist Pi Pico at less than $10 up to the Raspberry Pi 5 flagship product announced in September 2023. This sells for $60 for the 4GB model, and $80 for the 8GB model.

Because of their tiny size, low price point, and ability to run a Linux distribution, Raspberry Pis were adopted by hobbyists, makers, and tinkerers and used in all sorts of interesting and creative projects, far beyond its intended educational market. These projects often run as headless systems, using the computational power in instances where you don’t need a screen, keyboard, and mouse. The Raspberry Pi provides the embedded brain of the project, and runs without human interaction. People have used the Raspberry Pi as the core computing element for their own networked appliances and Internet-of-Things devices.

But you’re not locked into headless devices. Most Raspberry Pi models can drive a high-resolution monitor. In fact, Raspberry Pi models 4 and 5 have two micro-HDMI outputs, allowing them to drive two monitors simultaneously, and the Raspberry Pi models 1, 2, and 3 could all drive a single monitor. Load them with a Linux distribution designed for ARM hardware, attach a keyboard, mouse and monitor, and you’ve got a desktop PC.

Admittedly, the power of the earlier models meant performance was modest, but the later models are significantly more powerful. Being able to use the Raspberry Pi like this makes developing for the Pi much easier. Developing on another platform such as a traditional desktop PC could lead to surprises when your code was moved to the Raspberry Pi for testing.

The trouble is, software developers need power, and the Raspberry Pi only has so much to offer. For developments to move at a realistic pace, compilation times need to be short. Perhaps your tool chain needs more memory than the Raspberry Pi can support. On top of that, the Raspberry Pi uses an SD card as storage, so disk-intensive activities can be throttled.

One answer is to run the Raspberry Pi operating system as a virtual machine on other hardware. That gives you the power you need to drive it at a realistic speed, and the ability to configure as much RAM and hard drive space as you like.

You can use that to aid your development efforts, and then test your app on another virtual machine configured to replicate the actual specification of the Raspberry device you’re going to run the finished software on. Because you can create a snapshot of a virtual machine and roll back to it, you can instantly roll your test machine back to a naked state between tests.

Maybe you’re not a developer though, you might just be someone who is intrigued by the Raspberry Pi but wary of handing over your money until you’ve had a chance to poke around and see if it suits your needs. Running the Raspberry OS in a virtual machine will give you a good idea of what to expect.

There will be some differences of course, you won’t be testing the actual Raspberry Pi hardware, so network throughput and video quality won’t be representative of the actual device.

Let’s go through the steps required to set up a Raspberry Pi virtual machine in VirtualBox.

Downloading the Raspberry Pi Desktop OS

There are many operating systems you can use on a Raspberry Pi, but the Raspberry Pi hardware is ARM-based, and VirtualBox doesn’t emulate ARM hardware. So to create a virtual machine you need to use an Raspberry Pi operating system that also provides a version that supports x86 hardware.

The official operating system for the Raspberry Pi called Raspberry Pi OS. It’s based on Debian Linux and you can download a version for PC and Mac. That’s the version we’ll use.

Download the Raspberry Pi Desktop operating system and take note of where the ISO image is located on your computer. It’ll probably be in your “Downloads” folder.

Creating The Virtual Machine

The first step is to create the virtual computer that we’re going to install the operating system into.

Start VirtualBox, and click “Machine” then “New.” We need to give a name to the virtual machine. This is just a label that VirtualBox uses to identify the machine, so you can call it anything. We’re going with the straightforward name of “RaspberryPi.”

Setting the name for the virtual machine, and it's location on the hard drive

In the “Folder” field, enter the directory you want VirtualBox to store your new virtual machine in. In the “ISO Image” field choose the file you downloaded. The drop-down lets you navigate to the file. Finally, select the “Skip Unattended Installation” checkbox and click the “Next” button.

The “Hardware” page lets us set the RAM and number of CPU cores we’re devoting to this virtual machine.

Setting the RAM and number of processors for the virtual machine

I selected 8GB of RAM and left the CPU cores at one. Click the “Next” button when you’re ready to proceed.

The “Virtual Hard Disk” page lets you select the size of the hard drive in our VirtualMachine. This will replicate the SD card that the Raspberry Pi uses for storage.

Creating the hard drive for the virtual machine

I gave it a 16GB hard drive, and ignored the other options. This doesn’t immediately pinch 16GB from your hard drive, VirtualBox allows the virtual machine’s virtual drive to grow on demand up to a maximum of 16GB.

Click the “Next” button to move on.

The “Summary” page shows you a recap of your choices.

The Summary screen showing the choices made so far in the creation of the virtual machine

Click the “Finish” button to create your virtual machine.

You’ll see a new entry in the VirtualBox application, with the name you’ve just chosen. In our case, it was “Raspberry Pi.”

The new virtual machine in the VirtualBox application

We’re going to fine-tune some settings in our machine. Select your new virtual machine and click the “Settings” icon.

Select “Display” in the sidebar, and drag the “Video Memory” slider all the way to the right.

Setting the video memory for the virtual machine

This gives the virtual machine more RAM to use for its virtual graphics card.

Select “Network” in the sidebar and choose “Bridged Adapter” in the “Attached to” drop down.

Setting the virtual machine's network interface to a Bridged Adapter

This gives our virtual machine a network connection in the same IP range as your actual PC. This makes it easier to SSH onto your virtual machine, should you need to, and allows your virtual machine to access physical devices such as printers. Click the “OK” button at the bottom of the screen. The settings dialog will close.

Now we can launch our virtual machine by clicking the green arrow icon.

Launching the virtual machine by clicking the green arrow icon

Our virtual machine is launched and the ISO image is booted.


Select “Install” from the menu and hit “Enter.” Select your keyboard from the list, and hit “Enter.”

Selecting the keyboard type in the installation program

On the “Partitioning Disks” screen select “Guided – use Entire Disk” and hit “Enter.”

Selecting the partitioning method in the installation program

We’ve only got one hard drive in this virtual machine. We’re warned it will be wiped of all data. That’s fine, there’s nothing on this brand-new virtual drive.

Confirming the hard drive to partition in the installation program

Hit “Enter” to move on. You’re asked for a partitioning scheme. Make sure “All files in one partition (recommended for new users)” is selected and hit “Enter.”

A summary of the partitioning choices made in the installation program

You’ll see a summary of the partitioning choices you’ve made.


Hit “Enter” to proceed. The screen changes to allow you to opt out. “No” is selected by default.

Committing to partitioning the disks in the installation program

Highlight “Yes” and hit “Enter.” Presently, you’ll see a screen telling you that the installer assumes you want to install the GRUB boot loader to the primary drive of this virtual machine.

Installing the GRUB boot loader in the installation program

It’s the only drive we’ve got, so you can hit “Enter” to accept that location.

On the next screen select “/dev/sda (ata-VBOX_HARDRISK….)” and hit “Enter.”

Confirming the location of the boot loader in the installation program

That tells the installer to use the first partition on the hard drive as the location for the boot loader.

A progress bar will slowly creep along as the installation takes place.

The installtion progress bar in the installation program

Eventually you’ll see the “Finish the Installation” page.

The installation complete, time to reboot screen in the installation program

Make sure “Continue” is highlighted and hit “Enter.” Your virtual machine will reboot.

Booting into Raspberry Pi for the First Time

As your virtual machine is booting you’ll see the usual boot screens just as if you were booting a physical Raspberry Pi. The first screen you’ll see is the GRUB menu.

The GRUB boot loader menu

You can either hit “Enter” or wait for the menu to time out. This usually takes about 10 seconds.

The first time you boot your virtual machine you’ll have to provide some information to finalize configuring your virtual Pi.

The Raspberry Pi welcome screen

Click the “Next” button when you see the first setup screen. On the “Set Country” screen use the drop-down menus to select your country, language and timezone settings.

Selecting locale specific settings in the Raspberry Pi configuration process

Click the “Next” button to proceed.

On the “Create User” screen, enter the name of your user and create a password for them.

Creating a user in the Raspberry Pi configuration process

Click the “Next” button to create their user account.

The “Update Software” screen checks your current install against the software repositories to make sure it is up to date. This takes a little while, but I recommend you bite the bullet and sit through it .

Checking for updates in the Raspberry Pi OS

Clicking the “Next” button performs the update checks.

The update complete confirmation message

Click the “OK” button when the updates have completed.

The reboot screen at the completion of the Raspberry pi configuration process

Click the “Restart” button to apply the changes.

Setting the Screen Resolution

When your virtual Raspberry Pi boots, it’ll log your user in, and boot straight into the LXDE desktop. But you’ll probably see that your desktop is a small rectangle in the middle of your screen with a resolution of 800×600.

Setting a more realistic resolution is easy. Click the Raspberry icon in the top left corner.

The Raspberry Pi desktop

From the menus, select “Preferences” > “Screen Configuration.”

The Preferences menu

The “Screen Layout Editor” application will open on your desktop. Right-click on the gray square labeled “virtual1.”

Setting the screen resolution in the Raspberry Pi desktop

From the menus select “Resolution” and then the resolution you’d like to use. You’ll need to reboot for the changes to take effect.

You’re All Set

That’s it. You’re ready to experiment and explore in your virtual Raspberry Pi.

Related: 16 Cool Projects for Your New Raspberry Pi

Source link

By John P.

Leave a Reply

Your email address will not be published. Required fields are marked *