From 37eed131e9967a35f47bacb3437a9d3c8a57b3f4 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 15 Feb 2021 07:06:42 +0000 Subject: [PATCH] system: expose if system was booted from initramfs 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 --- initd/preinit.c | 1 - system.c | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/initd/preinit.c b/initd/preinit.c index 9dfe5c1..46411aa 100644 --- a/initd/preinit.c +++ b/initd/preinit.c @@ -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"); diff --git a/system.c b/system.c index 7855659..83aea42 100644 --- 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)); -- 2.30.2