Turning an iPad into a Desktop with a Raspberry Pi
Rationale
Lately I have moved away from using a regular laptop while away from my desktop workstation. My current computing model is to only use an iPad for casual web browsing and media consumption, and a nice big 4k 27 inch workstation when doing real work. The reasons for this are numerous, but basically boil down to the following -
-
Any regular desktop OS is way less secure than iOS. Restricting yourself to using iOS for general web browsing and media consumption dramatically reduces the risk of being compromised.
-
After many years of juggling different projects, I’ve learnt that it pays to keep my computing roles segregated. On a workstation, I achieve this by running various virtual machines - one for data science, one for Botswana work, one for personal tinkering… you get the idea. If I break one machine, it doesn’t break anything else. If I want to find a file, I know which machine it is in. Virtualbox enables snaphots, and I can back up the entire VM directory to an offline hard drive regularly. This segregation model doesn’t work so well when you have a laptop. Because laptops are great for ad-hoc work, they encourage bleeding of these segregated roles.
-
When I’m doing serious work, I’m at a desk, with proper ergonomics, in a focused environment. Laptops encourage poor posture and my work can follow me anywhere! Using an iPad as my exclusive portable computing device severely curtails my propensity to ‘just put in another hour’ in the middle of the night, when I should be relaxing.
This model is working well for me. I find I am much more productive when I am actually working, my posture is better, I’m getting more sleep - it’s been a good lifestyle change.
Anyway, lately my master plan has hit a stumbling block. I’m planning a 6 week backpacking trip to Japan with my family in September and October, and we don’t want to take a laptop. So far so good, we’ll take the iPad. But iPads don’t have lots of space (mine is a 16gb iPad Air). Some bank websites don’t work with iOS (I’m looking at you, FNB Botswana). There is no filesystem for me to back up photos or stash important documents. And heaven help me if I need to put something on a flash disk.
Nevermind. I can set up a Raspberry Pi 3 to act as a mobile desktop pc. Raspbian is a fully fledged OS, so it can overcome all the bottlenecks mentioned above. How do we do it?
What We Will Do
- Install the relevant apps on the iPad for RDP access and FTP consumption of media files and documents
- Set up RDP on the Pi
- Set up the Pi to throw up a WiFi access point at boot
- Use an extra WiFi dongle for the Pi to connect to the internet
- Set up an FTP server on the Pi for document access
So, without further ado, here is how to set up a Raspberry Pi 3, from scratch, to act as a mobile desktop companion for the iPad.
Required hardware:
- A Raspberry Pi 3
- A Micro SD Card with a fresh install of Raspbian. Minimum 8gb. I’ve got a 200gb one in mine so I can put a lot of movies on it. Toddlers don’t travel without The Jungle Book and The Aristocats. TO do it on the cheap, use a small SD card and a big flash disk or connect an external 2.5 inch drive.
- A Wifi Dongle. Any will do.
- Power Supply. The iPad charger works well. Or, for truly mobile, get a power brick that serves up at least 2.4A of power.
- An iPad. Or any tablet at all. Or even your phone.
Installing Required iPad Apps:
This section basically amounts to a list of app recommnedations.
- You can display your Pi desktop on your iPad screen. You need an RDP client: I use Jump Desktop.
- You can stream video and audio from your Pi to your iPad. The simplest way is via an FTP server and VLC on the iPad. Free.
- You can store files in a filesystem on the iPad. I Use Goodreader. Same as above: it can download and read files from FTP servers.
Setting up RDP Access
Everything in this tutorial can be done via command line if you set up SSH access, but I’m doing it via the GUI because it’s easier.
Assuming you have a fresh Raspbian install (google it, lots of tutorials online), and that you have booted up the Pi while connected to a screen, keyboard and mouse.
Connect to Wifi - top right of desktop interface.
Then open up terminal and type -
# Update and upgrade the distro
sudo apt-get update
# Remove Wolfram Engine - optional, I don't need it,
# and removing it frees space and makes upgrade much quicker.
sudo apt-get purge wolfram-engine
# Upgrade the distro
sudo apt-get upgrade -y
# Install RDP
sudo apt-get install xrdp tightvncserver
That’s it! RDP should be set up and enabled on boot.
If your iPad is on the same wifi network as the Pi, get the Pi IP address -
sudo iwconfig
There should be an ip address under wlan0. That’s the Pi IP address. Open up your iPad RDP app, create a new host. Enter the IP address seen above as your host. Username is pi. Password is raspberry.
If it all works, then change the password from the default to something unique. All Pis have the same password out the box, so this is pretty important for security purposes. Just follow the prompts:
passwd
Setting up the WiFi interfaces
This section is a major gotcha. Our goal is to setup the Pi so that (1) whenever it boots up, it presents an ad hoc wifi network that we can connect to and (2) it can connect to the internet itself.
You can actually make the onboard WiFi chip do these two things simultaneously, but the ad-hoc network and the network you are connecting to with the Pi need to be on the same channel, or else weird things start happening. To simplify this technical challenge, we will keep things separate. We will use the on-board chip for the ad-hoc network, and a separate USB WiFi dongle to serve up the network. The on-board chip will be wlan0, and the usb dongle will be wlan1.
So far so good? Ok. Here’s the gotcha. When the Raspberry Pi boots, it assigns the identifier wlan0 to the first chip it encounters. THIS SOMETIMES CHANGES. So we need to tell the Pi to lock down what it calls wlan0 and what it calls wlan1.
Here’s the code, taken from https://www.reddit.com/r/raspberry_pi/comments/2lf8eg/two_wifi_adapters_attached_to_my_pi_they_keep/clu8ab7/
sudo nano /lib/udev/rules.d/75-persistent-net-generator.rules
replace:
KERNEL!="ath*|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
with:
KERNEL!="eth*[0-9]|ath*|wlan*[0-9]|msh*|ra*|sta*|ctc*|lcs*|hsi*", \
Shutdown your Pi, remove the USB dongle you intend to call wlan1. The PI will boot, find ONLY the onoboard chip, and permanently assign it to wlan0.
Once fully booted, plug the dongle back in. The Pi will assign it wlan1 permanently.
You should be able to manually edit the assignments later if you want.
Creating the WiFi Access Point
I’ve taken this from https://hackaday.io/project/10638-raspberry-pi-3-wifi-access-point pretty much word for word and modified it to accommodate our wlan0 and wlan1 configuration.
Install DHCP
sudo apt-get install hostapd isc-dhcp-server
Configure DHCP
sudo nano /etc/dhcp/dhcpd.conf
Place a # in front of the two option domain-name entries and remove the # in front of authoritive
At the end of the file enter -
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8,8.8.4.4;
}
Save and exit.
Edit server to work with wlan0
Sudo nano /etc/default/isc-dhcp-server
Find INTERFACES and change to -
INTERFACES="wlan0"
Save and exit
Set up static ip for wireless
sudo nano /etc/network/interfaces
Edit code after allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
Put # in front of wpa roam after “iface wlan0 inet manual”
Save and exit
Set IP address for wlan0
sudo ifconfig wlan0 192.168.42.1
Create WLAN
sudo nano /etc/hostapd/hostapd.conf
Enter code below. YOu can change ssid and wpa_passphrase to whatever you want.
interface=wlan0
driver=nl80211
ssid=raspberrypi
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Save and exit
Point hostapd to new file
sudo nano /etc/default/hostapd
Find line #DAEMON_CONF="" and edit as such and remove the #
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Save and exit
Set up nat for multiple users
sudo nano /etc/sysctl.conf
Add to bottom of file
net.ipv4.ip_forward=1
Save and exit, then run by entering below
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Set up nat between eth0 and wlan0
sudo iptables –t nat –A POSTROUTING –o wlan1 –j MASQUERADE
sudo iptables –A FORWARD –i wlan1 –o wlan0 –m state --state RELATED,ESTABLISHED –j ACCEPT
sudo iptables –A FORWARD -i wlan0 –o wlan1 –j ACCEPT
Now to have them applied every reboot
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Now go back to interfaces
sudo nano /etc/network/interfaces
Add to the end of the file
up iptables-restore < /etc/iptables.ipv4.nat
Save and exit
Setup daemon to run at boot
sudo service hostapd start
sudo service isc-dhcp-server start
sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable
Test it out
Reboot the Pi. Once it has booted, check available wifi networks with your iPad. Your Pi ssid should appear. Click it, and enter the password when prompted. YOu should connect and get full wifi bars.
Now open up your iPad RDP app. Create a new host.
Under IP address, add 192.168.42.1
Under username, add pi
Under password, enter your new raspberry pi password (remember you changed it with the passwd
command earlier)
Connect. Your RDP app should now present a nice clean desktop of your raspberry pi.
Click the wifi button at the top right of the gui. If you are connected to your home wifi network, great. If not, connect and enter your home wiif password.
Your iPad is now connected to your Raspberry Pi, and your Raspberry Pi is now connected to the internet. You should be able to access the internet from the Raspberry Pi desktop interface, and you should also be able to connect to the internet using regulaer iPad apps.
Setting up an FTP Server
In order to get files between the iPad and the Pi, we need to set up an FTP server.
I’ve taken the following instructions from https://www.raspberrypi.org/documentation/remote-access/ftp.md
On the Pi -
# Install required packages
sudo apt-get install pure-ftpd
# Create an FTP user
sudo groupadd ftpgroup
# Add the FTP user to an FTP group
sudo useradd ftpuser -g ftpgroup -s /sbin/nologin -d /dev/null
# Create an FTP folder
# This is where all media will be stored
sudo mkdir /ftpfiles
# Make sure the FTP user has necessary permissions for the folder
sudo chown -R ftpuser:ftpgroup /ftpfiles
# Create a masked user for the FTP user for login purposes
sudo pure-pw useradd upload -u ftpuser -g ftpgroup -d /ftpfiles -m
# Initialize the FTP daemon
sudo pure-pw mkdb
sudo ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb
sudo service pure-ftpd restart
That’s it! You should have a folder called ftpfiles in the root directory of your pi that presents itself to the world.
If you want to put files in this folder directly from the pi, don’t drag them directly in. Rather, open the file browser, type in ftp://localhost to the top search bar. You should get a pasword prompt (user: upload, password: whatever you entered earlier) and then you should be granted access.
Drag files form anywhere else on the pi into that folder.
Any device connected to the same network as the pi should be able to connect to the FTP server, so don’t put mission critical files in there permanently.
To connect to the FTP server from the iPad, use VLC or Goodreader, and follwo the prompts to connect to an FTP server. If you are connected to the Pi WiFi AP, the IP address is 192.168.42.1, and the username is upload. The password is whatever you set it to be earlier.
End!
You should now have a tiny box that you can throw in your bag and boot up whenever you want to use a fully-fledged desktop while out and about with your iPad.
You can also let anyone else connect to is if you want - just like you would do with WiFi tethering on your smartphone.
Hope it all worked for you first time!