system: expose if system was booted from initramfs
authorDaniel Golle <daniel@makrotopia.org>
Mon, 15 Feb 2021 07:06:42 +0000 (07:06 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 23 Feb 2021 00:42:37 +0000 (00:42 +0000)
It can be good for UI to show to the user that the system was booted
from initramfs ie. no writable permanent storage is available.
I imagine LuCI only serving applications which are explicitely marked
as being shown even in initramfs mode, ie. nothing but status,
network->interfaces, network->wireless, system->upgrade,
system->backup, system->backuprestore tabs.
Also sysupgrade could take into account we are running on initramfs
and perform offline backup/restore of whatever is in the flash.
In that way OpenWrt-generated initramfs-images can serve as recovery
OS on devices with dual-boot in a meaningful way.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
initd/preinit.c
system.c

index 9dfe5c17576fbd2fcb19ee887e054e3ee24c6464..46411aa413a2a65614cfc765d3d6a42dee200532 100644 (file)
@@ -97,7 +97,6 @@ spawn_procd(struct uloop_process *proc, int ret)
        if (plugd_proc.pid > 0)
                kill(plugd_proc.pid, SIGKILL);
 
-       unsetenv("INITRAMFS");
        unsetenv("PREINIT");
        unlink("/tmp/.preinit");
 
index 7855659d79710c9e742b1fd00d8c674f10cf738f..83aea423ec6aaceedca54e42aea18ce90d7ddfa1 100644 (file)
--- a/system.c
+++ b/system.c
@@ -36,6 +36,7 @@
 static struct blob_buf b;
 static int notify;
 static struct ubus_context *_ctx;
+static int initramfs;
 
 enum vjson_state {
        VJSON_ERROR,
@@ -55,6 +56,9 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
 
        blob_buf_init(&b, 0);
 
+       if (initramfs)
+               blobmsg_add_u8(&b, "initramfs", 1);
+
        if (uname(&utsname) >= 0)
        {
                blobmsg_add_string(&b, "kernel", utsname.release);
@@ -759,6 +763,11 @@ void ubus_init_system(struct ubus_context *ctx)
        int ret;
 
        _ctx = ctx;
+
+       initramfs = !!getenv("INITRAMFS");
+       if (initramfs)
+               unsetenv("INITRAMFS");
+
        ret = ubus_add_object(ctx, &system_object);
        if (ret)
                ERROR("Failed to add object: %s\n", ubus_strerror(ret));