[Recovery]自动挂载system分区

栏目: Android · 发布时间: 6年前

内容简介:前一篇因为原本关于挂载

前一篇 Recovery打开adb shell 里提到system目录是用来挂载系统 /system 分区的,所以是一个空目录。这一点是通过打开adb shell后,查看文件目录知道的。

因为原本 cache 目录也是空的,但是通过 shell 能看到 /cache 目录里的文件和Android系统是一致的,也就说明,这个目录是挂载进来的。因此推测 system 也应该是用来挂载的。

关于挂载 /system ,在Recovery里有实现代码动态挂载:

// bootable/recovery/recovery.cpp
case Device::MOUNT_SYSTEM:
    char system_root_image[PROPERTY_VALUE_MAX];
    property_get("ro.build.system_root_image", system_root_image, "");

    // For a system image built with the root directory (i.e.
    // system_root_image == "true"), we mount it to /system_root, and symlink /system
    // to /system_root/system to make adb shell work (the symlink is created through
    // the build system).
    // Bug: 22855115
    if (strcmp(system_root_image, "true") == 0) {
        if (ensure_path_mounted_at("/", "/system_root") != -1) {
            ui->Print("Mounted /system.\n");
        }
    } else {
        if (ensure_path_mounted("/system") != -1) {
            ui->Print("Mounted /system.\n");
        }
    }

    break;

但是实现开机挂载,我们就要去看init.rc了。

mvim /bootable/recovery/etc/init.rc

import /init.recovery.${ro.hardware}.rc

on early-init
    # Set the security context of /postinstall if present.
    restorecon /postinstall

    start ueventd
    start healthd

on init
    export ANDROID_ROOT /system
    export ANDROID_DATA /data
    export EXTERNAL_STORAGE /sdcard

    symlink /system/etc /etc

    mkdir /sdcard
    mkdir /udisk
    mkdir /system
    mkdir /data
    mkdir /cache
    mkdir /sideload
    mkdir /firmware
    mount tmpfs tmpfs /tmp

    chown root shell /tmp
    chmod 0775 /tmp

    write /proc/sys/kernel/panic_on_oops 1
    write /proc/sys/vm/max_map_count 1000000

on fs
    mkdir /dev/usb-ffs 0770 shell shell
    mkdir /dev/usb-ffs/adb 0770 shell shell
    mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000

    write /sys/class/android_usb/android0/enable 0
    write /sys/class/android_usb/android0/idVendor 18D1
    write /sys/class/android_usb/android0/idProduct D001
    write /sys/class/android_usb/android0/f_ffs/aliases adb
    write /sys/class/android_usb/android0/functions adb
    write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
    write /sys/class/android_usb/android0/iProduct ${ro.product.model}
    write /sys/class/android_usb/android0/iSerial ${ro.serialno}

首先会去访问 init.recovery.${ro.hardware}.rc 的内容,这个文件不存在,然后后面的流程也没有做mount操作。

作为对比,看一下Android系统的init文件

mvim /device/qcom/xxxx/imit.target.rc

on fs
	wait /dev/block/bootdevice
	mount_all fstab.qcom
	write /proc/sys/vm/swappiness 100

好了,Android系统启动的时候做了一个mount_all操作。来看一下fstab.qcom文件

# Android fstab file.
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

#TODO: Add 'check' as fs_mgr_flags with data partition.
# Currently we dont have e2fsck compiled. So fs check would failed.

#<src>                                                <mnt_point>  <type>  <mnt_flags and options>                     <fs_mgr_flags>
/dev/block/bootdevice/by-name/system         /system      ext4    ro,barrier=1,discard                                wait, verify
/dev/block/bootdevice/by-name/userdata       /data        ext4    nosuid,nodev,barrier=1,noauto_da_alloc,discard      wait,forceencrypt=footer
/devices/soc/7864900.sdhci/mmc_host*        /storage/sdcard1   vfat    nosuid,nodev         wait,voldmanaged=sdcard1:auto,noemulatedsd,encryptable=footer
/devices/soc/78db000.usb/msm_hsusb_host*    /storage/usbotg    vfat    nosuid,nodev         wait,voldmanaged=usbotg:auto
/dev/block/bootdevice/by-name/config         /frp  emmc    defaults                                            defaults
/dev/block/bootdevice/by-name/misc          /misc              emmc    defaults             defaults

我们的system就在这个表里。所以要挂载 system ,只需要在Recovery的init.rc添加:

wait /dev/block/bootdevice/by-name/system
mount ext4 /dev/block/bootdevice/by-name/system /system wait rw barrier=1

然后还要注意,挂载点应该(没专门验证)是空目录,所以如果在Recovery开启了shell,要把它删掉。


以上所述就是小编给大家介绍的《[Recovery]自动挂载system分区》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Algorithms in Java, Part 5

Algorithms in Java, Part 5

Robert Sedgewick / Addison-Wesley Professional / 2003-7-25 / USD 54.99

Algorithms in Java, Third Edition, Part 5: Graph Algorithms is the second book in Sedgewick's thoroughly revised and rewritten series. The first book, Parts 1-4, addresses fundamental algorithms, data......一起来看看 《Algorithms in Java, Part 5》 这本书的介绍吧!

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具