Skip to content

Instantly share code, notes, and snippets.

@oskarirauta
Created February 27, 2024 12:09
Show Gist options
  • Save oskarirauta/703492e1a5e50e0e0513882c035ada44 to your computer and use it in GitHub Desktop.
Save oskarirauta/703492e1a5e50e0e0513882c035ada44 to your computer and use it in GitHub Desktop.
disable_extroot config for fstools
--- a/block.c
+++ b/block.c
@@ -84,7 +84,7 @@ struct mount {
static struct vlist_tree mounts;
static struct blob_buf b;
static LIST_HEAD(devices);
-static int anon_mount, anon_swap, auto_mount, auto_swap, check_fs;
+static int anon_mount, anon_swap, auto_mount, auto_swap, check_fs, disable_extroot;
static unsigned int delay_root;
enum {
@@ -94,6 +94,7 @@ enum {
CFG_AUTO_SWAP,
CFG_DELAY_ROOT,
CFG_CHECK_FS,
+ CFG_DISABLE_EXTROOT,
__CFG_MAX
};
@@ -104,6 +105,7 @@ static const struct blobmsg_policy confi
[CFG_AUTO_MOUNT] = { .name = "auto_mount", .type = BLOBMSG_TYPE_INT32 },
[CFG_DELAY_ROOT] = { .name = "delay_root", .type = BLOBMSG_TYPE_INT32 },
[CFG_CHECK_FS] = { .name = "check_fs", .type = BLOBMSG_TYPE_INT32 },
+ [CFG_DISABLE_EXTROOT] = { .name = "disable_extroot", .type = BLOBMSG_TYPE_INT32 },
};
enum {
@@ -281,9 +283,9 @@ static int mount_add(struct uci_section
parse_mount_options(m, blobmsg_get_strdup(tb[MOUNT_OPTIONS]));
m->overlay = m->extroot = 0;
- if (m->target && !strcmp(m->target, "/"))
+ if (!disable_extroot && m->target && !strcmp(m->target, "/"))
m->extroot = 1;
- if (m->target && !strcmp(m->target, "/overlay"))
+ if (!disable_extroot && m->target && !strcmp(m->target, "/overlay"))
m->extroot = m->overlay = 1;
if (m->target && *m->target != '/') {
@@ -366,6 +368,9 @@ static int global_add(struct uci_section
if ((tb[CFG_CHECK_FS]) && blobmsg_get_u32(tb[CFG_CHECK_FS]))
check_fs = 1;
+ if ((tb[CFG_DISABLE_EXTROOT]) && blobmsg_get_u32(tb[CFG_DISABLE_EXTROOT]))
+ disable_extroot = 1;
+
return 0;
}
@@ -1103,7 +1108,7 @@ static int mount_device(struct probe_inf
}
m = find_block(pr->uuid, pr->label, device, NULL);
- if (m && m->extroot)
+ if (m && m->extroot && !disable_extroot)
return -1;
mp = find_mount_point(pr->dev);
@@ -1293,7 +1298,7 @@ static int main_autofs(int argc, char **
continue;
m = find_block(pr->uuid, pr->label, NULL, NULL);
- if (m && m->extroot)
+ if (m && m->extroot && !disable_extroot)
continue;
blockd_notify("hotplug", pr->dev, m, pr);
@@ -1563,6 +1568,9 @@ static int mount_extroot(char *cfg)
struct mount *m;
int err = -1;
+ if (disable_extroot)
+ return 0;
+
/* Load @cfg/etc/config/fstab */
if (config_load(cfg))
return -2;
@@ -1581,7 +1589,7 @@ static int mount_extroot(char *cfg)
/* Find block device pointed by the mount config */
pr = find_block_info(m->uuid, m->label, m->device);
- if (!pr && delay_root){
+ if (!pr && delay_root && !disable_extroot){
ULOG_INFO("extroot: device not present, retrying in %u seconds\n", delay_root);
sleep(delay_root);
make_devs();
@@ -1645,7 +1653,7 @@ static int main_extroot(int argc, char *
libubi_t libubi;
#endif
- if (!getenv("PREINIT"))
+ if (!getenv("PREINIT") || !disable_extroot)
return -1;
if (argc != 2) {
@@ -1660,9 +1668,11 @@ static int main_extroot(int argc, char *
ulog_threshold(LOG_INFO);
/* try the currently mounted overlay if exists */
- err = mount_extroot("/tmp/overlay");
- if (!err)
- return err;
+ if (!disable_extroot) {
+ err = mount_extroot("/tmp/overlay");
+ if (!err)
+ return err;
+ }
/*
* Look for "rootfs_data". We will want to mount it and check for
@@ -1776,7 +1786,8 @@ static int main_detect(int argc, char **
printf("\toption\tauto_swap\t'1'\n");
printf("\toption\tauto_mount\t'1'\n");
printf("\toption\tdelay_root\t'5'\n");
- printf("\toption\tcheck_fs\t'0'\n\n");
+ printf("\toption\tcheck_fs\t'0'\n");
+ printf("\toption\tdisable_extroot\t'0'\n\n");
list_for_each_entry(pr, &devices, list)
print_block_uci(pr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment