Understanding some instructions from android init.rc

in #technology6 years ago (edited)

Introduction

Recently I met some problems with android system's directories, so I have to modify init.rc to implement some functions. But I didn't know much about how to write android's init.rc. Some colleagues who have known it helped me fix the problem. But I still don't understand these instructions from "init.rc", I look up some references on the internet to understand them, then this essay is here.

The instructions from the scenario

The below is the instructions we should interprete in the essay:

mkdir /cores 0777 system system
mount tmpfs tmpfs /cores mode=0777,uid=1000,gid=1000
restorecon_recursive /cores

Let's analyze them one by one:

1 mkdir /cores 0777 system system

We can see that it's different as the Linux command, mkdir /cores is the normal command in linux, but what the hell the latter three things are? This is the special syntax of android init language. From the reference, I have known mkdir has the syntax below:

mkdir <path> [mode] [owner] [group]

Create a directory at path, optionally with the given mode, owner, and
group. If not provided, the directory is created with permissions 755 and
owned by the root user and root group. If provided, the mode, owner and group
will be updated if the directory exists already.

Now we can know this instruction's mean is:

  1. Create a directory with the given mode 0777.
  2. And the the owner user and the group user are both system.

2 mount tmpfs tmpfs /cores mode=0777,uid=1000,gid=1000

mount <type> <device> <dir> [ <flag>\* ] [<options>]

Attempt to mount the named device at the directory dir
_flag_s include "ro", "rw", "remount", "noatime", ...
options include "barrier=1", "noauto_da_alloc", "discard", ... as
a comma separated string, eg: barrier=1,noauto_da_alloc

It is well known for Linux developers that the command "mount" is used to connect the real file system to the directory path. This instruction tells us that it will mount the "tmpfs" filesystem to the directory path "/cores". The other three options are the same as the last section.

3 restorecon_recursive /cores

This instruction is strongly related to SELinux. Firstly we should know the command "restorecon", I think that the "restorecon_recursive" command is the recursive version of the command "restorecon". After referencing the android source official site, I guess this command can restore the security settings from SELinux for some objects(Files or Directories) after doing some filesystem's actions, such as "mount". These filesystem's operations may destroy SELinux's security settings.

References

  1. Android Init Language
  2. tmpfs
  3. Implementing SELinux
Sort:  

Congratulations @mohism! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!