Customise Raspbian-Ua-NetInst – beyond post-install.txt

Want a bare-bones Raspbian distribution? Start with this one:

  • Raspbian-Ua-NetInst (Smaller installer)
  • RaspberryPi-Ua-NetInst (Firstly, it installs over wifi and gives faster boot time – 10 seconds! but mainly it lets you “Bring your own” files, which we’ll need for method 1 below.)

But what if you want to make a custom installer which comes with more? With either of the above, there are two ways you can do this:

  1. Add package names to installer-configure.txt as per the instructions on those links. Easy!
  2. Add scripts to post-install.txt  to manipulate what’s been installed.

The problem is the former does not give scope for configuration, and the latter is somewhat of a black art. For example, in post-install.txt you cannot simply include commands like this:

Instead you need to do this:

And if you want to manipulate files that will appear on the final installation, God help you. I have had mixed success with this. YMMV!

This brings me to the greatest resource for moving forward:

There are three options it hints at:

  1. Add a script which executes on first login using /root/.bashrc. ,using systemd to log in automatically on first boot to run it.
  2. Use  post-install.txt to install your own custom repository.
  3. Cron: set up a cronjob to run a script on boot-up
  4. Use chef or similar, like this guy did

I will explore them in that order as I find the time, but in the meantime here’s my personal favourite below; in my opinion, the easiest:

Method 1:

This assumes that you’ll be using the Pi’s UART via a USB-serial console, rather than using SSH to log in.

First, get a copy of the raspbian-ua-netinst installer, and follow the instructions, all from here: RaspberryPi-Ua-NetInst.

Everything we need to do will involve adding and changing files they provide that will be going onto your SD card before you put it in your Pi.

They way this method works is first we will configure the installer by making a configuration file in the root of the SD card called installer-config.txt . Put the following in it to make output go to the UART:

Once the installer has done most of the installing, we will tack on a few things for it to do by adding a file at the root of the SD card called post-install.txt . It will run these commands before the installer after it’s done the installing, but before it reboots.

The final feature of the installer that we will use, is it allows us to bundle any files we want onto the SD card, and tell it where it should place them on the final system. We do this by placing them in /config/files/ , and listing them in /config/my-files.txt  as per the instructions.

Putting it all together, we will use these features of the installer to firstly make the system automatically log in once the installer reboots, then to have the system run a script we’ll make once it’s logged in.

We will adapt this tutorial which shows how to make the Pi log in automatically when boot up after installation, using systemd, which we will configure to do so simply by adding a file we’ll call  serial-getty@ttyAMA0.service  into two places within /config/files .

Secondly, when the system is installed and boots and automatically logs-in for the first time, we’ll get the system to run our commands by putting a little something into the .bashrc file in root’s home directory. Here’s how:

In the installer files that you copy on to the SD card, edit /config/my-files.list  and add these lines:

Create this directory structure:

Make two files, both called  serial-getty@ttyAMA0.service , in the following locations:

With the following in each:

Then make a file called on-first-login.sh  in this location:

With the following contents:

Make a file at the root of the installation files called add.bashrc with the following:

Now create a file at the root of the installation files called post-install.txt  and put this in it:

And that’s it! Now you have what you need to easily set up your system post-installation without any attention required – it will do the entire thing without any input, just insert the SD card, power-up and wait 20 minutes! Just put your post-installation commands in on-first-login.sh  .

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *