【问题标题】:Remount /system from app从应用重新挂载 /system
【发布时间】:2013-07-15 03:25:09
【问题描述】:

我正在尝试创建一个需要对 /system 文件夹进行读/写访问的小型应用程序(它正在尝试删除一个文件,并创建一个新文件而不是它)。 我可以使用 adb 重新挂载文件夹而不会出现问题,如果我这样做了,我的应用程序肯定可以正常工作,直到重新启动。

我的设备已植根(带有库存 4.1.2 的 sgs3)。我可以毫无问题地获得 root 访问权限 - 我收到弹出消息,我可以在其中启用它。但在那之后它并没有真正响应命令。

我有这样的事情:

//at this point I get the popup to grant root access
Runtime.getRuntime().exec("su");

//no error messages - not on console, not in logcat
Runtime.getRuntime().exec("mount -w -o remount -t ext4 /dev/block/mmcblk0p9 /system");

//trying to do things in the system folder...
FileWriter fw=new FileWriter(file);
fw.write("a");
fw.close();

//trying to remount the folder as read only only once everything is done
Runtime.getRuntime().exec("mount -r -o remount -t ext4 /dev/block/mmcblk0p9 /system");

如果我从 adb shell 运行相同的重新安装命令,一切都会完美。如果我不运行它,而是尝试依赖应用程序,当我尝试从文件系统写入/删除时,我会收到以下错误消息(抛出 IOException):

open failed: EROFS (read-only file system)

一些附加信息:我正在使用 2.2 SDK,在我的清单文件中有 WRITE_EXTERNAL_STORAGE 权限(虽然我不确定我是否需要它,因为我正在尝试使用内部存储)。

欢迎所有想法。

【问题讨论】:

    标签: java android mount


    【解决方案1】:

    您的问题是您正在安装的进程与您拥有 root 权限的进程不同,请尝试以下操作:

    Process suProcess;
    DataOutputStream os;
    
    
    try{
            //Get Root
            suProcess = Runtime.getRuntime().exec("su");
            os= new DataOutputStream(suProcess.getOutputStream());
    
            //Remount writable FS within the root process
            os.writeBytes("mount -w -o remount -t ext4 /dev/block/mmcblk0p9 /system\n");
            os.flush();
    
            //Do something here
            os.writeBytes("rm /system/somefile\n");
            os.flush();
    
            //Do something there
            os.writeBytes("touch /system/somefile\n");
            os.flush();
    
            //Remount Read-Only
            os.writeBytes("mount -r -o remount -t ext4 /dev/block/mmcblk0p9 /system\n");
            os.flush();
    
            //End process
            os.writeBytes("exit\n");
            os.flush();
    
       }
    catch (IOException e) {
            throw new RuntimeException(e);
        }
    

    【讨论】:

    • 哇,它似乎工作。需要一些练习,但它会很完美。谢谢!
    猜你喜欢
    • 2018-08-26
    • 2017-08-12
    • 2020-02-06
    • 1970-01-01
    • 2018-12-20
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    相关资源
    最近更新 更多