Well, actually this applies to (I guess) any Linux system, but I needed it for Boot to Qt image, so…

Bash, Qt, Yocto

Just in case, here’s what I have:

root@b2qt-raspberrypi3:~# cat /etc/*-release
NAME="Boot to Qt for Embedded Linux"
VERSION="2.3.2 (pyro)"
PRETTY_NAME="Boot to Qt for Embedded Linux 2.3.2 (pyro)"

root@b2qt-raspberrypi3:~# uname -a
Linux b2qt-raspberrypi3 4.9.27 #1 SMP Sat Nov 18 02:35:59 EET 2017 armv7l armv7l armv7l GNU/Linux

Now, if you want to run your script instead of the Boot to Qt launcher, then simply create a symbolic link to your script:

ln -s /data/user/yourscript.sh /usr/bin/b2qt

And if you want just to run your script on startup, without messing with the standard Boot to Qt launcher, then read below.

But first some news. As you know, Qt 5.10 has just been released, and Boot to Qt images got a killer-feature there - now you can see the IP address for a Wi-Fi connection! Maybe this was added earlier, I don’t know, but it certainly was not in Qt 5.7. Anyway, what a giant leap for mankind:

Boot to Qt, Wi-Fi IP address

Now I can finally forget about dragging a router around, because I can set-up a local access point on Mac and deploy Qt applications to my Raspberry Pi over the thin air.

But okay, that’s not the point here. Let’s connect to the device:

ssh root@

Create a script that you want to run on startup:

vi /data/user/some.sh

Mine here just writes a text string to a file:

echo "ololo" >> /data/user/some.txt

Give it execute permission:

chmod +x /data/user/some.sh

Now create another script that will be your “launcher”. This script should go to /etc/init.d and here’s the thing - all the scripts in this folder should take at least the start argument in order to work, and also they should have a special commented header (but this one is not really a strict requirement). Here’s how it looks like:

vi /etc/init.d/autostart
# https://wiki.debian.org/LSBInitScripts
# Provides:          autostart
# Required-Start:    $all
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Autostart

# http://www.tldp.org/HOWTO/Path-4.html

case "$1" in
    logger "Starting autostart scripts"
    # your scripts here
    logger $?
    exit 0
    echo "It's just a startup script and has no arguments or commands"
    exit 1

Here we defined that our autostart script takes start argument (which is passed to it during startup by the system) and launches the /data/user/some.sh script. All the other arguments (*), including direct call with no arguments, are ignored.

Now we need to give it execute permission and enable it:

chmod +x /etc/init.d/autostart
update-rc.d autostart defaults

Reboot you device and check /data/user/some.txt. You can also look for messages in the system log (because we used logger):

cat /var/log/messages | grep "user.notice root"

If at some point you would like to disable the autostart script, execute the following:

update-rc.d -f autostart remove

And maybe remove the /etc/init.d/autostart file.