From 19f355ea0196ec04241cae57215c364c0c1fbb16 Mon Sep 17 00:00:00 2001 From: lean Date: Sat, 19 Jun 2021 19:26:22 +0800 Subject: [PATCH] fstools: enable any device with non-MTD rootfs_data volume Fixes: #673 (cherry picked from commit 90ace9890f07c710c7659142135231a9cf7bc747) --- package/system/fstools/Makefile | 4 +- ...port-extroot-for-non-MTD-rootfs_data.patch | 123 ++++++++++++++++++ 2 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 package/system/fstools/patches/100-fstools-support-extroot-for-non-MTD-rootfs_data.patch diff --git a/package/system/fstools/Makefile b/package/system/fstools/Makefile index 379f5d8c9d..a0f081846f 100644 --- a/package/system/fstools/Makefile +++ b/package/system/fstools/Makefile @@ -82,14 +82,14 @@ define Package/block-mount SECTION:=base CATEGORY:=Base system TITLE:=Block device mounting and checking - DEPENDS:=+ubox +libubox +libuci +libblobmsg-json +libjson-c + DEPENDS:=+ubox +libubox +libuci +libblobmsg-json +libjson-c +fstools endef define Package/blockd SECTION:=base CATEGORY:=Base system TITLE:=Block device automounting - DEPENDS:=+block-mount +fstools +libubus +kmod-fs-autofs4 +libblobmsg-json +libjson-c + DEPENDS:=+block-mount +libubus +kmod-fs-autofs4 +libblobmsg-json +libjson-c endef define Package/fstools/install diff --git a/package/system/fstools/patches/100-fstools-support-extroot-for-non-MTD-rootfs_data.patch b/package/system/fstools/patches/100-fstools-support-extroot-for-non-MTD-rootfs_data.patch new file mode 100644 index 0000000000..6a9ea9f4b0 --- /dev/null +++ b/package/system/fstools/patches/100-fstools-support-extroot-for-non-MTD-rootfs_data.patch @@ -0,0 +1,123 @@ +From: Qi Liu + +In order to support extroot, block extroot command has to be able to +discover and properly mount the rootfs_data volume in order to discover +the extroot volume. Currently this process can only discover MTD devices. +This patch leverages libfstools in a similar way as mount_root to +discover, initialize, and mount rootfs_data volume. It would enable any +device with non-MTD rootfs_data volume to support extroot, including x86. + +Signed-off-by: Qi Liu +--- + +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -79,9 +79,9 @@ INSTALL(TARGETS blockd RUNTIME DESTINATI + ADD_EXECUTABLE(block block.c probe.c probe-libblkid.c) + IF(DEFINED CMAKE_UBIFS_EXTROOT) + ADD_DEFINITIONS(-DUBIFS_EXTROOT) +- TARGET_LINK_LIBRARIES(block blkid-tiny dl uci ubox ubus blobmsg_json ubi-utils ${json}) ++ TARGET_LINK_LIBRARIES(block blkid-tiny dl fstools uci ubox ubus blobmsg_json ubi-utils ${json}) + ELSE(DEFINED CMAKE_UBIFS_EXTROOT) +- TARGET_LINK_LIBRARIES(block blkid-tiny dl uci ubox ubus blobmsg_json ${json}) ++ TARGET_LINK_LIBRARIES(block blkid-tiny dl fstools uci ubox ubus blobmsg_json ${json}) + ENDIF(DEFINED CMAKE_UBIFS_EXTROOT) + INSTALL(TARGETS block RUNTIME DESTINATION sbin) + +--- a/block.c ++++ b/block.c +@@ -44,6 +44,9 @@ + #include + #include + ++#include "libfstools/fstype.h" ++#include "libfstools/volume.h" ++ + #include "probe.h" + + #define AUTOFS_MOUNT_PATH "/tmp/run/blockd/" +@@ -1696,6 +1699,44 @@ static int main_extroot(int argc, char * + } + #endif + ++ /* Find volume using libfstools */ ++ struct volume *data = volume_find("rootfs_data"); ++ if (data) { ++ volume_init(data); ++ ++ switch (volume_identify(data)) { ++ case FS_EXT4: { ++ char cfg[] = "/tmp/ext4_cfg"; ++ ++ /* Mount volume and try extroot (using fstab from that vol) */ ++ mkdir_p(cfg, 0755); ++ if (!mount(data->blk, cfg, "ext4", MS_NOATIME, NULL)) { ++ err = mount_extroot(cfg); ++ umount2(cfg, MNT_DETACH); ++ } ++ if (err < 0) ++ rmdir("/tmp/overlay"); ++ rmdir(cfg); ++ return err; ++ } ++ ++ case FS_F2FS: { ++ char cfg[] = "/tmp/f2fs_cfg"; ++ ++ /* Mount volume and try extroot (using fstab from that vol) */ ++ mkdir_p(cfg, 0755); ++ if (!mount(data->blk, cfg, "f2fs", MS_NOATIME, NULL)) { ++ err = mount_extroot(cfg); ++ umount2(cfg, MNT_DETACH); ++ } ++ if (err < 0) ++ rmdir("/tmp/overlay"); ++ rmdir(cfg); ++ return err; ++ } ++ } ++ } ++ + /* As a last resort look for /etc/config/fstab on "rootfs" partition */ + return mount_extroot(NULL); + } +--- /dev/null ++++ b/libfstools/fstype.h +@@ -0,0 +1,13 @@ ++#ifndef _FS_TYPE_H__ ++#define _FS_TYPE_H__ ++enum { ++ FS_NONE, ++ FS_SNAPSHOT, ++ FS_JFFS2, ++ FS_DEADCODE, ++ FS_UBIFS, ++ FS_F2FS, ++ FS_EXT4, ++ FS_TARGZ, ++}; ++#endif +--- a/libfstools/libfstools.h ++++ b/libfstools/libfstools.h +@@ -18,20 +18,10 @@ + #include + #include + #include ++#include "fstype.h" + + struct volume; + +-enum { +- FS_NONE, +- FS_SNAPSHOT, +- FS_JFFS2, +- FS_DEADCODE, +- FS_UBIFS, +- FS_F2FS, +- FS_EXT4, +- FS_TARGZ, +-}; +- + enum fs_state { + FS_STATE_UNKNOWN, + FS_STATE_PENDING,