一、想在android 系统的根目录下新建一个tmp 文件夹,建立一个链接usr链接到data目录。
二、在system/core/rootdir/Android.mk里面的LOCAL_POST_INSTALL_CMD 增加
dev proc sys system data data_mirror odm oem acct config storage mnt apex debug_ramdisk tmp
ln -sf /data $(TARGET_ROOT_OUT)/usr; \
三、编译的时候会遇到set_selinux_xattr: No such file or directory searching for label "/usr"问题,需要修改selinux的权限问题。在最下面的修改内容里面有。
四、最后实现的效果图。
五、修改的内容
diff --git a/system/core/rootdir/Android.mk b/system/core/rootdir/Android.mk
old mode 100644
new mode 100755
index a9d0ed08a9..36214f2e53
--- a/system/core/rootdir/Android.mk
+++ b/system/core/rootdir/Android.mk
@@ -77,12 +77,13 @@ endif## create some directories (some are mount points) and symlinksLOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
- dev proc sys system data data_mirror odm oem acct config storage mnt apex debug_ramdisk \
+ dev proc sys system data data_mirror odm oem acct config storage mnt apex debug_ramdisk tmp \linkerconfig $(BOARD_ROOT_EXTRA_FOLDERS)); \ln -sf /system/bin $(TARGET_ROOT_OUT)/bin; \ln -sf /system/etc $(TARGET_ROOT_OUT)/etc; \ln -sf /data/user_de/0/com.android.shell/files/bugreports $(TARGET_ROOT_OUT)/bugreports; \ln -sfn /sys/kernel/debug $(TARGET_ROOT_OUT)/d; \
+ ln -sf /data $(TARGET_ROOT_OUT)/usr; \ln -sf /storage/self/primary $(TARGET_ROOT_OUT)/sdcardifdef BOARD_USES_VENDORIMAGELOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/vendor
diff --git a/system/sepolicy/prebuilts/api/30.0/private/file_contexts b/system/sepolicy/prebuilts/api/30.0/private/file_contexts
old mode 100644
new mode 100755
index 9620b75127..76f8ce2a44
--- a/system/sepolicy/prebuilts/api/30.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/30.0/private/file_contexts
@@ -36,6 +36,7 @@# Symlinks/bin u:object_r:rootfs:s0/bugreports u:object_r:rootfs:s0
+/usr u:object_r:system_data_root_file:s0/charger u:object_r:rootfs:s0/d u:object_r:rootfs:s0/etc u:object_r:rootfs:s0
@@ -471,6 +472,8 @@#/data u:object_r:system_data_root_file:s0/data/(.*)? u:object_r:system_data_file:s0
+/tmp u:object_r:system_data_root_file:s0
+/tmp/(.*)? u:object_r:system_data_file:s0/data/system/packages\.list u:object_r:packages_list_file:s0/data/unencrypted(/.*)? u:object_r:unencrypted_data_file:s0/data/backup(/.*)? u:object_r:backup_data_file:s0
diff --git a/system/sepolicy/private/file_contexts b/system/sepolicy/private/file_contexts
old mode 100644
new mode 100755
index 9620b75127..76f8ce2a44
--- a/system/sepolicy/private/file_contexts
+++ b/system/sepolicy/private/file_contexts
@@ -36,6 +36,7 @@# Symlinks/bin u:object_r:rootfs:s0/bugreports u:object_r:rootfs:s0
+/usr u:object_r:system_data_root_file:s0/charger u:object_r:rootfs:s0/d u:object_r:rootfs:s0/etc u:object_r:rootfs:s0
@@ -471,6 +472,8 @@#/data u:object_r:system_data_root_file:s0/data/(.*)? u:object_r:system_data_file:s0
+/tmp u:object_r:system_data_root_file:s0
+/tmp/(.*)? u:object_r:system_data_file:s0/data/system/packages\.list u:object_r:packages_list_file:s0/data/unencrypted(/.*)? u:object_r:unencrypted_data_file:s0/data/backup(/.*)? u:object_r:backup_data_file:s0
六、参考文章
Android系统在root目录下新建文件夹并创建链接_在root目录创建文件file6的软链接-CSDN博客
基于rk3588s andriod在根目录下创建软连接-CSDN博客
Android在rootdir根目录创建自定义目录和挂载点的方法_android高通平台根目录下创建目录_阿迷创客的博客-CSDN博客