简介
在android上创建用户自定义dir,不像linux上,直接到 / 目录下,mkdir dir 就可以创建,由于android系统selinux对系统安装要求高,特别是android10 、11 ,每个新增dir,file都要加一些te规则,特别是在/目录下。下面有两种方式,可以在/ dir创建,并且支持rw。以下两种方式是在编译系统镜像时,打包到系统里。
- 方式一:创建之后,并且在fs_config.cpp/中,把文件权限给到0775,根目录下创建的文件,依旧是read only,暂无找到解决方式。
- 方式二:利用软连接的方式,将data目录下的文件夹,链接到/目录,可读可写。
方法一:直接创建
暂无
方法二:软连接方式
diff --git a/bootable/recovery/etc/init.rc b/bootable/recovery/etc/init.rc
index 0822aba..b085044 100644
--- a/bootable/recovery/etc/init.rc
+++ b/bootable/recovery/etc/init.rc
@@ -19,13 +19,18 @@ on init
symlink /system/bin /bin
symlink /system/etc /etc
+ mkdir /data
+ mkdir /data/tmp
+ mkdir /data/var
+ mkdir /data/run
+ mkdir /data/opt
+ mkdir /data/usr
mount cgroup none /acct cpuacct
mkdir /acct/uid
mkdir /sdcard
mkdir /system
- mkdir /data
mkdir /cache
mkdir /sideload
mkdir /mnt/system
diff --git a/device/qcom/kona/BoardConfig.mk b/device/qcom/kona/BoardConfig.mk
index c6674c4..55c4818 100755
--- a/device/qcom/kona/BoardConfig.mk
+++ b/device/qcom/kona/BoardConfig.mk
@@ -69,6 +69,7 @@ TARGET_COPY_OUT_ODM := odm
BOARD_ODMIMAGE_FILE_SYSTEM_TYPE := ext4
AB_OTA_PARTITIONS ?= boot vendor odm dtbo vbmeta
BOARD_EXT4_SHARE_DUP_BLOCKS := true
+BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE := 104857600
endif
ifeq ($(ENABLE_AB), true)
diff --git a/system/core/rootdir/Android.mk b/system/core/rootdir/Android.mk
index 24b3999..32eb2cb 100644
--- a/system/core/rootdir/Android.mk
+++ b/system/core/rootdir/Android.mk
@@ -100,6 +105,11 @@ LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
sbin dev proc sys system data odm oem acct config storage mnt apex debug_ramdisk $(BOARD_ROOT_EXTRA_FOLDERS)); \
ln -sf /system/bin $(TARGET_ROOT_OUT)/bin; \
ln -sf /system/etc $(TARGET_ROOT_OUT)/etc; \
+ ln -sf /data/usr $(TARGET_ROOT_OUT)/; \
+ ln -sf /data/tmp $(TARGET_ROOT_OUT)/; \
+ ln -sf /data/var $(TARGET_ROOT_OUT)/; \
+ ln -sf /data/run $(TARGET_ROOT_OUT)/; \
+ ln -sf /data/opt $(TARGET_ROOT_OUT)/; \
ln -sf /data/user_de/0/com.android.shell/files/bugreports $(TARGET_ROOT_OUT)/bugreports; \
ln -sf /sys/kernel/debug $(TARGET_ROOT_OUT)/d; \
ln -sf /storage/self/primary $(TARGET_ROOT_OUT)/sdcard
diff --git a/system/core/rootdir/init.rc b/system/core/rootdir/init.rc
index f563d64..1ae4d70 100755
--- a/system/core/rootdir/init.rc
+++ b/system/core/rootdir/init.rc
@@ -53,7 +53,7 @@ on init
# Link /vendor to /system/vendor for devices without a vendor partition.
symlink /system/vendor /vendor
-
+
# Create energy-aware scheduler tuning nodes
mkdir /dev/stune/foreground
mkdir /dev/stune/background
@@ -450,6 +450,12 @@ on post-fs-data
# Make sure that apexd is started in the default namespace
enter_default_mount_ns
+ mkdir /data/tmp 0775 root system
+ mkdir /data/run 0775 root system
+ mkdir /data/var 0775 root system
+ mkdir /data/usr 0775 root system
+ mkdir /data/opt 0775 root system
+
# /data/apex is now available. Start apexd to scan and activate APEXes.
mkdir /data/apex 0750 root system
mkdir /data/apex/active 0750 root system
diff --git a/system/sepolicy/prebuilts/api/26.0/private/file_contexts b/system/sepolicy/prebuilts/api/26.0/private/file_contexts
index 4485b95..ed877e1 100644
--- a/system/sepolicy/prebuilts/api/26.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/26.0/private/file_contexts
@@ -32,6 +32,11 @@
/sys u:object_r:sysfs:s0
# Symlinks
+/tmp u:object_r:rootfs:s0
+/usr u:object_r:rootfs:s0
+/var u:object_r:rootfs:s0
+/run u:object_r:rootfs:s0
+/opt u:object_r:rootfs:s0
/bugreports u:object_r:rootfs:s0
/d u:object_r:rootfs:s0
/etc u:object_r:rootfs:s0
@@ -314,6 +319,11 @@
# propagate to the "Expanded data files" section.
#
/data(/.*)? u:object_r:system_data_file:s0
+/data/tmp(/.*)? u:object_r:system_data_file:s0
+/data/usr(/.*)? u:object_r:system_data_file:s0
+/data/var(/.*)? u:object_r:system_data_file:s0
+/data/run(/.*)? u:object_r:system_data_file:s0
+/data/opt(/.*)? u:object_r:system_data_file:s0
/data/.layout_version u:object_r:install_data_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/prebuilts/api/27.0/private/file_contexts b/system/sepolicy/prebuilts/api/27.0/private/file_contexts
index 5369758..dc203fc 100644
--- a/system/sepolicy/prebuilts/api/27.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/27.0/private/file_contexts
@@ -32,6 +32,11 @@
/sys u:object_r:sysfs:s0
# Symlinks
+/tmp u:object_r:rootfs:s0
+/usr u:object_r:rootfs:s0
+/var u:object_r:rootfs:s0
+/run u:object_r:rootfs:s0
+/opt u:object_r:rootfs:s0
/bugreports u:object_r:rootfs:s0
/d u:object_r:rootfs:s0
/etc u:object_r:rootfs:s0
@@ -321,6 +326,11 @@
# propagate to the "Expanded data files" section.
#
/data(/.*)? u:object_r:system_data_file:s0
+/data/tmp(/.*)? u:object_r:system_data_file:s0
+/data/usr(/.*)? u:object_r:system_data_file:s0
+/data/var(/.*)? u:object_r:system_data_file:s0
+/data/run(/.*)? u:object_r:system_data_file:s0
+/data/opt(/.*)? u:object_r:system_data_file:s0
/data/.layout_version u:object_r:install_data_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/prebuilts/api/28.0/private/file_contexts b/system/sepolicy/prebuilts/api/28.0/private/file_contexts
index 32eb3f1..9cb51a4 100644
--- a/system/sepolicy/prebuilts/api/28.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/28.0/private/file_contexts
@@ -33,6 +33,11 @@
/firmware/firmware_mnt u:object_r:rootfs:s0
# Symlinks
+/tmp u:object_r:rootfs:s0
+/usr u:object_r:rootfs:s0
+/var u:object_r:rootfs:s0
+/run u:object_r:rootfs:s0
+/opt u:object_r:rootfs:s0
/bin u:object_r:rootfs:s0
/bugreports u:object_r:rootfs:s0
/d u:object_r:rootfs:s0
@@ -360,6 +365,11 @@
# propagate to the "Expanded data files" section.
#
/data(/.*)? u:object_r:system_data_file:s0
+/data/tmp(/.*)? u:object_r:system_data_file:s0
+/data/usr(/.*)? u:object_r:system_data_file:s0
+/data/var(/.*)? u:object_r:system_data_file:s0
+/data/run(/.*)? u:object_r:system_data_file:s0
+/data/opt(/.*)? u:object_r:system_data_file:s0
/data/.layout_version u:object_r:install_data_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/prebuilts/api/29.0/private/file_contexts b/system/sepolicy/prebuilts/api/29.0/private/file_contexts
index d5e0d6c..aa5a0df 100644
--- a/system/sepolicy/prebuilts/api/29.0/private/file_contexts
+++ b/system/sepolicy/prebuilts/api/29.0/private/file_contexts
@@ -33,6 +33,11 @@
/apex u:object_r:apex_mnt_dir:s0
# Symlinks
+/tmp u:object_r:rootfs:s0
+/usr u:object_r:rootfs:s0
+/var u:object_r:rootfs:s0
+/run u:object_r:rootfs:s0
+/opt u:object_r:rootfs:s0
/bin u:object_r:rootfs:s0
/bugreports u:object_r:rootfs:s0
/charger u:object_r:rootfs:s0
@@ -426,6 +431,11 @@
# propagate to the "Expanded data files" section.
#
/data(/.*)? u:object_r:system_data_file:s0
+/data/tmp(/.*)? u:object_r:system_data_file:s0
+/data/usr(/.*)? u:object_r:system_data_file:s0
+/data/var(/.*)? u:object_r:system_data_file:s0
+/data/run(/.*)? u:object_r:system_data_file:s0
+/data/opt(/.*)? u:object_r:system_data_file:s0
/data/system/packages\.list u:object_r:packages_list_file:s0
/data/.layout_version u:object_r:install_data_file:s0
/data/unencrypted(/.*)? u:object_r:unencrypted_data_file:s0
diff --git a/system/sepolicy/private/file_contexts b/system/sepolicy/private/file_contexts
index d5e0d6c..aa5a0df 100644
--- a/system/sepolicy/private/file_contexts
+++ b/system/sepolicy/private/file_contexts
@@ -33,6 +33,11 @@
/apex u:object_r:apex_mnt_dir:s0
# Symlinks
+/tmp u:object_r:rootfs:s0
+/usr u:object_r:rootfs:s0
+/var u:object_r:rootfs:s0
+/run u:object_r:rootfs:s0
+/opt u:object_r:rootfs:s0
/bin u:object_r:rootfs:s0
/bugreports u:object_r:rootfs:s0
/charger u:object_r:rootfs:s0
@@ -426,6 +431,11 @@
# propagate to the "Expanded data files" section.
#
/data(/.*)? u:object_r:system_data_file:s0
+/data/tmp(/.*)? u:object_r:system_data_file:s0
+/data/usr(/.*)? u:object_r:system_data_file:s0
+/data/var(/.*)? u:object_r:system_data_file:s0
+/data/run(/.*)? u:object_r:system_data_file:s0
+/data/opt(/.*)? u:object_r:system_data_file:s0
/data/system/packages\.list u:object_r:packages_list_file:s0
/data/.layout_version u:object_r:install_data_file:s0
/data/unencrypted(/.*)? u:object_r:unencrypted_data_file:s0
版权声明:本文为m0_57123509原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。