Skip to content

Remote installation of PINN

procount edited this page May 5, 2023 · 9 revisions

D R A F T version

Overview

This page explains how PINN can be installed to a remote Raspberry Pi that is only accessible over a network. No keyboard, mouse, screen or physical access to the SD card is necessary.

Why do it

This allows PINN to be installed remotely when the SD card is not physically accessible. PINN can be used as a recovery partition to install other OSes, or to upgrade or replace an existing installation. The SD card will be repartitioned and reformatted for PINN, so anything important needs to be backed up first.

Requirements

  • The RPi must be accessible via SSH
  • It must be able to access the internet
  • It must have a writable boot partition > 64MB in size.
  • Optional attached USB drive (if you need to backup/transfer anything from the old OS to the new OS.)

Caution

Please read all of these instructions thoroughly before using to ensure you have all the necessary tools to complete the task. As this is all being done remotely you need to make sure all the steps complete successfully to avoid losing connectivity to your remote system. You may want to practice on a local Pi first to make sure the steps work before deploying remotely. The process below is not secure as it uses well known logins/password. It is possible to secure the network connection by using passwordless SSH. Instructions can be found in README_pinn.md but are not included here. They may be added a later date.

Process

  • In preparation for installing the new Raspberry OS headlessly, a userconf file should be generated with a username and password. At an appropriate linux command prompt:

echo 'pi:'>userconf;echo 'raspberry' | openssl passwd -6 -stdin>>userconf

You are advised to choose a different username/password. If you don't have a suitable installation to create this you can copy the following to userconf:

pi:$6$NIA.rG1axw8pDRt2$tcsWMTfeVIJuPXJXGnc9a9YVM8o/GIOaK1m77nVGGOUARhBCZLmbTDQXlVeXosuPOQfpDN/crmcRDVP3u8TaL.

Copy userconf to the home directory of your RPi.

  • If anything needs backing up or transferring from the old OS, this first needs to be copied off to the attached USB drive, or maybe to a network share
  • Download pinn-lite.zip to the SSD.
cd ~
wget http://downloads.sourceforge.net/project/pinn/pinn-lite.zip
  • Delete contents of boot partition. Deleting the boot partition means the RPi will no longer boot until PINN is installed on the drive, so this is the beginning of a dangerous period. The remaining OS will continue running without the boot partition temporarily until the next reboot.
cd /boot
sudo rm -rf *
  • Unzip pinn-lite.zip to the boot partition.

unzip ~/pinn-lite.zip

  • Setup any network configurations

As this is a remote installation, it is important that PINN can connect to the network straight away so that connectivity can be maintained. DHCP Ethernet connections should work straight away and connect using the same IP address. If you need to connect to a wifi access point, require a static ip address or other DHCP requirements, then copy your wpa_supplicant.conf and/or dhcpcd.conf files to the boot partition where PINN is now located.

  • Edit recovery.cmdline
nano recovery.cmdline

This file is equivalent to cmdline.txt in Raspberry Pi OS. Only the first line of text in this file is read. Add the following (without quotes) to the end of the single line of options: " ssh vncshare forcetrigger networktimeout=30". This will permit SSH and VNC connections to PINN. Forcetrigger will force the PINN installation menu to be shown on each boot to ensure you maintain connectivity whilst the new OS is being installed. Forcetrigger can be removed once the system is working properly.

  • Copy userconf

cp ~/userconf /boot

  • Reboot into PINN. (SD Card will be formatted)

sudo reboot

After reboot, PINN will start. It will repartition the SD card, thus removing your previous OS and any other partitions that are present. Provided your router provides a DHCP server, or you have set up your network configuration according to your needs, PINN should connect to the network with the same IP address you used before. It may take a minute or two for ssh to become available, depending on the size of the SD card. Subsequent reboots will be quicker but it may still take up to 30 secs to connect.

  • Connect to PINN over SSH

If the RPi is on a local area network, it will be possible to connect SSH and VNC directly to the RPi's IP address. If it is remote, then the VNC port would need to be forwarded through any remote firewall. To avoid this, VNC will be tunneled over SSH. From Linux, use:

ssh root@<ipaddress> -L 1234:localhost:5900

If using Windows Putty, enter the IPaddress and use port 22. Then in the connection/ssh/tunnels settings, add source port '1234', destination 'localhost:5900', check Local and Auto, then ADD this to the tunnel table. Now connect using the login root/raspberry

On successful SSH connection, a tunnel from port 1234 on the local PC to port 5900 on the remote RPi will have been established.

  • Connect to PINN over VNC

Use a suitable VNC client (RealVNC, tightVNC etc) to connect to the localhost (127.0.0.1) port 1234 which should then be tunneled to the RPi

  • Install New OS to remote pi.

For this example we will use Raspberry Pi OS Lite (64-bit). It can be found under the Minimal Tab. Select its checkbox and click install. PINN will download the OS and install it directly to the SD card. When it has installed, a dialog indicating "OSes installed successfully" is displayed. DO NOT PRESS OK at this stage otherwise you will lose connectivity. A couple of changes need to be made first...

  • Edit Installation

Swap to your SSH connection to PINN. You will be in a basic busybox ASH shell. It is similar to BASH, but with not so many options.
To edit some files in the new OS partitions, we first need to mount its boot partition.

cd /tmp
mkdir 6
mount /dev/mmcblk0p6 6
cd 6
touch ssh
cp /mnt/userconf .

The ssh file will force Raspberry Pi OS to enable SSH and the userconf file will cause the new user to be configured on first boot.

  • Final OS configuration

If there are any additional configurations you need to make to allow your OS to connect to your network, such as setting up wpa_supplicant.conf, static IP address or setup particular video modes etc., then this should be done now.

  • Boot your new OS

Reboot does not work in PINN, so instead use:

rebootp

  • OS First boot

When you boot into your new OS, the username should be configured and ssh enabled. Depending on the OS, it's first boot may try to expand the filesystem and then reboot. In this case, it will reboot into PINN. To get back to your OS, just press Esc (sometimes more than once) to boot back into the last OS.

  • Hide PINN.

Once your OS(-es) are installed, the forcetrigger option of PINN can be removed to prevent the installation menu showing on each boot. Instead PINN will act as a boot manager to select which OS you wish to boot. After a programmable timeout, or if you only have one OS installed, the last booted OS will automatically boot.

If the above boot selector is not required e.g. if only one OS is installed and there is no further use for PINN, it can be hidden by adding a file called autoboot.txt to PINN's boot partition. It should contain the line:

boot_partition=6

where '6' is the number of the partition to boot. Thereafter, your OS will boot as normal.
If you need to use PINN again, e.g. to backup your OS, restore it, install another etc. just remove this file.

Some advanced variations

  • Most boot partitions are recommended to be at least 256MB these days, so if you have a particularly small OS to install, say <200MB, it would be possible to save it in the /os folder of PINN's partition so that it can be installed directly form the SD card instead of from the internet. Installation from USB drive could also be possible.

  • PINN's noobsconfig feature could be used to install the additional configuration parameters to your OS. It could install its own first boot scripts or be used in conjunction with OS embedded scripts from sdm, Rpi-Imager etc.

  • Using the select and silentinstall options, PINN can be configured to automatically install a selected OS on first boot for a completely automated solution.

  • Please see README_PINN.md for other options and possibilities for using PINN.