【问题标题】:Customize /system mountpoint on Android在 Android 上自定义 /system 挂载点
【发布时间】:2022-04-03 10:31:26
【问题描述】:

我正在尝试将 Nexus 5 更改为使用 dm-verity 模块。为此,我需要:

  1. 在引导期间 /system挂载期间调用名为veritysetup的实用程序;
  2. (此实用程序将创建一个名为 /dev/mapper/devname 的新设备);
  3. 让 /system 挂载到 /dev/mapper/devname,不是实际的分区。

看起来挂载点是在 fstab.hammerhead (device/lge/hammerhead) 上配置的。事实上,我有另一个模块通过更改这个文件来工作。所以这似乎是最简单的部分。

我知道有些文件系统是由 init.c (system/core/init) 挂载的,例如 /dev 和 /proc,而有些是由 init.hammerhead (system/core/rootdir) 挂载的,例如 /acct。但是我可以找到挂载 /system 的请求在哪里。

有什么想法吗?

【问题讨论】:

  • 我想到了 RAMDisk 修改。不能多说,因为我几乎没有触及 Linux/Android ROM 开发的皮毛。
  • 在我的情况下,确实更改引导加载程序是理想的,因为它会简化一些未来的任务。它是(我还在学习)一个位于 system/core/rootdir 上的 ramdisk。

标签: android linux security embedded-linux


【解决方案1】:

这不是正确的做法。要使用 dm-verity,我们需要:

  1. 使用“user”构建类型构建android(默认为“eng”);
  2. 更改 fstab 以在 fs_mgr_flags 中包含“verify”关键字。

因此,当 Android 时,vold 模块会找到 verity 标志并创建映射器设备。

如果系统映像具有签名哈希表和预先计算的哈希,并且根映像具有公钥,那么一切都应该正常工作。我们应该会发现系统分区挂载在 /dev/block/dm-0 而不是 /dev/block/platform/msm_sdcc.1/by-name/system 并且正在被读取时进行验证。

【讨论】:

    【解决方案2】:

    我有一个类似的询问,这里发布的答案是我找到的最相关的帖子,当然我的询问是相关的......

    有谁知道生成 fstab 文件或将 fstab 文件放入 stage1 和 stage2 引导的代码在哪里,我认为某处存在错误或文件丢失。我可以轻松更改和更新内容。 AOSP 中的哪些文件实际上需要在构建之前进行编辑,以便在将 fstab 文件打包到 ramfs 阶段 1 或阶段 2 之前对其进行修改或更改。此外,我在哪里放置内核调试参数,如“pci=nocrs”?

    *注意:此处接受的答案是根据 aosp 源文档的正确答案,但它遗漏了与源文档相同的有价值信息。在运行构建之前需要将文件放在树中的什么位置我可以看到输出确实有带有几个版本的 fstab 的供应商文件夹,但我不确定它在启动映像中的位置。

    我想在 qemu kvm 中使用墨鱼构建启动它。 完整的 kernel.log 文件在这里:https://pastebin.com/9MKFKeyN 下面有趣的部分:

    [    1.702829] init: Switching root to '/first_stage_ramdisk'
    [    1.703038] init: [libfs_mgr]ReadFstabFromDt(): failed to read fstab from dt
    [    1.703574] init: Using Android DT directory /proc/device-tree/firmware/android/
    [    1.712562] init: [libfs_mgr]Invalid ext4 superblock on '/dev/block/by-name/metadata'
    [    1.712864] traps: init[1] trap invalid opcode ip:41a6eb sp:7ffff59c93e0 error:0 in init[2f7000+200000]
    [    1.713197] init: InitFatalReboot: signal 4
    [    1.713574] init: #00 pc 000000000031b86b  /init
    [    1.713626] init: Reboot ending, jumping to kernel
    [    1.713718] kvm: exiting hardware virtualization
    [    1.788726] reboot: Restarting system with command 'bootloader'
    [    1.788872] reboot: machine restart
    

    截至 2022 年 4 月 2 日的最新 AOSP 版本

    构建道具 aosp/out/target/product/vsoc_x86_64/ramdisk/system/etc/ramdisk/build.prop

    ####################################
    # from generate-common-build-props
    # These properties identify this partition image.
    ####################################
    ro.product.bootimage.brand=generic
    ro.product.bootimage.device=vsoc_x86_64
    ro.product.bootimage.manufacturer=Google
    ro.product.bootimage.model=Cuttlefish x86_64 tv
    ro.product.bootimage.name=aosp_cf_x86_64_tv
    ro.bootimage.build.date=Sat Apr  2 12:06:36 CDT 2022
    ro.bootimage.build.date.utc=1648919196
    ro.bootimage.build.fingerprint=generic/aosp_cf_x86_64_tv/vsoc_x86_64:Tiramisu/AOSP.MASTER/me04021206:userdebug/test-keys
    ro.bootimage.build.id=AOSP.MASTER
    ro.bootimage.build.tags=test-keys
    ro.bootimage.build.type=userdebug
    ro.bootimage.build.version.incremental=eng.me.20220402.120943
    ro.bootimage.build.version.release=12
    ro.bootimage.build.version.release_or_codename=Tiramisu
    ro.bootimage.build.version.sdk=32
    # end of file
    

    fstab.ext4 /genvol/aosp/out/target/product/vsoc_x86_64/recovery/root/first_stage_ramdisk/fstab.ext4

    # Non-dynamic, boot critical partitions
    /dev/block/by-name/boot /boot emmc defaults recoveryonly,slotselect,first_stage_mount,avb=boot
    /dev/block/by-name/init_boot /init_boot emmc defaults recoveryonly,slotselect,first_stage_mount,avb=init_boot
    /dev/block/by-name/vendor_boot /vendor_boot emmc defaults recoveryonly,slotselect
    system /system erofs ro wait,logical,first_stage_mount,slotselect,avb=vbmeta_system,avb_keys=/avb
    system /system ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb=vbmeta_system,avb_keys=/avb
    # Add all non-dynamic partitions except system, after this comment
    /dev/block/by-name/userdata /data ext4 nodev,noatime,nosuid,errors=panic latemount,wait,check,quota,formattable,fileencryption=aes-256-xts:aes-256-cts,keydirectory=/metadata/vold/metadata_encryption,checkpoint=block
    /dev/block/by-name/metadata /metadata ext4 nodev,noatime,nosuid,errors=panic wait,formattable,first_stage_mount,check
    /dev/block/by-name/misc /misc emmc defaults defaults
    # Add all dynamic partitions except system, after this comment
    odm /odm erofs ro wait,logical,first_stage_mount,slotselect,avb
    odm /odm ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb
    product /product erofs ro wait,logical,first_stage_mount,slotselect,avb
    product /product ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb
    system_ext /system_ext erofs ro wait,logical,first_stage_mount,slotselect,avb=vbmeta_system
    system_ext /system_ext ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb=vbmeta_system
    vendor /vendor erofs ro wait,logical,first_stage_mount,slotselect,avb=vbmeta
    vendor /vendor ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb=vbmeta
    vendor_dlkm /vendor_dlkm erofs ro wait,logical,first_stage_mount,slotselect,avb
    vendor_dlkm /vendor_dlkm ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb
    odm_dlkm /odm_dlkm erofs ro wait,logical,first_stage_mount,slotselect,avb
    odm_dlkm /odm_dlkm ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb
    system_dlkm /system_dlkm erofs ro wait,logical,first_stage_mount,slotselect,avb=vbmeta
    system_dlkm /system_dlkm ext4 noatime,ro,errors=panic wait,logical,first_stage_mount,slotselect,avb=vbmeta
    # ZRAM, SD-Card and virtiofs shares
    /dev/block/zram0 none swap defaults zramsize=75%
    /dev/block/vdc1 /sdcard vfat defaults recoveryonly
    /devices/*/block/vdc auto auto defaults voldmanaged=sdcard1:auto,encryptable=userdata
    shared /mnt/vendor/shared virtiofs nosuid,nodev,noatime nofail
    

    如果有帮助,我还有完整的内核日志和其他信息,Vtd 和 Vtx 正在工作,并且所有 pci 都显示在 IOMMU 组中。

    acloud create --local-instance 1 --local-image 告诉我如何在失败时开始故障排除,只有在您手动构建证书文件后,因为 instance1 的 acloud 设置的那部分无法完成,我发现了那个错误,但尚未修复它的来源,这很简单 - 手动创建证书允许它继续,但在引导中的 switchroot 失败。所有硬件和qemu都表现良好。

    无法添加完整 kernel.log 的一些兴趣点

    Waiting for AVD(s) to boot up ...stop_cvd I 04-02 17:33:50 137759 137759 main.cc:162] Successfully stopped device cvd-1: 0.0.0.0:6520
    Fail! (453s)
    Total time:  (453s)
    
    
    Device summary:
    Fail in:
    Cannot create cuttlefish instance: Device did not boot within 450 secs. Stderr:
    The following files contain useful debugging information:
      Serial console is disabled; use -console=true to enable it.
      Kernel log: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/kernel.log
      Logcat output: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/logs/logcat
      Launcher log: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/logs/launcher.log
      Instance configuration: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/cuttlefish_config.json
      Instance environment: /tmp/acloud_cvd_temp/local-instance-1/.cuttlefish.sh
    Failed to read a complete exit code, read 0 bytes only instead of the expected 4
    VIRTUAL_DEVICE_BOOT_FAILED
    launch_cvd E 04-02 17:33:50 115944 115944 main.cc:252] run_cvd returned 10
    For more detail: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/launcher.log
    
    Encountered the following errors:
    Cannot create cuttlefish instance: Device did not boot within 450 secs. Stderr:
    The following files contain useful debugging information:
      Serial console is disabled; use -console=true to enable it.
      Kernel log: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/kernel.log
      Logcat output: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/logs/logcat
      Launcher log: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/logs/launcher.log
      Instance configuration: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/instances/cvd-1/cuttlefish_config.json
      Instance environment: /tmp/acloud_cvd_temp/local-instance-1/.cuttlefish.sh
    Failed to read a complete exit code, read 0 bytes only instead of the expected 4
    VIRTUAL_DEVICE_BOOT_FAILED
    launch_cvd E 04-02 17:33:50 115944 115944 main.cc:252] run_cvd returned 10
    For more detail: /tmp/acloud_cvd_temp/local-instance-1/cuttlefish_runtime/launcher.log
    
    If you have any question or need acloud team support, please feel free to contact us by email at buganizer-system+419709@google.com.
    
    
    Line 227 of kernel log: [    0.318334] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
    

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 2021-04-04
      • 1970-01-01
      • 2022-07-10
      • 2020-02-06
      • 2017-08-12
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多