Unless I’m messing about with a legacy desktop or low-cost digital signage I generally connect to my Raspberry Pi from my PC or laptop using a USB console cable.
Powering the Raspberry Pi from the USB port keeps the number of cables to a minimum and means you don’t need a separate power supply, all I have to do is plug the USB console cable into my computer or laptop and the Raspberry Pi will start to boot. If I need to I can still install XFCE or MATE and connect to the desktop remotely over the network using XDMCP or VNC.
To accommodate the serial cable I used a fine file to cut a narrow slot about 1.5-2 mm wide in layer 4 of my Pibow Ninja case. When in place the heat shrink on the end of the cable acts as a strain relief collar and prevents the serial cable from being pulled out. Start out by making the slot a little narrower than you need and widen it with the file until it is just right.
Obviously if you want to use the serial cable in conjunction with a HAT then some ingenuity and a soldering iron may be needed! When installed the red and black cables provide power and the green and white cables are for the serial console.
Note – Make sure you use a cable that is compatible with the Raspberry Pi, the Raspberry Pi may use 5v for power but any more than 3.3v on the serial port will damage it.
Having removed the need for a separate display, keyboard or mouse the next problem is how to do a minimal installation using just the serial console. Fortunately there is an unattended installer available, don’t be put off by the complex looking github page it isn’t that hard, all you need to do is download the compressed installer image from the downloads section at the bottom of the page.
If you are already using a linix machine you can do this using the following commands.
Or you can just click on this link. Then you just need to uncompress it.
The uncompressed image file should be about 64M bytes, next we need to transfer this image into an SD card.
Writing the image
After inserting your SD card you can use this script to help identify which device it is.
On my system my SD card is ‘/dev/sde’ – you will need to change this to match your system when entering the commands below.
Note – The existing contents of the SD card will be overwritten!
We need to be logged in as a super user.
Then we need to make sure that there are no mounted partitions on the SD card. To do this I have used ‘mount’ to list all the mounted partitions and combined this with ‘grep’ to filter the results before using ‘cut’ to remove everything but the first space delimited field so only the names of the mounted partitions on the SD card are shown (on my machine the SD card is ‘/dev/sde’ but it may be a different device on your system).
If as in this example there are mounted partitions on the SD card then we need to unmount each of them in turn using ‘umount’.
Then we are ready copy the image file to our SD card.
Before removing the card you need to make sure that all the data has been written from memory to the device.
Then remove the SD card and reinsert it – if you are using a graphical desktop it will be mounted automatically so we need to unmount it and remount it for the commands that follow to work.
Configuring the installer
In order to use the serial interface we need to make some changes to the existing configuration file, and create a new file containing the installation options we want to use.
Start by editing the ‘cmdline.txt’ file to configure the console to use the serial interface during the installation – on my system the serial interface defaults to 9600 baud so I also need to reduce the baud rate to match.
Then you need to configure the installer by creating a new file called ‘installer-config.txt’.
Note – It is best to type this filename in by hand as when pasting text from a web page the hyphen may look the same but actually be a different character from the one on your keyboard (if the installer ignores the installation options check the file name first, it would have saved me hours trying to get this to work the first time if I has spotted that sooner!)
Note – Remember to change the hostame and root password entries above.
If you don’t specify which release to use the installer will default to the older ‘wheezy’ release and if you want to use all the free space on the SD card you don’t have to specify the root size, however I use 1918M as this means that the resulting system image will fit on a 2GB card and on a larger card you can use the remaining space to create a separate ‘home’ partition later. Lastly, if you don’t want ti use the newer journalling ‘ext4’ filesystem you can change this to ext2.
You can then unmount the SD card, eject it and insert in your Raspberry Pi.
Note – Make sure your Raspberry PI is NOT powered on when you insert or remove the SD card.
The installer is designed to work unattended so you can just plug your Raspberry Pi console cable into you serial port and let it get on with it – but I like to monitor what is happening in a console window.
If you just plug in the USB cable then open a console window and connect to the USB serial port then by the time you are connected you will have missed initial output completely. To overcome this problem I use this script and desktop shortcut to open a console window and then wait while I plug in the USB cable.
If the installer hangs at this point you have probably just forgotten to connect the network cable. When you connect the network the installer will continue.
The installation will take about 15 to 20 minutes or so depending on the speed of your internet connection, SD card and model of Raspberry Pi and at the end your Raspberry Pi will automatically reboot, ready for you to use.
Since the installation leaves the ‘installer-config.txt’ file in the boot partition (which contains the root password) you may want to delete it after logging in for the first time!
This minimal installation makes a great starting point for a number of projects, but you will probably want to modify the configuration and then to install some additional packages to get a more functional system.
You will probably want to begin by creating a separate home partition if you have not already used all the space available on your SD card. Then if you want a graphical desktop then the next step is probably to install either MATE or XFCE. Alternatively you could configure NFS and turn the system into a file server.
Of course all this would be impossible without the work done by Diederik de Haas so I’d like to finish by just saying a big ‘Thank You’ to him for all his hard work.
Raspberry Pi is a trademark of the Raspberry Pi Foundation