[v4,1/3] package/tinyinit: new package

Message ID 20240831120833.2915529-2-dario.binacchi@amarulasolutions.com
State New
Headers show
Series
  • tinyinit and stm32f746_disco_sd_defconfig
Related show

Commit Message

Dario Binacchi Aug. 31, 2024, 12:08 p.m. UTC
This package contains a Linux init script suitable for resource-limited
systems which can be used as an alternative to the one provided by
Busybox.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Cc: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
Changes v3 -> v4:
 - Add tinyinit to Busybox dependencies
 - Add a comment to the tinyinit.mk just before the statements creating
   the symlink
 - Drop the comment from package/tinyinit/Config.in
 - Add the entry in the init selection in system/Config.in.

Changes v2 -> v3:
 - Add the init script
 - Drop the entry in the init selection in system/Config.in.

Changes v1 -> v2:
 - Rename tinit to tinyinit.
 - Put the script inside the tinyinit package without the need to use
   a github repo.
 - Update the commit message.

 DEVELOPERS                   |  1 +
 package/Config.in            |  1 +
 package/busybox/busybox.mk   |  1 +
 package/tinyinit/Config.in   |  8 ++++++++
 package/tinyinit/init        | 32 ++++++++++++++++++++++++++++++++
 package/tinyinit/tinyinit.mk | 13 +++++++++++++
 system/Config.in             |  9 +++++++++
 7 files changed, 65 insertions(+)
 create mode 100644 package/tinyinit/Config.in
 create mode 100644 package/tinyinit/init
 create mode 100644 package/tinyinit/tinyinit.mk

Comments

'Jan Kiszka' via Amarula Linux Sept. 2, 2024, 12:26 a.m. UTC | #1
On 8/31/24 21:08, Dario Binacchi wrote:
> This package contains a Linux init script suitable for resource-limited
> systems which can be used as an alternative to the one provided by
> Busybox.

I think it would be good to add a description of the menuconfig path to enable
this init here.

Other than that, looks good to me:

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Yann E. MORIN Sept. 14, 2024, 9:24 a.m. UTC | #2
Dario, All,

On 2024-08-31 14:08 +0200, Dario Binacchi spake thusly:
> This package contains a Linux init script suitable for resource-limited
> systems which can be used as an alternative to the one provided by
> Busybox.
> 
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> Cc: Yann E. MORIN <yann.morin.1998@free.fr>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> ---
[--SNIP--]
> diff --git a/package/tinyinit/Config.in b/package/tinyinit/Config.in
> new file mode 100644
> index 000000000000..f68b030e7e0f
> --- /dev/null
> +++ b/package/tinyinit/Config.in
> @@ -0,0 +1,8 @@
> +config BR2_PACKAGE_TINYINIT
> +	bool "tinyinit"
> +	depends on BR2_INIT_TINYINIT
> +	imply BR2_PACKAGE_BUSYBOX

As discussed with together with the other maintainers at the dev-days,
we concluded that we do not want to use 'imply', at least not in this
case.

Indeed, imply is a soft requirement, that makes the target enabled by
default, but can still be de-selectable. In our case, busybox is already
enabled by default, so 'imply' has no impact.

Applied to master with 'imply' dropped, thanks!

Regards,
Yann E. MORIN.

> +	help
> +	  A Linux tiny initialization script suitable for resource
> +	  limited systems, which can be used as an alternative to the
> +	  one provided by Busybox.
> diff --git a/package/tinyinit/init b/package/tinyinit/init
> new file mode 100644
> index 000000000000..fbcb481010c2
> --- /dev/null
> +++ b/package/tinyinit/init
> @@ -0,0 +1,32 @@
> +#!/bin/sh
> +
> +# This script replaces the default busybox init process to avoid having that
> +# process staying alive and sleeping in the background, (uselessly) consuming
> +# precious memory.
> +
> +# Mount procfs and sysfs
> +/bin/mount -t proc proc /proc
> +/bin/mount -t sysfs sysfs /sys
> +
> +# When the kernel is directly booted, devtmpfs is not automatically mounted.
> +# Manually mount it if needed.
> +devmnt=$(mount | grep -c devtmpfs)
> +if [ "${devmnt}" -eq 0 ]; then
> +    /bin/mount -t devtmpfs devtmpfs /dev
> +fi
> +
> +# Use the /dev/console device node from devtmpfs if possible to not
> +# confuse glibc's ttyname_r().
> +# This may fail (E.G. booted with console=), and errors from exec will
> +# terminate the shell, so use a subshell for the test
> +if (exec 0</dev/console) 2>/dev/null; then
> +    exec 0</dev/console
> +    exec 1>/dev/console
> +    exec 2>/dev/console
> +fi
> +
> +# Clear memory to reduce page fragmentation
> +echo 3 > /proc/sys/vm/drop_caches
> +
> +# Finally, let's start an interactive shell
> +exec /bin/sh
> diff --git a/package/tinyinit/tinyinit.mk b/package/tinyinit/tinyinit.mk
> new file mode 100644
> index 000000000000..ac1f0f736e38
> --- /dev/null
> +++ b/package/tinyinit/tinyinit.mk
> @@ -0,0 +1,13 @@
> +################################################################################
> +#
> +# tinyinit
> +#
> +################################################################################
> +
> +define TINYINIT_INSTALL_TARGET_CMDS
> +	$(INSTALL) -m 0755 -D $(TINYINIT_PKGDIR)/init $(TARGET_DIR)/sbin/init
> +	# Downside: In non-initramfs systems the symlink isn't used/needed
> +	(cd $(TARGET_DIR); ln -sf /sbin/init init)
> +endef
> +
> +$(eval $(generic-package))
> diff --git a/system/Config.in b/system/Config.in
> index d7d59db47db7..974152bd23e6 100644
> --- a/system/Config.in
> +++ b/system/Config.in
> @@ -165,6 +165,15 @@ config BR2_INIT_TINI
>  
>  	  https://github.com/krallin/tini
>  
> +config BR2_INIT_TINYINIT
> +	bool "tiny init"
> +	select BR2_PACKAGE_TINYINIT
> +	select BR2_PACKAGE_SKELETON_INIT_NONE if BR2_ROOTFS_SKELETON_DEFAULT
> +	help
> +	  A Linux tiny initialization script suitable for resource
> +	  limited systems, which can be used as an alternative to the
> +	  one provided by Busybox.
> +
>  config BR2_INIT_NONE
>  	bool "Custom (none)"
>  	select BR2_PACKAGE_SKELETON_INIT_NONE if BR2_ROOTFS_SKELETON_DEFAULT
> -- 
> 2.43.0
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 0b590f0ec20c..cf62d0ed65ae 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -791,6 +791,7 @@  F:	configs/imx8mn_bsh_smm_s2_defconfig
 F:	configs/imx8mn_bsh_smm_s2_pro_defconfig
 F:	configs/stm32f769_disco_sd_defconfig
 F:	package/sscep/
+F:	package/tinyinit/
 F:	package/uuu/
 
 N:	Dario Binacchi <dariobin@libero.it>
diff --git a/package/Config.in b/package/Config.in
index 211080345adc..af7f13a75f7e 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -2868,6 +2868,7 @@  menu "System tools"
 	source "package/tar/Config.in"
 	source "package/tealdeer/Config.in"
 	source "package/thermald/Config.in"
+	source "package/tinyinit/Config.in"
 	source "package/tpm-tools/Config.in"
 	source "package/tpm2-abrmd/Config.in"
 	source "package/tpm2-tools/Config.in"
diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index 204ebe0106ee..942875ee0e12 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -68,6 +68,7 @@  BUSYBOX_DEPENDENCIES = \
 	$(if $(BR2_PACKAGE_UNZIP),unzip) \
 	$(if $(BR2_PACKAGE_USBUTILS),usbutils) \
 	$(if $(BR2_PACKAGE_UTIL_LINUX),util-linux) \
+	$(if $(BR2_PACKAGE_TINYINIT),tinyinit) \
 	$(if $(BR2_PACKAGE_VIM),vim) \
 	$(if $(BR2_PACKAGE_WATCHDOG),watchdog) \
 	$(if $(BR2_PACKAGE_WGET),wget) \
diff --git a/package/tinyinit/Config.in b/package/tinyinit/Config.in
new file mode 100644
index 000000000000..f68b030e7e0f
--- /dev/null
+++ b/package/tinyinit/Config.in
@@ -0,0 +1,8 @@ 
+config BR2_PACKAGE_TINYINIT
+	bool "tinyinit"
+	depends on BR2_INIT_TINYINIT
+	imply BR2_PACKAGE_BUSYBOX
+	help
+	  A Linux tiny initialization script suitable for resource
+	  limited systems, which can be used as an alternative to the
+	  one provided by Busybox.
diff --git a/package/tinyinit/init b/package/tinyinit/init
new file mode 100644
index 000000000000..fbcb481010c2
--- /dev/null
+++ b/package/tinyinit/init
@@ -0,0 +1,32 @@ 
+#!/bin/sh
+
+# This script replaces the default busybox init process to avoid having that
+# process staying alive and sleeping in the background, (uselessly) consuming
+# precious memory.
+
+# Mount procfs and sysfs
+/bin/mount -t proc proc /proc
+/bin/mount -t sysfs sysfs /sys
+
+# When the kernel is directly booted, devtmpfs is not automatically mounted.
+# Manually mount it if needed.
+devmnt=$(mount | grep -c devtmpfs)
+if [ "${devmnt}" -eq 0 ]; then
+    /bin/mount -t devtmpfs devtmpfs /dev
+fi
+
+# Use the /dev/console device node from devtmpfs if possible to not
+# confuse glibc's ttyname_r().
+# This may fail (E.G. booted with console=), and errors from exec will
+# terminate the shell, so use a subshell for the test
+if (exec 0</dev/console) 2>/dev/null; then
+    exec 0</dev/console
+    exec 1>/dev/console
+    exec 2>/dev/console
+fi
+
+# Clear memory to reduce page fragmentation
+echo 3 > /proc/sys/vm/drop_caches
+
+# Finally, let's start an interactive shell
+exec /bin/sh
diff --git a/package/tinyinit/tinyinit.mk b/package/tinyinit/tinyinit.mk
new file mode 100644
index 000000000000..ac1f0f736e38
--- /dev/null
+++ b/package/tinyinit/tinyinit.mk
@@ -0,0 +1,13 @@ 
+################################################################################
+#
+# tinyinit
+#
+################################################################################
+
+define TINYINIT_INSTALL_TARGET_CMDS
+	$(INSTALL) -m 0755 -D $(TINYINIT_PKGDIR)/init $(TARGET_DIR)/sbin/init
+	# Downside: In non-initramfs systems the symlink isn't used/needed
+	(cd $(TARGET_DIR); ln -sf /sbin/init init)
+endef
+
+$(eval $(generic-package))
diff --git a/system/Config.in b/system/Config.in
index d7d59db47db7..974152bd23e6 100644
--- a/system/Config.in
+++ b/system/Config.in
@@ -165,6 +165,15 @@  config BR2_INIT_TINI
 
 	  https://github.com/krallin/tini
 
+config BR2_INIT_TINYINIT
+	bool "tiny init"
+	select BR2_PACKAGE_TINYINIT
+	select BR2_PACKAGE_SKELETON_INIT_NONE if BR2_ROOTFS_SKELETON_DEFAULT
+	help
+	  A Linux tiny initialization script suitable for resource
+	  limited systems, which can be used as an alternative to the
+	  one provided by Busybox.
+
 config BR2_INIT_NONE
 	bool "Custom (none)"
 	select BR2_PACKAGE_SKELETON_INIT_NONE if BR2_ROOTFS_SKELETON_DEFAULT