Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

Custom Image Tweaks



  • Hi Guys

    Im trying a different tactic for making a custom image my TinyPi Project. Rather than tweaking an image then backing it up, it was thinking about mounting the img file as a loop device and adding the needed files.

    I have the screen code and button code set as services, so they actually need enabling on first boot. is there a script that gets run on first boot that i can add on to?

    Also is the config,txt re-written on first boot? i tried replacing it with my own, and it seemed to be replaced once it had booted

    Thanks in advance

    Pete


  • Global Moderator

    @moosepr What's the basis for your image - the Raspbian Lite or the RetroPie image ? AFAIK, on 1st boot it's only the partition resizing service that starts.

    What you could do is to use something like the raspberry-net-mods.service. It runs once on boot and it executes something if it finds a file. Here is is how it works

    [Unit]
    Description=Copy user wpa_supplicant.conf
    ConditionPathExists=/boot/wpa_supplicant.conf
    Before=dhcpcd.service
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/bin/mv /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
    ExecStartPost=/bin/chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
    
    [Install]
    WantedBy=multi-user.target
    

    (/etc/systemd/system/multi-user.target.wants/raspberrypi-net-mods.service)

    Basically if it finds a Wifi configuration file on the /boot partition, it moves it from there - so subsequent system reboots will not run this service again - then executes a command after copying.
    You can do something similar - adding a folder/zip file file on the /boot partition would trigger a script that will copy some files and perform some configuration, moving the trigger-file out of the /boot partition.



  • @mitu thanks for your input 😁

    It's RetroPie based, just adding screen and button executables so that the end user doesn't have to.

    I successfully added the executables and the service files into the respective folders by mounting the image file as a loop device. I also tried manually creating the symbolic link that enabling a service does, but I'm assuming that because it was actually mounted inside a folder within another Linux instance, that it used the absolute file path which will be different on the end machine. Maybe I need to use chroot so it creates the link with the correct paths? 🤔


  • Global Moderator

    @moosepr I don't understand what you're referring to when you say 'symlink' ? The /boot folder will be empty on the Linux partition of the image (2nd one), but the first partition will be mounted there at runtime (so whatever is on the 1st partition will appear under /boot when the system runs).



  • @mitu when you create your own custom service files in /etc/systemd/system/ they don't actually do anything unless you enable them. I can successfully copy the service files into the correct location, but without enabling, they sit dormant.

    All I needed to do to get my image ruining was to run

    Systemctl enable TinyPi

    Which basically creates a link

    pi@raspberrypi:~ $ sudo systemctl enable TinyPi
    Created symlink /etc/systemd/system/multi-user.target.wants/TinyPi.service → /etc/systemd/system/TinyPi.service.
    pi@raspberrypi:~ $

    So as I can't enable the service in that way until the card has been written, I assumed that creating a symlink manually would work


  • Global Moderator

    @moosepr I see now. You can try adding a relative symlink, this way it would work without chroot.



  • @mitu im just trying it now. looked back at the commands i tried before and it looked as though i did it wrong. I also looked back and the config.txt was standard, so it looked like i had not actually copied that properly



  • so it turns out doing relative file paths for the symlink worked a treat, but i was still having issues with config.txt
    I managed to track it down though. Mounting the boot partition, changing the config, then unmounting wasn't actually working!! if i re-mounted again straight away, it would be back to the original files.

    I found a fix though, you have to mount the loop device with a sync flag, this stops it caching the changes and makes it work as expected :)

    thanks again for your help @mitu :)


Log in to reply
 

Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.