【问题标题】:Android emulator system partition no space from startAndroid模拟器系统分区从一开始就没有空间
【发布时间】:2010-04-20 13:18:53
【问题描述】:

我在使用 Android 模拟器时遇到了一个奇怪的问题。我通过 Android AVD 管理器(新创建的平台 2.1 和 API 级别 7 的模拟器)创建了一个虚拟设备。我已尝试使用标准设置并为更大 (256 MB) 设备 RAM 大小添加了硬件参数,但没有任何改变。

我需要将文件放到系统分区来测试一个项目(称为讨价还价),但由于某种原因,系统分区从一开始就没有空间。

aa a@aaa /home/haggle-0.2-android
$ adb -s emulator-5554 shell

 # df
df
/dev: 47084K total, 0K used, 47084K available (block size 4096)
/sqlite_stmt_journals: 4096K total, 0K used, 4096K available (block size 4096)
/system: 73600K total, 73600K used, 0K available (block size 4096)
/data: 65536K total, 18464K used, 47072K available (block size 4096)
/cache: 65536K total, 1156K used, 64380K available (block size 4096)

如您所见,系统分区有 0K 可用空间。当连接无根 HTC Nexus One 并执行相同操作时,我会得到以下值:

/dev: 108896K total, 0K used, 108896K available (block size 4096)
/sqlite_stmt_journals: 4096K total, 0K used, 4096K available (block size 4096)
/system: 148480K total, 116364K used, 32116K available (block size 4096)
/data: 200960K total, 22296K used, 178664K available (block size 4096)
/cache: 97280K total, 1852K used, 95428K available (block size 4096)
/sdcard: 3864064K total, 118496K used, 3745568K available (block size 32768)

为什么模拟器上的系统分区从一开始就有0K的可用空间,我该怎么做才能改变呢?即使我使用 mount/remount 使分区可写,我也会得到相同的 0K 值。

有什么建议吗?

【问题讨论】:

    标签: android emulation adb


    【解决方案1】:

    找到答案:)

    启动模拟器时可以通过 -partition-size x emulator_name 指定分区大小。

    通过终端完成。 示例:

    emulator -partition-size 125 @AVD1
    

    emulator -partition-size 125 -avd AVD1
    

    请注意,大小必须大于您当前的系统分区大小。 对于 Android4.0.3 模拟器,默认大小已经是 168,因此请将您的新分区大小设置为更大的值,例如 256

    【讨论】:

    • 有什么方法可以通过 AVD 管理器做到这一点?
    • Alt 语法:emulator -partition-size 125 -avd AVD1
    【解决方案2】:

    现在,-partition-size 更改 /system/data 分区,但不更改 /system 分区空间。

    例如,如果您想安装完整的 GApp,则需要更多空间。

    在 Unix 中执行此操作的一般过程记录在 https://unix.stackexchange.com/questions/104790/how-to-setup-a-growable-loopback-device

    简而言之:

    1. 制作一份 system.img 的副本,这样您就不会修改 SDK 中的原始文件 (cp system.img system-extended.img)
    2. 将您的system-extended.img 扩大到您想要的大小(例如,truncate system-extended.img -s 2G
    3. 调整内部 ext4 文件系统的大小(resizefs system-extended.imgresize2fs system-extended.img
    4. 通过-system <path/to/system-extended.img>参数调用模拟器时使用新的img文件。 -writable-system 参数也可能会派上用场。

    【讨论】:

    • 这个答案应该是接受的答案,因为它是唯一允许增加“/系统”分区大小的答案。
    【解决方案3】:

    我在 Android Q 上尝试@ssice 的答案时遇到了问题(如果重要的话,Android TV)。

    显然 system.img 现在是 GPT 分区磁盘映像。

    您可以通过运行file system.img 来确认这一点:

    system.img: DOS/MBR boot sector; partition 1 : ID=0xee, start-CHS (0x0,0,2), end-CHS (0x87,130,59), startsector 1, 2177023 sectors, extended partition table (last)
    

    如果您也是这种情况,那么您可以在 Linux 上执行以下操作:

    1. 调整system.img大小:truncate -s 3G system.img
    2. 重新创建分区表并创建一个跨越它的分区:
      • fdisk system.img
      • g 用于新的 GPT 分区表
      • n 用于新分区。选择分区号 1;接受将跨越整个磁盘的分区的默认值
      • w 保存更改
    $ fdisk system.img
    
    Welcome to fdisk (util-linux 2.27.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): g
    Created a new GPT disklabel (GUID: 2E6B87B6-5492-47E0-A164-A148E24445A0).
    
    Command (m for help): n
    Partition number (1-128, default 1):
    First sector (2048-6291422, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-6291422, default 6291422):
    
    Created a new partition 1 of type 'Linux filesystem' and of size 3 GiB.
    
    Command (m for help): w
    The partition table has been altered.
    Syncing disks.
    
    1. system.img 挂载为环回设备
      • losetup -fP system.img
      • losetup -a | grep system.img获取分配的/dev/loopN(例如/dev/loop1
    2. 调整文件系统大小:resize2fs /dev/loop1p1/dev/loop1 分区 1)

    【讨论】:

      【解决方案4】:

      对于从源代码构建的 Android 10 模拟器,以下解决方案运行良好:

      $ emulator -partition-size 8192 -writable-system
      

      如果模拟器在需要清除并重新构建之前已经启动:

      $ make installclean
      $ rm out/target/product/generic_x86_64/*qcow2
      $ make
      $ emulator -partition-size 8192 -writable-system
      

      aosp_car_x86_64 目标上成功测试。

      【讨论】:

        【解决方案5】:

        我发现了问题。 SDK_MANAGER 文件夹位于我的 D 盘中的非标准字符目录中 (D:/ასერ/?dwe + joan/SKD_MANAGER) 这就是为什么它无法获得正确的分区大小。我将 **SD​​K_MANAGER* 移至 D:/**SDK_MANAGER* 并解决了问题!

        (所以,谁有“无效的系统分区大小”或“恐慌:无法打开 avd1”之类的错误消息,这篇文章可能会有所帮助)

        【讨论】:

          猜你喜欢
          • 2021-05-11
          • 2011-01-15
          • 1970-01-01
          • 1970-01-01
          • 2017-10-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-08-23
          相关资源
          最近更新 更多