mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-18 08:32:59 +00:00
Use /data as tmpfs mount point in 2SI setup
Design credit to @yujincheng08 Close #5146. Fix #5491, fix #3752 Previously, Magisk changes the mount point from /system to /system_root by patching fstab to prevent the original init from changing root. The reason why we want to prevent the original init from switching the root directory is because it will then be read-only, making patching and injecting magiskinit into the boot chain difficult. This commit (ab)uses the fact that the /data folder will never be part of early mount (because it is handled very late in the boot by vold), so that we can use it as the mount point of tmpfs to store files. Some advantages of this method: - No need to switch root manually - No need to modify fstab, which significantly improves compatibility e.g. avoid hacks for weird devices like those using oplus.fstab, and avoid hacking init to bypass fstab in device trees - Supports skip_mount.cfg - Support DSU
This commit is contained in:
@@ -34,7 +34,6 @@ struct fstab_entry {
|
||||
fstab_entry(fstab_entry &&) = default;
|
||||
fstab_entry &operator=(const fstab_entry&) = delete;
|
||||
fstab_entry &operator=(fstab_entry&&) = default;
|
||||
void to_file(FILE *fp);
|
||||
};
|
||||
|
||||
#define INIT_SOCKET "MAGISKINIT"
|
||||
@@ -44,7 +43,6 @@ extern std::vector<std::string> mount_list;
|
||||
|
||||
bool unxz(int fd, const uint8_t *buf, size_t size);
|
||||
void load_kernel_info(BootConfig *config);
|
||||
bool is_dsu();
|
||||
bool check_two_stage();
|
||||
void setup_klog();
|
||||
const char *backup_init();
|
||||
@@ -107,7 +105,6 @@ public:
|
||||
class FirstStageInit : public BaseInit {
|
||||
private:
|
||||
void prepare();
|
||||
void get_default_fstab(char *buf, size_t len);
|
||||
public:
|
||||
FirstStageInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {
|
||||
LOGD("%s\n", __FUNCTION__);
|
||||
@@ -124,17 +121,14 @@ public:
|
||||
|
||||
class SARInit : public SARBase {
|
||||
private:
|
||||
bool is_two_stage;
|
||||
|
||||
void early_mount();
|
||||
bool early_mount();
|
||||
void first_stage_prep();
|
||||
public:
|
||||
SARInit(char *argv[], BootConfig *cmd) : MagiskInit(argv, cmd), is_two_stage(false) {
|
||||
SARInit(char *argv[], BootConfig *cmd) : MagiskInit(argv, cmd) {
|
||||
LOGD("%s\n", __FUNCTION__);
|
||||
};
|
||||
void start() override {
|
||||
early_mount();
|
||||
if (is_two_stage)
|
||||
if (early_mount())
|
||||
first_stage_prep();
|
||||
else
|
||||
patch_rootdir();
|
||||
@@ -178,8 +172,10 @@ public:
|
||||
};
|
||||
|
||||
void start() override {
|
||||
if (prepare()) patch_rootfs();
|
||||
else patch_rootdir();
|
||||
if (prepare())
|
||||
patch_rootfs();
|
||||
else
|
||||
patch_rootdir();
|
||||
exec_init();
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user