Monday, January 25

Upgrade your old laptop with a Raspberry Pi

Have you ever wondered what to do with that old laptop you kept for so long because you never had the heart to trough it away?

Plug a Raspberry Pi2 into your old laptop and give it a second life! Also wouldn't it be great to get your Pi around the house with a very portable setup? I know you get a Pi-Top (I'll admit it's cool but $269.99 without the Pi!!!), you can get a Touchscreen even the original from the Pi Foundation, but the recycler in me sometimes screams for justice.

This setup I am using costs near to nothing and gets the dust off those useless laptops in the loft.

The idea is pretty easy; we get a Pi, plug it in two USB ports of the laptop via a Y cable, connect it via the Ethernet port to the NIC of the laptop, VNC into the Pi, configure the Wi-Fi and job done.

Fix the Pi on the back of your laptop's screen with whatever you can think of and enjoy a Pi with no dangling cables but with a nice keyboard, video and mouse setup.

I made sure that the steps to follow are as simple as possible and that the configuration should work in the majority of situations. By all means this can be further improved and I'll be glad to hear from anybody who might have suggestions.

The configuration and setup can be replicated pretty much on any laptop you might have, even a new one!

Hardware requirements

The requirements for the laptop are:
2 USB ports
1 NIC ethernet
1 Working keyboard and 1 Working Touchpad/Mouse :)
1 Working Screen :))

Mine is quite old as you can see

The Pi needs a Y USB cable with the usual micro connector on the other side. This StarTech 1 feet USB Y Cable for External Hard Drive - Dual USB A to Micro B can do just the job.
A short (20-30 cm) Ethernet cable CAT5e would be more than enough.
Finally a compatible Wi-Fi card.

This is essentially it from the HW point of view. The reason for the Y cable is to make sure that the Pi receives enough current to power itself correctly. Each USB ports in USB1/2 delivers a maximum of 500mA so if you have a laptop of that era you certainly need the Y cable.
The Ethernet cable doesn't need to be a cross-over although that wouldn't hurt if it is. The Pi is capable of Auto MDI-X and will be able to adjust to a straight or a crossover cable directly connected to the laptop; no Ethernet HUB/SWITCH required.

Software configuration

Software wise the Pi will come with its usual distro Raspbian and the Laptop in my case is Elementary Linux. Different combinations of distros should certainly work but might require adjustments compared to what I am showing here.

The quickest A quick way to have the best "Plug & Play" experience is to configure the laptop to work as a DHCP for the Pi, this will ensure that the Pi can just come out of a freshly burned SD card (If you use NOOBS you need to install an OS first) with no need for any configuration only requiring to only install VNC server on your Pi but with no need to configure its networking.

Most NetworkManager distributions should allow for "internet connection sharing" for each network cards. This allows for the laptop to use a service called Dnsmasq to provide automatic configuration of networking parameters for the guests, in our case the Pi. Great!
This is how I configured my laptop:

Once the "internet configuration sharing" is setup our Pi can be plugged in in the USB ports of the laptop and hooked to the Ethernet cable.
After a while we should have an IP for the PI but we are not going to know which is going to be that easily. Luckily both Rasbian and Elementary (Linux in general does) support something called mDNS out of the box. mDNS is for DNS what Link-local address is for IP (you know those 169.254.x.y addresses?) and it allows for DNS names to be setup "democratically" amongst computers in the same network. Raspbian sets its name as


and once it gets an IP you should be able to ping raspberrypi.local without knowing the IP, excellent!
If you can ping it, you can SSH to it and that's the next thing to do.

We SSH to the Pi and start the VNC server (of course there will be a one off password to setup, keep it simple and use the Pi user password).

The server should be started with the same resolution of your laptop screen as we want to run the Pi in full screen on the laptop. The command to run on the Pi will be something like:

vncserver -geometry 1280x800 

or whichever is the resolution of your laptop, I hope you know how to find it :)

We now have a VNC server to connect to, note that it runs on screen :1 but don't try yet to get on the Pi until you have done the steps below otherwise you won't be able to use F8 to close the session as the keyboard might not work.

One thing you may find in fact is that once in fullscreen the keyboard is not working on the remote session. To fix this I had to edit /etc/X11/app-defaults/Vncviewer as sudo

sudo nano /etc/X11/app-defaults/Vncviewer

This is distribution dependant and you might have to look elsewhere for this file depending on what you run on the laptop.

The line that we are uncommenting is:

Vncviewer.grabKeyboard: true

on the laptop we should now be able to VNC safely to the Pi. The command I am using is:

xtightvncviewer raspberrypi.local:1 -fullscreen -compresslevel 3

we are connecting on host raspberrypi.local on screen 1 in fullscreen and compress the session to get better performance. I made a script just not to have to type that all the time.

You can play with compresslevel from 0 to 9 where 9 is less compressed. The network should not be the bottleneck as it is a dedicated fast-ethernet connection but the video card on you old laptop might be the one not actually able to keep up.

If the command above succeeds you should be prompted for the VNC server password you set earlier on and after that you should finally be in your Pi's desktop!!

We are not done yet unfortunately, a few more tweaks.

The first thing to do on the Pi is to configure the eth0 card as static IP.

The reason is still within the realm of keeping things as simple as possible. You remember that Dnsmasq you mentioned earlier? Well as a good DHCP it will keep on refreshing periodically the information of the Pi's Ethernet adapter not only with IP and Mask but also with Gateway, DNS and default route. Now, after we will enable the Wi-Fi card on the Pi we'll want for the default route and the DNS server to be only the ones of the Wireless card not the ones configured from the DHCP server on the laptop. This will ensure that the Pi will be able to connect to the internet only through its Wi-Fi card.
The best thing to do is to configure the IP address of the Pi's eth0 as the one it used to receive from the DHCP's laptop and

uncheck "Automatically configure empty options"

leaving the Router and DNS sections empty.

Note that this will configure the network mask of the Pi as whilst the laptop interface will have a mask of This is not going to cause any problems although it is quite an horrible thing to live with if you have done any serious networking in your life!

Next we need to edit:

sudo nano /etc/resolv.conf

on the Pi to remove the settings obtained from the laptop. We need to remove the line that says:


or whichever is the IP of your laptop
it should look like this:

Lastly we need to remove the default route associated with the laptop's address, in my case:

sudo route del -net gw

so that the routes will look like this:

At this point we'll need to configure the Wi-Fi connection on the Pi in the standard way and we should be done!!!

After these steps connecting again should be just a question of powering up the laptop, starting the VNC server on the Pi (which can of course be set to start automatically) and VNC into the Pi.

What is left to do

A lot more automation can be done. When the laptop shuts down for example we should be able to also run a clean shutdown and wait for the Pi to be off before shutting down the laptop. The VNC session could also be run automatically at the startup of the laptop including passing the password for the Pi. The initial configuration of things for both the Pi and the laptop could be scripted to make things easy even for the less expert.
Finally get a better networking configuration, I hate that thing about the network mask!!

Also some good designer cloud come up with maybe a 3D printed enclosure or VESA fix like structure that can be adjusted to most laptop screens. It'll be nice to find a way to accommodate a breadboard too although having it always fixed on the back of the screen might not be ideal.

I leave it here I guess but this is clearly far from being something to "resell".


If your laptop comes with a Wi-Fi interface then you could use that to connect the Pi to the internet in a much more traditional ICS configuration. This hides the Pi behind a NAT and for the majority won't be a problem and work great, I preferred to use the laptop just as a KVM though.

I must admit that I have tried to find out whether the Pi supports Link-local address which would have made things less complicated but I couldn't find much about this and eventually opted for the more cumbersome "internet connection sharing" approach.


In the long run having to type a password for the laptop and one for the Pi can be tedious so my advice is to at least enable autologin on the laptop and disable the password prompt when exiting the screensaver

06-02-16 - UPDATE

Link-Local Address

Since I wrote this article I made a bit more research into the matter of Link-Local Address and specifically with regard to the support of this in Raspbian. It turns out that the Pi is more than capable of supporting IP auto configuration and this is in fact the quickest way to go about configuring the Pi in tailless mode (I like calling it this way!).
By configuring the laptop Ethernet interface as Link-Local only the adapter will get a 169.254.x.y address and will be immediately ready to resolve raspberrypi.local.

No comments: