≡ Menu

Tricks With Raspberry Pi OS

Raspberry Pi logo

So, you’re working on a Raspberry Pi project (what’s that?) neat, eh? I’m working on one too. Here’s a simple trick: you don’t actually have to have the Raspberry Pi at all, or use the old slow one you have around to develop on.

Instead, run it in a Virtual Machine on your computer! My main platform is an Apple MacBook Pro (intel – running OSX 12.6.6 at the time of this writing) but everything here can also be done in your favorite flavor of Windows or Linux. Advantages over a physical rPi:

  • You don’t have to have the Raspberry Pi setup and running and on your network. It’s on your laptop and now you can get to it everywhere you go.
  • You can use as much of the power of your host computer in the rPi vm as you’d like. That way later you can deploy to a much slower (cough: “cheaper”) rPi without having to deal with performance issues in the meantime.
  • If you want to make a complete backup of your rPi project, at any time you can just make a copy of the vm. Easy-peasy lemon-squeezy.

You can run virtual machines on your computer for free using VirtualBox. I prefer to use Parallels Desktop because it provides excellent integration between Windows and OSX and other features I find handy.

Below you will find instructions on nifty ways to get this setup.
I hope you will find them useful.

These instructions are for Parallels. You can find a tutorial on VirtualBox rPi vm here.

Step 1: Get the Raspberry Pi OS as a .iso file. Go here: https://www.raspberrypi.com/software/raspberry-pi-desktop/. (Note: These instructions are for Apple Intel CPU machines. I don’t have an Apple-produced CPU machine to test on. Later I will add instructions for MS Windows.)

Step 2: In Parallels, create a new virtual machine using that .iso file you downloaded. If you’re customizing stuff on an rPi, you should be able to walk yourself through the menu choices the installer presents. If not, well Grasshopper, it is time for you to learn. It is left as an exercise for the reader.

To take things another step further, if you stay with the Mac GUI, cut and paste works everywhere just the way you like it. So, what I like to do is browse tutorials and instructions on the Mac side, and paste commands into a terminal window that’s connected to the rPi. Here’s how you set that up.

Step 3: Once you’ve got the rPi vm up and running, you’ll need to enable SSH. Easy enough. In the rPi, click the raspberry icon in the upper left, preferences, Raspberry Pi Configuration. Click the Interfaces tab and you’ll see a slider to turn SSH connections on. Do that. On your Mac, make sure you can SSH to the vm. In a terminal window you’ll want to do this:

ssh -l your_rPi_username

You’ll put your username in that command, and replace that series of numbers with the IP address of your vm, which in Parallels you can find in the Parallels menu by looking under Devices -> Network. If this is your first time connecting, you’ll be asked if you want to continue and the answer is “yes”. If you now have a command prompt for your vm in your terminal window, SSH is working!

Now let’s take it a step further. In Parallels you’ve got the rPi desktop, everything running inside that window. However, cutting and pasting text between the Mac and the vm isn’t so great, but we can improve that by launching browser windows that display inside the Mac GUI that accept cut and paste between windows better. Here’s how to do it.

Step 4: We’re going to make use of what’s called The X Window System. You could spend a couple of decades reading about it, but we’ll skip to the chase. You’ll need a piece of software on your Mac to display the windows from the rPi vm. At the time of this writing, a good option for that on OSX is XQuartz. You can download it here: https://www.xquartz.org.

Step 5: When you start XQuartz on your Mac, it will bring up a fresh terminal window known as an Xterm. Inside this Xterm, try this command:

ssh -X username@rPi_ip_address mousepad

You’ll put in your rPi username and your rPi IP address in that command. When you hit return you’ll be asked for your password, and a moment later you’ll have the Mousepad window show up. Clever! Mousepad is running on your rPi, but displaying on your Mac. This can be done for many rPi applications, like so:

ssh -X sbp@ chromium

On my setup, this opens up a Chrome (on Linux “Chromium”) browser window that’s running on the rPi, but displaying on the Mac. Try it out and see what you can make it do! As you might imagine when computers are involved, there’s a few catches:

  1. You’ll notice that the command prompt doesn’t come back on in your Xterm until you close the app you’ve opened. If you want more apps, just do a cmd-n in XQuartz to open a new Xterm.
  2. If you’ve got Chromium running inside your rPi vm and you give the above command, the new window will open up inside the vm window, not in the Mac GUI. So, watch out for that.
  3. Depending on your setup, you may need to replace “chromium” in the above command with “chromium-browser”. Also you can start other apps like mousepad this way.
  4. Inside XQuartz the clipboard is shared with the Mac GUI, which means if you copy something out of Microsoft Word with a cmd-c, it’s available to be pasted to any app in XQuartz – but (because computers have to be complicated) on the vm side you’ll need to use the control key instead of the command key. So Paste is control-v. Not as convenient as it could be, but improved over other approaches.
  5. Would you like to start X apps without having to type your password every time? It is not so simple to do, but here are instructions for getting that set up.
  6. Yes, this same technique can be used with a hardware rPi on your network, and may come in very handy as it’s a lot less resource intensive to run a single app in a window than for the rPi to run a whole desktop and display it via VNC.
  7. And of course, you’ll be hard pressed to find a *nix-based system that can’t do this, though the procedure differs based on all the particulars. If you’re the kind of person who has a reason to set this up, I bet you’ll get it figured out.

Stay tuned for more tips!