Monthly Archives: December 2015

Connecting from Mac to Raspberry Pi’s remote desktop using X11

I play a lot with my Raspberry Pi PC. Usually I connect using Mac’s Terminal application via ssh to the Pi.

Sometimes though, I need to use the Pi’s full graphical desktop. For example I’m much more comfortable partitioning disks using gparted vs. any other command line tool.

So for those occasions I use an X11 window to connect from the Mac to the Pi, I use ssh to connect, and then run lxsession as the desktop on the Pi.

First, install X11 from XQuartz (

Download the installer package disk image from the homepage. Open the disk image and run the installer package. The installation will take a few minutes and towards the end it will say there’s 1 minute left for quite a while ūüôā

Once the installation is complete you must log out and log back in. If you don’t, the remote desktop won’t open. XQuartz is installed to Applications -> Utilities

Second, launch XQuartz then open XQuartz’s Terminal application (XQuartz menu -> Applications -> Terminal).

Third, connect to the Pi using ssh inside the XQuart’z Terminal. Then Enter ssh -X user@pi (replace user with your username on Pi, and pi with the name of your Pi).

Fourth, launch the Pi’s desktop. Enter lxsession. The Pi’s desktop should now be running on the Mac’s desktop.

Cloning/Backing Up Raspberry Pi using a Mac

This grew out of the need to create multiple SD card Raspbian images for my Raspberry Pi Hadoop cluster. I was constantly experimenting and really wanted not to create the Raspbian OS from scratch every time (note that Raspbian OS is really Linux of the Debian variant).

I sought about how to create an image file of a Raspbian installation so I could flash the image to an SD card when I needed a fresh Raspbian OS installed.

A running Raspbian OS installation configured as necessary is required.That installation’s SD card is used to create the image and clones.

Cloning doesn’t really save time, the time taken to write the image a scratch SD card is the same as writing the clone image, but it saves on errors from human forgetfulness and typing. It also makes the base configuration easy as Pi (LOL), known and fixed.

First thing to know is the size of the source SD card matters. The disk image can only be flashed to an SD card of the same or larger size. I chose 16GB size as they are readily available for a reasonable price.

First, I use Mac’s Disk Utility tool. Applications -> Utility->¬†Disk Utility app.

Second, I insert the micro SD card with a Raspbian OS installation into the micro SD card reader and then insert the reader in the¬†Mac’s USB port. A¬†new disk shows up in Disk Utility.

Third, I click on the disk and then click on the “New Image” item on the menu bar on top, choosing “DVD/CD Master”as the Image Format and click “Create”. I use cloneimage.cdr as the filename, this will actually create an .ISO file, it will create the image file to be used later to clone an installation.

Whenever I need a new Raspbian installation I do the following.

First, I insert a new micro SD card in the card reader and insert the reader in your Mac’s USB port.

Second, I launch the Terminal utility application from Applications -> Utility. I enter “diskutil list” and make note of the disk name, this would be in the form of /dev/diskN where N is a number. I typically find the right disk by looking at the SIZE column and find my 16GB card that way.

Third, I unmount the disk using: “diskutil unmountdisk /dev/diskN”

Forth, this step overwrites the card in the reader. WARNING: this step will not pause for confirmation. If the wrong disk is specified, that disk will be overwritten, so I’m very careful and double check. Enter: “sudo dd if=cloneimage.cdr of=/dev/rdiskN bs=10m”

Fifth, well, I wait until the image has finished writing, there is no ongoing progress status output but pressing Ctl-T will print some status information.

About the only indication is the app finishes running and the console prompt shows again.

That’s it, the only way to know is to boot up the new Pi with the new card.

Cleanup,¬†I usually clean up the new Pi by changing the hostname, if I picked an installation with a static IP address then I’ll update the static IP address.¬†Depending on the installation, sometimes I also change users and passwords.