Raspberry Pi Install with Overlay Control (Ubuntu Studio)

These instructions enable a Raspberry Pi to be configured with a ramdisk overlay, thereby protecting the underlying OS memory card from corruption

They contain scripts which are designed to run on a linux host system to initialise and pre-install the memory card.

In addition to setting up the machine, they also allow for a USB device to be mounted which contains the user home directories.

The script has been tested on Ubuntu Studio 20.

INGREDIENTS

  • Configuration Script
  • 1 Raspberry Pi
  • 1 Pi Memory Card
  • 1 USB Memory Stick

METHOD

1. Configuration Script

On a Linux machine, download the configuration script bundle from here:
Include Bundle Link
Unpack the bundle into an empty folder:
tar xzf pi-config-script.tar.gz
This bundle incorporates the overlay control scripts verbatim from: ghollingworth

2. Preparing the USB Stick

Ensure that the USB memory stick is formatted for use on a Linux operating system, ideally with the ext2 disk format.

  • Use dmesg, or lsblk to identify the device name of the USB stick.
  • And then, use the fdisk to create a partition.
  • And then use mkfs.ext2 to format that partition.

3. Downloading the Raspberry Pi OS

Download the latest Raspberry Pi OS Lite from:


And unpack the file to reveal the .img data file

4. Setting up your Network

Generate wpa_supplicant.conf, and edit it to configure your wireless network.
# cp wpa_supplicant.conf.org wpa_supplicant.conf
# vi wpa_supplicant.conf

5. Formatting and Installing

Insert the micro-SD memory card for the Pi into a Linux PC, and identify which device it appears as.  You can wait for it to auto-mount (if it has been previously used), or use the lsblk or dmesg program.

Run the setup script, e.g.:
# ./install.sh 2021-01-11-raspios-buster-armhf-lite.img /dev/sda

sda           8:0    1  14.9G  0 disk 
├─sda1        8:1    1   256M  0 part /media/username/boot
└─sda2        8:2    1  14.6G  0 part /media/username/rootfs
type YES to confirm you wish to use this device

yes 

Confirmed use of device /dev/sda
Unmounting /dev/sda1
Unmounting /dev/sda2
Writing image to card ....
[sudo] password for user: ******
1776+0 records out
1862270976 bytes (1.9 GB, 1.7 GiB) copied, 128.924 s, 14.4 MB/s
Write complete
Waiting for device to mount. If it doesn't happen automatically
after 30 seconds, remove and reinsert the card.
Image complete, copying files
Transferring install scripts to /media/username/rootfs/home/pi
1776+0 records in

 On completion, the disk can be removed and installed into the Pi


6. Booting the Pi

Install both the memory card and the USB stick into the Pi and boot it.
Wait for a couple of minutes, and attempt to connect to if from your Linux machine:
# ssh -l pi raspberrypi.local
password: raspberry
Note that the ssh may complain if you have previously configured a different pi, in which case you should follow the ssh-keygen advice which is presented.

7. Configuring the Pi

Configure the Pi by running the install script, which will set up the overlay control, change the device name and set up a default admin user and normal user:
# install/install.sh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
initramfs-tools is already the newest version (0.133+deb10u1).
initramfs-tools set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
update-initramfs: Generating /boot/initrd.img-5.4.83-v7l+

==================================================

Disabling swapfile
 
==================================================

Setting login message of the day

==================================================

Mounting memory stick as /usbhome
Found ext2 Device: /dev/sda1 with partuuid: 0a2d4262-af55-c643-8971-9192939a9b93
No fstab entry found, adding one
/usbhome disk mounted

==================================================

current hostname is raspberrypi
Enter new hostname: 
openhab 
Updating /etc/hostname for new hostname
Updating /etc/hosts for new hostname
hostname is now: openhab
Enter the account username for a new adminuser user: 
adminuser 
Creating user adminuser
Enter a password for adminuser
New password: *****
Retype new password: *****
passwd: password updated successfully
Enter the account username for a new mortal user: 
mortaluser 
Enter the full (readable) Name of the new mortal user: 
M User 
Creating user mortaluser
Not copying any file from skel directory into it.
Enter a password for mortalusers
New password: *****
Retype new password: *****
passwd: password updated successfully
Changing pi user password - this is important to ensure the device is secure
New password: *****
Retype new password: *****
passwd: password updated successfully
NOTE: It is recommended you remove the pi user
New User Addition Complete
/ will be mounted RW on next boot
Now reboot, and connect again with 'ssh -l adminuser openhab.local'
Press ENTER to reboot

 

8. Reboot the Pi

Following the reboot, log back in with ssh.  This time you will need to use the new device name and the administration account.

If you plan to expose the device to the internet it is recommended that you go one step above simply setting the pi user password, and that you completely remove the pi user:
# deluser -r pi

9. Install Other Software

Install any other software you will need to use on the Pi.

10. Enable Overlay

Enable the overlay and reboot:
# sudo overctl -r
# sync
# sudo reboot