aoakley.com

RetroPie and Raspberry Pi PIXEL Desktop

Skip to: How and why does this work? - an explanation of Linux TTY consoles

In Linux, there's always more than one way to do it. RetroPie is a wonderful set of scripts and skins for EmulationStation, a collection of retro computer and video game emulators. By far the easiest way of running RetroPie is to flash their ready-made image to a memory card, but what if you want to have both RetroPie and Raspbian Pixel on the same card? Well, NOOBS and BerryBoot will both support multiple operating system partitions on a single card.

I don't want that. I want to have a RetroPie icon in my PIXEL menu under "Games".

What I wanted to achieve, was to have a single Raspbian operating system running from a single partition (plus /boot) and be able to boot to the PIXEL desktop, then be able to run RetroPie as if it were any other desktop application. And that's where it gets complicated, because RetroPie is not a desktop application.

If you like this and want to say thanks, donate to Cotswold Raspberry Jam, the computing club aimed at children that I run in Gloucestershire. You can find out more about Cotswold Jam here.

Install RetroPie alongside Raspbian PIXEL

You will need to manually install RetroPie as it doesn't come with Raspbian PIXEL by default.

From a terminal on Raspbian PIXEL, follow these instructions to manually install RetroPie:

RetroPie Manual Installation

My Solution

Important: The PIXEL desktop will be stopped and any work you haven't saved will be lost. I recommend you close all your desktop programs/windows yourself before you run RetroPie using my method. We'll start the desktop again when we're finished with RetroPie.

The manual method

Now you've got RetroPie installed alongside Raspbian PIXEL, you'll need a way of starting RetroPie. A way to do this manually is:

What we're going to do now, is to automate that manual process as a desktop menu item. My solution is to stop the desktop, run RetroPie without the desktop, and then start the desktop again once RetroPie is finished. Yup, I'm cheating. We're not really running RetroPie from the desktop, we're just finding a way to start it from the desktop - and then temporarily getting rid of the desktop!

To implement my solution, you need two files:

1. ttyecho

ttyecho is a program that pretends to type into the Linux console. This isn't included by default in Raspbian, so you'll need to download it. You have a few options:

In both the above cases, you should move the file to /usr/local/sbin , chown root.root and chmod 755 . Alternatively you can copy and paste this all-on-one-line incantation into the terminal, which will download it, move it to the right place and set the ownership and permissions:

curl -O "http://aoakley.com/articles/artifacts/retropie-pixel/ttyecho" && sudo mv ttyecho /usr/local/sbin && sudo chmod 755 /usr/local/sbin/ttyecho && sudo chown root.root /usr/local/sbin/ttyecho

2. retropie.desktop

A .desktop file is a file that tells the PIXEL menu (and other Linux desktop menus) about an item in the menu. It typically includes an icon, a name, what command to run, and often a description. The .desktop files go inside the /usr/share/applications/ folder.

Here's what's needed inside retropie.desktop:

[Desktop Entry]
Type=Application
Name=RetroPie
Comment=Retro video game emulators
Exec=sudo su -c "systemctl stop lightdm ; ttyecho -n /dev/tty1 \"emulationstation ; sudo systemctl start lightdm\""
Icon=face-smile-big
Terminal=false
Categories=Application;Game;

If you want to download it, you can:

then move the file to /usr/share/applications , chown root.root and chmod 755 .

Alternatively, copy & paste into a terminal, this all-on-one-line incantation to download, move and set ownership & permissions:

curl -O "http://aoakley.com/articles/artifacts/retropie-pixel/retropie.desktop" && sudo mv retropie.desktop /usr/share/applications && sudo chmod 644 /usr/share/applications/retropie.desktop && sudo chown root.root /usr/share/applications/retropie.desktop

My solution relies on Raspbian having automatically logged in the Pi user on the first console. If you've modified your system to prevent auto login (for example, using raspi-config) then you will need to edit retropie.desktop to log in, by adding a couple of extra ttyecho commands after stop lightdm ; and also to exit the console session after use.

Exec=sudo su -c "systemctl stop lightdm ; ttyecho -n /dev/tty1 \"pi\" ; ttyecho -n /dev/tty1 \"raspberry\" ; ttyecho -n /dev/tty1 \"emulationstation ; sudo systemctl start lightdm ; exit\""

Obviously if you've changed the password (or the username), you'll need to adapt the script appropriately.

Starting and stopping RetroPie from the desktop

Once you've restarted your Raspberry Pi (or at least restarted the desktop with sudo systemctl restart lightdm ) then you should find a new smiley-faced RetroPie icon under the Raspberry menu - Games - RetroPie.

How and why does this work?

RetroPie, and many (but not all) of its emulators, expect to be in sole charge of the "console". In the context of multi-user computer systems, "console" means the monitor, keyboard and mouse which is directly attached to your computer. Raspbian, like almost all variants of GNU/Linux, are multi-user systems, and are designed so they can be connected to by several users at once, for example over the internet. However they assume, more or less, that there is only ever one user actually sitting at the monitor, mouse and keyboard.

Linux, including Raspbian, Debian, RedHat, Ubuntu, Mint and others, is usually configured to have four to six text consoles (usually at least four) and between two and six graphical consoles (usually at least two).

You can switch between these consoles with the following CTRL+ALT key combinations (by which I mean, hold down the CTRL key, also hold down the ALT key, then press the nominated F-number key):

Some Linux systems use CTRL+ALT+F9, F10, F11 and F12 for different purposes. F7 and F8 are usually reserved for graphical consoles for desktop versions of Linux.

Give it a try - if you get lost, use CTRL+ALT+F7 to return to the desktop.

TTY and the Framebuffer

Why "tty"? Well, it's an abbreviation of "teletype". Multics and Unix systems, upon which Linux is based, date back to the 1960s when it was common to use typewriter keyboards and printers instead of monitors. These were standard components of telegraph, telex and teleprinter systems that predated monitors. Multics, the precursor of Unix, was quite unusual for the time, in that it allowed more than one program to run at the same time - for example more than one user with more than one teletype terminal. Hence "Multiplexed" Information and Computing Service - multi, more than one. Unix was written in the 1970s to do a similar job, by students who gave it a rude-sounding name as a joke.

The separation between text and graphics consoles is arbritary, simply a common convention; you can run a graphical desktop from console 1-6 if you insist, and you can run a terminal session from consoles 7 upwards. But most systems don't.

It's worth mentioning that you can also run graphics from what we call the text consoles - but those tend to be full-screen applications, usually quite old programs or single-purpose programs such as signage slideshow. This is called the "framebuffer" and it is quite a different way of doing graphics than the X-Windows desktop.

Guess what? RetroPie mostly uses the framebuffer.

Helping RetroPie take control of TTY1

RetroPie expects to run from the first text console. It will get extremely confused if you try to run it as a desktop application - some bits will work, but most won't.

It's quite difficult for another program to take control of the first text console, especially as the Raspbian operating system, by default, logs the user into a terminal session on the first text console. That's where the ttyecho program comes in, by typing stuff into the console on the user's behalf.

What my solution does, is:

Public Domain - Andrew Oakley - 2016-12-21

Top - More Computing Articles - Article Index - aoakley.com