Raspberry Pi Headless Or Remote OS Reinstall

RAsberry Pi NOOBS in VNC viewer.

Raspberry Pi NOOBS in VNC viewer.

The Raspberry Pi series of credit card sized computer boards comes with a full-sized HDMI output interface. It’s pretty great and with the built-in GPU hardware acceleration it works very well, even when playing 1080p video content.

But, there are endless cases where you might choose to run the Raspberry Pi as a “headless” server. This means running without any kind of monitor attached to the Pi and, for that matter usually no keyboard or mouse either.

Once Raspbian is installed, running your Pi headless is no problem at all. Any interaction that you need to perform on it can be done via an SSH session from another computer with monitor, keyboard, and maybe even a mouse. That’s great! Right up to the point that you decide that you need to re-install Raspbian or you want to install one of the other OS options. At that point, you need to connect an HDMI display to your Pi and a keyboard etc. Alternatively, you may prefer to pull the micro SD card and re-image it from another computer, but there may be an easier way.

The Raspbery Pi developers have thoughtfully provided an option that will allow you to install or reinstall your OS using their NOOBS installer utility. Unfortunately, they don’t seem to talk(document) about it much. But, if NOOBS was used to install your OS, then you can easily access your Pi and install or reinstall your OS remotely on a headless Pi.

To accomplish this you’ll need to make a simple edit of a text file in the NOOBS partition and then connect to the Pi with a VNC viewer application. The first step will be to gain access to your NOOBS partition from the Pi command line in order to edit the necessary file. This might be old hat to Linux veterans, but the NetCodger will go through the motions anyway, beginning right after you’ve logged into the Pi via SSH.

You need to create a directory to serve as a mount point for the NOOBS partition.

pi@raspberrypi ~ $ mkdir n00bs

Next we mount the partition.

pi@raspberrypi ~ $ sudo mount /dev/mmcblk0p1 n00bs/

Next we alter the file.

pi@raspberrypi ~ $ sudo nano n00bs/recovery.cmdline

Inside the recovery.cmdline file we append the command line to look like this.

quiet vt.cur_default=1 elevator=deadline vncinstall forcetrigger

Notice the vncinstall keyword. This starts a VNC server when the N00bs utility is booted. The forcetrigger keyword forces the Pi to boot to the NOOBS utility on the next boot, rather than back into Raspbian. This is similar to holding the Shift key, on a keyboard attached to the Pi, while it initially boots.

At this point you’re done. Save the recovery.cmdline file and reboot with the sudo reboot command. Your Pi will then boot up into the NOOBS utility and have a VNC server running. Use your preferred VNC viewer and connect to your Pi’s IP address for a nice graphical OS installer/reinstaller.

After N00bs has finished and you click the final OK button, NOOBS will boot your Pi into the newly installed OS(Raspbian). This will end your VNC session. You must now connect to your Pi again via SSH to the newly installed OS and you should probably run the Pi’s initial configuration utility sudo raspi-config to set your internationalization settings and timezone.

But, you’re not done yet. Your NOOBS configuration has not changed back and if you restart your Raspberry Pi now, you will be booted back into the NOOBS utility to begin the install process all over again. If this happens to you, simply reconnect via your VNC viewer and click the Exit icon. But to prevent this form happening again, you must remove the changes that you previously made, from the recovery.cmdline file.

pi@raspberrypi ~ $ mkdir n00bs
pi@raspberrypi ~ $ sudo mount /dev/mmcblk0p1 n00bs/
pi@raspberrypi ~ $ sudo nano n00bs/recovery.cmdline

For ease of use in the future, so that the NetCodger doesn’t have to look up the commands, he leaves them in the file but on a separate line, as follows.

quiet vt.cur_default=1 elevator=deadline 

vncinstall forcetrigger

The second line is ignored at boot and your Pi will boot into the normal OS without issue.

Save the file and dismount the partition.

pi@raspberrypi ~ $ sudo umount n00bs/

And you’re done!

Advertisements

About Net Codger
A long-time Information Technology(IT) person who has been made to feel old beyond their years by the merciless and relentless assault from IT vendors and the clueless user community.

5 Responses to Raspberry Pi Headless Or Remote OS Reinstall

  1. Greg Minshall says:

    hi. thanks. let’s say i’m not using VNC, but rather would like to ssh in to the RPi and run the NOOBS installer over ssh’s X11 forwarding. any idea how i would *launch* (from the command line) the NOOBS installer? cheers!

  2. Liviu Stancu says:

    What if I have a dual boot setup and I don’t want to reinstall or add any new os, I just want to be able to connect with vnc to the os selector menu. It seems that adding only the vncinstall is not working: the system is booting to the last used os, and only after that I can connect with vnc.

  3. K says:

    Thanks for the writeup. A note on os x – The builtin os x vnc client prompts for a password when connecting. I could not find away around this. I ended up connecting from a Windows host using the TightVNC client, and ran the operation successfully.

  4. Mike says:

    The latest version of Raspbian sets both VNC and SSH to Disabled by default, so this actually doesn’t work anymore. Once you’ve reinstalled from n00bs and reboot into the OS you can no longer SSH in to turn on VNC, without connecting directly to the machine. Unless I’m missing something…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: