一、问题描述

为了正常挂在debugfs,需要在根分区创建/sys/kernel/debug目录,参照//base/startup/init/services/etc/init.cfg文件中mkdir命令的写法,在自定义产品的init.${ohos.boot.hardware}.cfg文件中的pre-init job中增加两条mkdir命令。

{
    "jobs" : [{                                         
            "name" : "pre-init",
            "cmds" : [
                "mkdir /sys/kernel/debug 0700 root root",
                "mkdir /sys/kernel/tracing 0700 root root",
                "write /proc/sys/vm/min_free_kbytes 10240"
            ]                   
        }, {                  
            "name" : "init",                                          
            "cmds" : [             
                "mount debugfs /sys/kernel/debug /sys/kernel/debug mode=755"
            ]                      
        }, {                                         
            "name" : "fs",                               
            "cmds" : [                                           
            ]                                                         
        }
    ]       
}

启动系统时,控制台输出有以下报错

[    4.846038] [pid=1][Init][ERROR][init_common_cmds.c:338]Create directory '/sys/kernel/debug' failed, err=1.
[    4.847072] [pid=1][Init][ERROR][init_common_cmds.c:338]Create directory '/sys/kernel/tracing' failed, err=1.
[    4.848944] [pid=1][Init][ERROR][init_common_cmds.c:455]Failed to mount for /sys/kernel/debug, err 2.
[    4.849711] [pid=1][Init][ERROR][init_common_cmds.c:455]Failed to mount for /sys/kernel/tracing, err 2.

错误码1是EPERM错误,查询man 2 mkdir找到该报错原因是EPERM The filesystem containing pathname does not support the creation of directories.。另外,init.cfg指定的mkdir命令也有很多报错的,错误码2,表示ENOENT A directory component in pathname does not exist or is a dangling symbolic link.,应该是父目录不存在导致的。
针对该问题,应该如何实现以下功能

  1. 系统启动时默认创建必需的目录
  2. 一次创建多层目录,类似mkdir -p参数
Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐