0

I'm trying to build an embedded Linux image for the embedded system I'm working on.
It uses Buildroot and we are trying to install generic packages in it.
This works well up to the point where I install a script in the /etc/init.d/ directory on the target image.

To build in my software inside the image, I created the following makefile that is picked up by Buildroot.
It aims to copy a JAR file to the filesystem, with some additional scripts.
I found that scripts that start with the letter S are run automatically.
See: https://buildroot.org/downloads/manual/manual.html#_init_system

define MY_GATEWAY_INSTALL_TARGET_CMDS

  $(INSTALL) -d $(TARGET_DIR)/$(DST_FOLDER); \
  $(INSTALL) -D -m 0644 $(@D)/*.jar $(TARGET_DIR)/$(DST_FOLDER); \
  \
  $(INSTALL) -D -m 0700 /work/package/mycompany/my-gateway/artifacts/start_heimdall $(TARGET_DIR)/$(DST_FOLDER); \
  ln -snrf $(TARGET_DIR)/$(DST_FOLDER)/start_heimdall $(TARGET_DIR)/usr/bin/start_heimdall; \
  \
  $(INSTALL) -D -m 0755 /work/package/mycompany/my-gateway/artifacts/S99gateway $(TARGET_DIR)/$(DST_FOLDER); \
  $(INSTALL) -D -m 0755 /work/package/mycompany/my-gateway/artifacts/S99gateway $(TARGET_DIR)/etc/init.d/S99gateway; \
  \
  if [[ "$(BR2_HSDP_GATEWAY_INCLUDE_VERSION_FILE)" == "y" ]]; then \
      echo $(HEIMDALL_VERSION) > $(TARGET_DIR)/my_gw_version; \
  fi

endef

After building my image, I found that the JAR file and the start_heimdall script are correctly placed in the expected directory.
This is not the case for the S99gateway script, which does not appear in the /etc/init.d/ directory.
My application is therefor not started.

The target directory of the built image looks as follows:

ls -al $(TARGET)/usr/heimdall
total 19476
drwxr-xr-x 2 rick rick     4096 feb 28 08:43 .
drwxr-xr-x 8 rick rick     4096 feb 28 08:43 ..
-rw-r--r-- 1 rick rick 19924893 feb 28 08:40 heimdall-squidlink-1.0.0-1582809178-release.jar
-rwxr-xr-x 1 rick rick      362 feb 28 08:40 S99gateway
-rwx------ 1 rick rick      230 feb 28 08:40 start_heimdall

ls -al /etc/init.d
total 68
drwxr-xr-x  2 rick rick 4096 feb 28 08:43 .
drwxr-xr-x 14 rick rick 4096 feb 28 08:43 ..
-rwxr-xr-x  1 rick rick  423 dec  4 14:50 rcK
-rwxr-xr-x  1 rick rick  408 dec  4 14:50 rcS
-rwxr-x---  1 rick rick 1295 aug 13  2014 S01logging
-rwxr-xr-x  1 rick rick  241 feb 28 08:19 S10mdev
-rwxr-x---  1 rick rick 1708 nov  4  2016 S10modules
-rwxr-x---  1 rick rick  396 mei 30  2016 S11led
-rwxr-x---  1 rick rick  968 mrt 17  2015 S12automount
-rwxr-x---  1 rick rick  397 apr 27  2015 S15hostname
-rwxr-xr-x  1 rick rick 1365 dec  4 14:50 S20urandom
-rwxr-x---  1 rick rick   48 apr 22  2015 S40network
-rwxr-xr-x  1 rick rick  936 feb 28 08:40 S49ntp
-rwxr-xr-x  1 rick rick 4066 feb 28 08:31 S50dropbear
-rwxr-xr-x  1 rick rick  435 feb 28 08:41 S50stunnel
-rwxr-xr-x  1 rick rick  462 feb 28 08:31 S80dnsmasq
-rwxr-xr-x  1 rick rick  362 feb 28 08:40 S99gateway

The last line shows that my script is successfully copied to the desired directory.
When I flash the image onto my embedded device and SSH into it, I see the following:

ls -al /usr/heimdall
total 19468
drwxr-xr-x    2 root     root           408 Feb 28  2020 .
drwxr-xr-x    8 root     root           616 Feb 28  2020 ..
-rwxr-xr-x    1 root     root           362 Feb 28  2020 S99gateway
-rw-r--r--    1 root     root      19924893 Feb 28  2020 heimdall-squidlink-1.0.0-1582809178-release.jar
-rwx------    1 root     root           230 Feb 28  2020 start_heimdall

ls -al /etc/init.d
total 56
drwxr-xr-x    2 root     root          1128 Jan 17 22:12 .
drwx--x--x   14 root     root          3088 Jan 17 22:12 ..
-rwxr-x---    1 root     root          1295 Aug 13  2014 S01logging
-rwxr-xr-x    1 root     root           241 Feb  7  2020 S10mdev
-rwxr-x---    1 root     root          1708 Nov  4  2016 S10modules
-rwxr-x---    1 root     root           396 May 30  2016 S11led
-rwxr-x---    1 root     root           968 Mar 17  2015 S12automount
-rwxr-x---    1 root     root           397 Apr 27  2015 S15hostname
-rwxrwxr-x    1 root     root          1365 Dec  4  2019 S20urandom
-rwxr-x---    1 root     root            48 Apr 22  2015 S40network
-rwxr-xr-x    1 root     root           936 Jan 17 22:12 S49ntp
-rwxr-xr-x    1 root     root          4066 Feb  7  2020 S50dropbear
-rwxr-xr-x    1 root     root           435 Feb  7  2020 S50stunnel
-rwxr-xr-x    1 root     root           462 Feb  7  2020 S80dnsmasq
-rwxrwxr-x    1 root     root           423 Dec  4  2019 rcK
-rwxrwxr-x    1 root     root           408 Dec  4  2019 rcS

In this case, after flashing, the S99 script is no longer there.
Is the /etc/init.d/ directory protected in some way? I'm trying to understand why the script is not there anymore.
Is the correctness of the inner workings of the script important for the installation process?

Rick Slinkman
  • 643
  • 10
  • 23
  • See how we do our scripts to be placed inside Buildroot: https://github.com/andy-shev/buildroot/tree/intel (So called *netboot* infrastructure done this way: https://github.com/andy-shev/buildroot/commit/f5429b194f68d91f06343b8b61139977a00ae5bc) – 0andriy Feb 28 '20 at 15:50

1 Answers1

0

There is nothing special about /etc/init.d/. However, we cannot really understand what happened here: what is your DST_FOLDER variable ?

If your S99 script is in output/target, then it should definitely be part of the final filesystem image. Are you sure you ran make to regenerate the filesystem image, and reflashed your image properly ?

Generally speaking, what you wrote has a number of problems:

  • You don't need ; or \ at the end of each line
  • The init script should rather be installed in the _INIT_SYSV variable instead of in _INSTALL_TARGET_CMDS variable, even though that's not your issue
  • The check on BR2_HSDP_GATEWAY_INCLUDE_VERSION_FILE should be done using a make condition and not a shell condition
  • It's not clear why you install each file several times.
Thomas Petazzoni
  • 5,636
  • 17
  • 25
  • Thanks for your reply Thomas. The `DST_FOLDER` is defined in the same file and it's value is `/usr/heimdall`. I see that everything is correctly installed there, even my duplicate "sanity checks" that I put there to see if the file is installed at all. I will take the style comments and best practices to heart, thanks for that. – Rick Slinkman Feb 28 '20 at 16:19