https://wiki.archlinux.org/api.php?action=feedcontributions&user=Purofle&feedformat=atomArchWiki - User contributions [en]2024-03-29T10:49:25ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Ccache_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=754747Ccache (简体中文)2022-10-25T03:10:38Z<p>Purofle: Update to the latest version.</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Package development (简体中文)]]<br />
[[en:Ccache]]<br />
[[ja:Ccache]]<br />
[[pt:Ccache]]<br />
{{TranslationStatus (简体中文)|Ccache|2022-10-25|720873}}<br />
[https://ccache.dev/ Ccache] 是一个编译器的包装,它将已编译的二进制文件存储在指定位置,并将其提供给用户,以加快同一代码的重新编译。虽然第一次编译程序可能要时间长些,但随后的编译会快得多,因为不需要进行重复编译,只需要对之前存储的二进制文件进行查找。{{ic|ccache}} 与 [[GCC]] 和 [[Clang]] 兼容。<br />
<br />
== 安装 ==<br />
<br />
[[pacman|安装]] 位于 [[official repositories|官方软件仓库]] 的 {{pkg|ccache}} 软件包。<br />
<br />
== 配置 ==<br />
<br />
可以用配置文件修改默认行为,优先级由高到低为:<br />
# 环境变量 <br />
# 单个 Cache 的配置文件 ({{ic|$HOME/.config/ccache/ccache.conf}})<br />
# 系统配置文件 ({{ic|/etc/ccache.conf}})<br />
<br />
详见 {{man|1|ccache}}。<br />
<br />
=== 为 makepkg 启用 ccache ===<br />
<br />
要在 makepkg 启用 ''ccache'',请编辑 {{ic|/etc/makepkg.conf}}. 在 {{ic|BUILDENV}} 中删除 ccache 前的感叹号:<br />
BUILDENV=(fakeroot !distcc color ccache !xdelta)<br />
<br />
=== 在命令行中启用 ===<br />
<br />
<br />
如果要从中命令行编译而不是生成软件包,同样可以使用 ''ccache'' 提高速度。<br />
<br />
为此,你可以在每个编译命令前加上 {{Ic|ccache}}。<br />
<br />
$ ccache cc hello_world.c<br />
<br />
或者修改你的 {{Ic|$PATH}},在编译器的路径之前加上 ''ccache'' 的二进制文件目录。<br />
<br />
export PATH="/usr/lib/ccache/bin/:$PATH"<br />
<br />
你他可以把它设置到你的环境变量里,方便多次使用。<br />
<br />
{{Note|如果用这个方法,将同时对 ''makepkg'' 启用 ''ccache''。}}<br />
<br />
<br />
=== 启用 colorgcc 支持 ===<br />
<br />
由于 colorgcc 也是一个编译器的包装,所以需要确保包装的调用顺序是正确的。<br />
<br />
export PATH="/usr/lib/colorgcc/bin/:$PATH" # 按照正常安装 colorgcc 的情况保持不变(不要添加 ''ccache'')<br />
<br />
export CCACHE_PATH="/usr/bin" # 告诉 ''ccache'' 只使用这里的编译器<br />
<br />
''colorgcc'' 需要调用 ''ccache'' 而不是真正的编译器。编辑 {{ic|/etc/colorgcc/colorgccrc}} 修改所有 {{ic|/usr/bin}} 路径为 {{ic|/usr/lib/ccache/bin}}:<br />
{{hc|/etc/colorgcc/colorgccrc|g++: /usr/lib/ccache/bin/g++<br />
gcc: /usr/lib/ccache/bin/gcc<br />
c++: /usr/lib/ccache/bin/g++<br />
cc: /usr/lib/ccache/bin/gcc<br />
g77:/usr/bin/g77<br />
f77:/usr/bin/g77<br />
gcj:/usr/bin/gcj<br />
}}<br />
<br />
新版本的 ''ccache'' 在设置 {{ic|GCC_COLORS}} 时,将始终为GCC启用颜色支持,同时 Clang 默认启动多色输出。如果输出对象不是 TTY,''ccache'' 会让编译器生成颜色,将它们保存在缓存中,但从输出中剥离。在统一 [https://github.com/ccache/ccache/issues/224 -fdiagnostics-color] 方面仍然存在一些问题。<br />
<br />
== Misc ==<br />
<br />
{{Note|此章节未进行翻译。}}<br />
<br />
=== 修改缓存目录 ===<br />
<br />
可以将缓存目录 {{ic|~/.cache/.ccache}} 配置到其它地方,例如 SSD 或 [[ramdisk]]:<br />
<br />
要在修改当前 shell 的缓存目录:<br />
$ export CCACHE_DIR=/ramdisk/ccache<br />
<br />
要修改默认缓存目录:<br />
<br />
{{hc|~/.config/.ccache/ccache.conf|2=<br />
cache_dir = /ramdisk/ccache}}<br />
<br />
=== 设置最大缓存大小 ===<br />
<br />
默认值是 5G,可以通过配置修改:<br />
<br />
{{hc|1=/home/<user>/.ccache/ccache.conf|<br />
2=max_size = 2.0G}}<br />
<br />
=== 通过环境变量禁用缓存 ===<br />
<br />
如果你想只在当前的shell中禁用 ''ccache'':<br />
<br />
$ export CCACHE_DISABLE=1<br />
<br />
=== CLI ===<br />
<br />
<br />
此外可以使用 ‘’ccache‘’ 命令行工具。<br />
<br />
显示统计数据:<br />
$ ccache -s<br />
<br />
清空缓存:<br />
$ ccache -C<br />
<br />
=== makechrootpkg ===<br />
<br />
{{Pkg|devtools}} 中 makechrootpkg 也可以使用 ''ccache'',要在清理 chroot 后保留缓存,可以使用 ''makechrootpkg'' 的 {{ic|-d}} 选项将 cache 目录从普通系统绑定到 chroot: <br />
$ mkdir /path/of/chroot/ccache<br />
<br />
$ makechrootpkg -d /path/to/cache/:/ccache -r /path/of/chroot -- CCACHE_DIR=/ccache<br />
<br />
这样 chroot 中就可以和正常系统中一样配置和使用 ''ccache''.<br />
<br />
== 注意事项 ==<br />
<br />
''ccache'' 只有在编译 ''完全相同'' 的源代码时才有效。(或者说是预处理过的源码)<br />
<br />
在 Gentoo Linux 社区,一个基于源代码的发行版,''ccache'' 因其安慰剂效应、编译失败(由于不受欢迎的遗留对象)等而臭名昭著。Gentoo要求在报告编译失败之前关闭 ''ccache''。参见 [[Gentoo:Handbook:Parts/Working/Features#Caching compilation objects]] 和 [https://flameeyes.blog/2008/06/21/debunking-ccache-myths/ the blog post] 题为 "Debunking ccache myths",作者是 Diego Pettenò,一位前 Gentoo 开发者。<br />
<br />
== 参阅 ==<br />
<br />
*[https://ccache.dev/manual/latest.html ccache manual]</div>Puroflehttps://wiki.archlinux.org/index.php?title=AMDGPU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=737256AMDGPU (简体中文)2022-07-11T16:50:35Z<p>Purofle: 修改 ulpan</p>
<hr />
<div>[[Category:Graphics (简体中文)]]<br />
[[Category:X server (简体中文)]]<br />
[[de:AMDGPU]]<br />
[[en:AMDGPU]]<br />
[[ja:AMDGPU]]<br />
{{Related articles start (简体中文)}}<br />
{{Related|ATI (简体中文)}}<br />
{{Related|Xorg (简体中文)}}<br />
{{Related|Vulkan}}<br />
{{Related articles end}}<br />
{{TranslationStatus (简体中文)|AMDGPU|2019-09-02|581347}}<br />
'''amdgpu''' 是 AMD Radeon 显卡的开源图形驱动。<br />
<br />
== 选择正确的驱动 ==<br />
<br />
请参考[[Xorg#AMD]]选择合适的显卡驱动,这个页面包含 '''AMDGPU''' 和 '''AMDGPU PRO'''的说明。<br />
<br />
目前驱动支持[https://www.x.org/wiki/RadeonFeature/ Volcanic Islands (VI)] (和更新的显卡) 并且实验性支持 [https://www.phoronix.com/scan.php?page=news_item&px=AMD-AMDGPU-Released Sea Islands (CI)] 和 [https://www.phoronix.com/scan.php?page=news_item&px=AMDGPU-SI-Experimental-Code Southern Islands (SI)] 显卡,AMD 没有计划支持更老的 GCN GPUs。<br />
<br />
驱动不支持的显卡用户可以使用开源[[radeon]]驱动代替。<br />
<br />
== 安装 ==<br />
<br />
安装这个{{Pkg|mesa}} 软件包,它提供 DRI 和 3D 加速。<br />
<br />
* 为支持32位程序,也可以从[[multilib]]仓库中安装{{Pkg|lib32-mesa}}软件包。<br />
* 为提供 DDX 驱动 (可提供 2D 加速 在[[Xorg]]中),可以安装这个 {{Pkg|xf86-video-amdgpu}} 软件包。<br />
* 为支持 [[Vulkan]] , 可以安装 {{Pkg|vulkan-radeon}} 或 {{Pkg|amdvlk}} 软件包, 可选安装 {{Pkg|lib32-vulkan-radeon}} 或 {{Pkg|lib32-amdvlk}} 软件包来获得32位应用程序支持。一般来说更常用 {{Pkg|vulkan-radeon}} 来通过 wine/proton 运行 DirectX12 游戏,因为 amdvlk 会破坏你的 Vulkan 驱动。<br />
<br />
想要开启[[#Video acceleration|accelerated video decoding]],可以安装{{Pkg|libva-mesa-driver}}和{{Pkg|lib32-libva-mesa-driver}}软件包来支持 VA-API,安装{{Pkg|mesa-vdpau}}和{{Pkg|lib32-mesa-vdpau}}软件包支持VDPAU。<br />
<br />
=== 开启 Southern Islands (SI) and Sea Islands (CIK) 支持 ===<br />
<br />
{{Pkg|linux}} 软件包 可以开启 AMDGPU 支持对于 the Southern Islands (SI) 和 Sea Islands (CIK)的显卡。 当编译和构建一个 [[kernels (简体中文)]], 需要设置{{ic|1=CONFIG_DRM_AMDGPU_SI=Y}} 和 {{ic|1=CONFIG_DRM_AMDGPU_CIK=Y}} 参数。<br />
<br />
==== 指定正确的模块加载顺序 ====<br />
<br />
当内核启用 AMDGPU 对 SI/CIK 显卡的支持时,[[radeon]]驱动可能会在{{ic|amdgpu}}驱动之前加载。 <br />
<br />
确保{{ic|amdgpu}}在[[Mkinitcpio#MODULES]]数组中被设置为第一个模块,例如{{ic|1=MODULES=(amdgpu radeon)}}。<br />
<br />
==== 设置所需的模块参数 ====<br />
{{ic|amdgpu}} 和 {{ic|radeon}}模块都需要设置的[[module parameters]]是{{ic|1=cik_support=}} and {{ic|1=si_support=}}。<br />
<br />
它们必需设置为内核参数或者在一个''modprobe''配置文件中,并且取决于显卡的 GCN 版本。<br />
<br />
{{Tip (简体中文)|[[dmesg]]可能会指示应该使用的正确内核参数: {{ic|1=[..] amdgpu 0000:01:00.0: Use radeon.cik_support=0 amdgpu.cik_support=1 to override}}.}}<br />
<br />
===== 在内核命令行中设置模块参数 =====<br />
<br />
设置以下 [[kernel parameters]]之一:<br />
<br />
* Southern Islands (SI): {{ic|1=radeon.si_support=0 amdgpu.si_support=1}}<br />
* Sea Islands (CIK): {{ic|1=radeon.cik_support=0 amdgpu.cik_support=1}}<br />
<br />
===== 设置内核参数在 modprobe.d 中 =====<br />
<br />
在 {{ic|/etc/modprobe.d/}}中创建配置 [[modprobe]] 文件, 查看 {{man|5|modprobe.d}} 可以了解语法细节。<br />
<br />
对于 Southern Islands (SI) 使用 {{ic|1=si_support=1}} 选项,对于 Sea Islands (CIK) 使用 {{ic|1=cik_support=1}} 选项,就像下面的例子一样:<br />
<br />
{{hc|/etc/modprobe.d/amdgpu.conf|2=<br />
options amdgpu si_support=1<br />
options amdgpu cik_support=0<br />
}}<br />
<br />
{{hc|/etc/modprobe.d/radeon.conf|2=<br />
options radeon si_support=0<br />
options radeon cik_support=0<br />
}}<br />
<br />
确保 {{ic|modconf}} 添加到 {{ic|HOOKS}} 数组中在 {{ic|/etc/mkinitcpio.conf}} 和 [[regenerate the initramfs]]。<br />
<br />
=== AMDGPU PRO ===<br />
AMD 提供一个叫 ''AMDGPU PRO'' 的专有二进制用户驱动,它工作于开源驱动 AMDGPU 之上。<br />
<br />
From [https://www.phoronix.com/vr.php?view=27266 Radeon Software 18.50 vs Mesa 19 benchmarks] article: When it comes to OpenGL games, the RadeonSI Gallium3D driver simply dominates the proprietary AMD OpenGL driver. About the only advantage to the closed-source AMD OpenGL driver is its support for GL 4.6 while RadeonSI is still limited to GL 4.5 until its SPIR-V ingestion support is completed.<br />
<br />
安装 {{AUR|amdgpu-pro-libgl}}软件包, 也可以安装 {{AUR|lib32-amdgpu-pro-libgl}} 软件包提供32位程序支持。<br />
== 加载 ==<br />
<br />
应该会在系统启动时自动加载。<br />
<br />
如果没有自动加载:<br />
<br />
* 如果需要的话,确保 [[#开启 Southern Islands (SI) and Sea Islands (CIK) 支持]]。<br />
* 确保你已经安装最新的 {{Pkg|linux-firmware}} 软件包。<br />
* 确保你没有将 {{ic|nomodeset}} 或 {{ic|1=vga=}} 作为内核参数,因为{{ic|amdgpu}} 需要 [[KMS]]。<br />
* 确保你没有禁用 {{ic|amdgpu}} 通过使用 [[Kernel_modules#Blacklisting|kernel module blacklisting]]。<br />
<br />
=== Enable early KMS ===<br />
See [[Kernel mode setting#Early KMS start]].<br />
<br />
== Xorg configuration ==<br />
<br />
[[Xorg]] will automatically load the driver and it will use your monitor's EDID to set the native resolution. Configuration is only required for tuning the driver.<br />
<br />
If you want manual configuration, create {{ic|/etc/X11/xorg.conf.d/20-amdgpu.conf}}, and add the following:<br />
<br />
{{hc|/etc/X11/xorg.conf.d/20-amdgpu.conf|2=<br />
Section "Device"<br />
Identifier "AMD"<br />
Driver "amdgpu"<br />
EndSection<br />
}}<br />
<br />
Using this section, you can enable features and tweak the driver settings, see {{man|4|amdgpu}} first before setting driver options.<br />
<br />
=== Tear Free Rendering ===<br />
''TearFree'' controls tearing prevention using the hardware page flipping mechanism. If this option is set, the default value of the property is 'on' or 'off' accordingly. If this option isn't set, the default value of the property is auto, which means that TearFree is on for rotated outputs, outputs with RandR transforms applied and for RandR 1.4 slave outputs, otherwise off:<br />
<br />
Option "TearFree" "true"<br />
<br />
=== DRI level ===<br />
<br />
''DRI'' sets the maximum level of DRI to enable. Valid values are ''2'' for DRI2 or ''3'' for DRI3. The default is ''3'' for DRI3 if the [[Xorg]] version is >= 1.18.3, otherwise DRI2 is used:<br />
<br />
Option "DRI" "3"<br />
<br />
=== Variable refresh rate ===<br />
See [[Variable refresh rate]].<br />
<br />
== Features ==<br />
=== Video acceleration ===<br />
<br />
See [[Hardware video acceleration]].<br />
<br />
=== Overclocking ===<br />
<br />
Since Linux 4.17, it is possible to adjust clocks and voltages of the graphics card via {{Ic|1=/sys/class/drm/card0/device/pp_od_clk_voltage}}. It is however required to unlock access to it in sysfs by appending the boot parameter {{Ic|1=amdgpu.ppfeaturemask=0xffffffff}}.<br />
<br />
{{Note (简体中文)|In sysfs, paths like {{Ic|1=/sys/class/drm/...}} are just symlinks and may change between reboots. Persistent locations can be found in {{Ic|1=/sys/devices/}}, e.g. {{Ic|1=/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/}}. Adjust the commands accordingly for a reliable result.}}<br />
<br />
To set the GPU clock for the maximum pstate 7 on e.g. a Polaris GPU to 1209MHz and 900mV voltage, run:<br />
# echo "s 7 1209 900" > /sys/class/drm/card0/device/pp_od_clk_voltage<br />
The same procedure can be applied to the VRAM, e.g. maximum pstate 2 on Polaris 5xx series cards:<br />
# echo "m 2 1850 850" > /sys/class/drm/card0/device/pp_od_clk_voltage<br />
{{Warning (简体中文)|1=Double check the entered values, as mistakes might instantly cause fatal hardware damage!}}<br />
To apply, run<br />
# echo "c" > /sys/class/drm/card0/device/pp_od_clk_voltage<br />
To check if it worked out, read out clocks and voltage under 3D load:<br />
# watch -n 0.5 cat /sys/kernel/debug/dri/0/amdgpu_pm_info<br />
You can reset to the default values using this:<br />
# echo "r" > /sys/class/drm/card0/device/pp_od_clk_voltage<br />
<br />
It is also possible to forbid the driver so switch to certain pstates, e.g. to workaround problems with deep powersaving pstates like flickering artifacts or stutter. To force the highest VRAM pstate on a Polaris RX 5xx card, while still allowing the GPU itself to run with lower clocks, run:<br />
# echo "manual" > /sys/class/drm/card0/device/power_dpm_force_performance_level<br />
# echo "2" > /sys/class/drm/card0/device/pp_dpm_mclk<br />
Allow only the three highest GPU pstates:<br />
# echo "5 6 7" > /sys/class/drm/card0/device/pp_dpm_sclk<br />
<br />
To set the allowed maximum power consumption of the GPU to e.g. 50 Watts, run<br />
# echo 50000000 > /sys/class/drm/card0/device/hwmon/hwmon0/power1_cap<br />
Until Linux kernel 4.20, it will only be possible to decrease the value, not increase.<br />
<br />
{{Note (简体中文)|The above procedure was tested with a Polaris RX 560 card. There may be different behavior or bugs with different GPUs.}}<br />
<br />
=== Enable GPU display scaling ===<br />
<br />
To avoid the usage of the scaler which is built in the display, and use the GPU own scaler instead, when not using the native resolution of the monitor, execute:<br />
$ xrandr --output "<output>" --set "scaling mode" "<scaling mode>"<br />
Possible values for {{ic|"scaling mode"}} are: {{ic|None, Full, Center, Full aspect}}<br />
<br />
* To show the available outputs and settings, execute:<br />
$ xrandr --prop<br />
<br />
* To set {{ic|1=scaling mode = Full aspect}} for just every available output, execute:<br />
$ for output in $(xrandr --prop | grep -E -o -i "^[A-Z\-]+-[0-9]+"); do xrandr --output "$output" --set "scaling mode" "Full aspect"; done<br />
<br />
== Troubleshooting ==<br />
<br />
=== Xorg or applications won't start ===<br />
<br />
* "(EE) AMDGPU(0): [DRI2] DRI2SwapBuffers: drawable has no back or front?" error after opening glxgears, can open Xorg server but OpenGL apps crash.<br />
* "(EE) AMDGPU(0): Given depth (32) is not supported by amdgpu driver" error, Xorg won't start.<br />
<br />
Setting the screen's depth under Xorg to 16 or 32 will cause problems/crash. To avoid that, you should use a standard screen depth of 24 by adding this to your "screen" section:<br />
<br />
{{hc|/etc/X11/xorg.conf.d/10-screen.conf|<br />
Section "Screen"<br />
Identifier "Screen"<br />
DefaultDepth 24<br />
SubSection "Display"<br />
Depth 24<br />
EndSubSection<br />
EndSection<br />
}}<br />
<br />
=== Screen artifacts and frequency problem ===<br />
<br />
[[ATI#Dynamic power management|Dynamic power management]] may cause screen artifacts to appear when displaying to monitors at higher frequencies (120+Hz) due to issues in the way GPU clock speeds are managed[https://bugs.freedesktop.org/show_bug.cgi?id=96868][https://bugs.freedesktop.org/show_bug.cgi?id=102646].<br />
<br />
A workaround [https://bugs.freedesktop.org/show_bug.cgi?id=96868#c13] is saving {{ic|high}} or {{ic|low}} in {{ic|/sys/class/drm/card0/device/power_dpm_force_performance_level}}.<br />
<br />
There is also a GUI solution [https://github.com/marazmista/radeon-profile] where you can manage the "power_dpm" with {{aur|radeon-profile-git}} and {{aur|radeon-profile-daemon-git}}.<br />
<br />
=== R9 390 series Poor Performance and/or Instability ===<br />
<br />
If you experience issues [https://bugs.freedesktop.org/show_bug.cgi?id=91880] with a AMD R9 390 series graphics card, set {{ic|1=radeon.cik_support=0 radeon.si_support=0 amdgpu.cik_support=1 amdgpu.si_support=1 amdgpu.dpm=1 amdgpu.dc=1}} as [[kernel parameters]] to force the use of amdgpu driver instead of radeon.<br />
<br />
If it still does not work, try disabling DPM, by setting the [[kernel parameters]] to: {{ic|1=radeon.cik_support=0 radeon.si_support=0 amdgpu.cik_support=1 amdgpu.si_support=1}}<br />
<br />
=== Freezes with "[drm] IP block:gmc_v8_0 is hung!" kernel error ===<br />
<br />
If you experience freezes and kernel crashes during a GPU intensive task with the kernel error " [drm] IP block:gmc_v8_0 is hung!" [https://bugs.freedesktop.org/show_bug.cgi?id=102322], a workaround is to set {{ic|1=amdgpu.vm_update_mode=3}} as [[kernel parameters]] to force the GPUVM page tables update to be done using the CPU. Downsides are listed here [https://bugs.freedesktop.org/show_bug.cgi?id=102322#c15].<br />
<br />
=== Cursor corruption ===<br />
<br />
If you experience issues with the mouse cursor sometimes not rendering properly, set {{ic|Option "SWCursor" "True"}} in the {{ic|"Device"}} section of the {{ic|/etc/X11/xorg.conf.d/20-amdgpu.conf}} configuration file.<br />
<br />
If you are using {{ic|xrandr}} for scaling and the cursor is flickering or disappearing, you may be able to fix it by setting the {{ic|TearFree}} property: {{ic|xrandr --output HDMI-A-0 --set TearFree on}}.</div>Puroflehttps://wiki.archlinux.org/index.php?title=User:Purofle&diff=696633User:Purofle2021-09-19T08:30:38Z<p>Purofle: Created blank page</p>
<hr />
<div></div>Puroflehttps://wiki.archlinux.org/index.php?title=Anbox_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=690319Anbox (简体中文)2021-08-02T03:41:09Z<p>Purofle: </p>
<hr />
<div>[[Category:Virtualization_(简体中文)]]<br />
[[Category:Android (简体中文)]]<br />
[[en:Anbox]]<br />
[[ja:Anbox]]<br />
[[ru:Anbox]]<br />
[[zh-hans:Anbox]]<br />
{{Related articles start}}<br />
{{Related|Linux Containers}}<br />
{{Related articles end}}<br />
{{Bad translation (简体中文)|部分内容可能由机器翻译。}}<br />
{{TranslationStatus (简体中文)|Anbox|2021-08-02|28657}}<br />
Anbox 是一个可以在 GNU/Linux 发行版上运行 Android App 的一个 [[Linux_Containers|容器]]。<br />
<br />
== 准备工作 ==<br />
<br />
{{Note|Anbox 的 dkms 模块在内核版本 ≥5.7 下不会工作。请按照以下说明进行操作。 对于较老的内核请参阅 [[#较老的内核|较老的内核]]。}}<br />
<br />
您需要运行带有 ashmem 和 binder 模块的内核。但是它们不是 Arch Linux 的默认内核 ( linux ) 的一部分,所以您需要安装一个包含这些模块的内核。<br />
<br />
您可能还需要配置引导加载程序以使用不同的内核。<br />
<br />
您有多种选择:<br />
<br />
=== 使用 Linux-Zen ===<br />
<br />
{{Pkg|linux-zen}} 内核自带 Anbox 需要的模块。这可能是最简单的方式,因为您不必编译内核并且版本会定期更新。<br />
<br />
=== 编译内核 ===<br />
<br />
当然,您也可以自己重新编译 {{Pkg|linux}} 内核。请阅读 [[Kernel_(简体中文)#编译]] and [[#配置模块|配置模块]] 。<br />
<br />
您还可以从[[AUR]]里构建一个已经包含特定补丁的内核包, 请参阅 [https://aur.archlinux.org/packages/?K=linux+anbox AUR search "linux+anbox"].<br />
<br />
==== 配置模块 ====<br />
<br />
模块同样也可以被编译进内核里 ({{ic|y}}), 模块里 ({{ic|m}}), 或者不编译 ({{ic|n}}).此外,并非配置中的所有组合都是可能的,某些选项将需要其他选项。<br />
<br />
下面的的内核配置将把 ashmem 和 binder 编译为模块,而最后一个选项指定在 {{ic|/dev/}} 加载 binder 模块时在目录中创建三个设备。<br />
<br />
{{bc|1=<br />
CONFIG_ASHMEM=m <br />
CONFIG_ANDROID=y<br />
CONFIG_ANDROID_BINDER_IPC=m<br />
CONFIG_ANDROID_BINDERFS=n<br />
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"<br />
}}<br />
<br />
如果您要从 AUR 构建内核,那么您可以参考下面的步骤:<br />
<br />
# 运行 {{ic|makepkg --nobuild}}, 它将下载源代码,验证并提取。最后运行 {{ic|prepare()}} 函数.<br />
# 编辑位于内核目录底部的 {{ic|.config}} 文件。<br />
# 在 {{ic|prepare()}} 函数的末尾可能是一个命令,它使用来自配置的信息重新生成 makefile,也可能是 {{ic|make olddefconfig}}. 将它移动到 {{ic|build()}} 函数内,或自己执行一遍。<br />
# 运行 {{ic|makepkg --noextract}}, 它将在 {{ic|makepkg --nobuild}} 停止的地方继续。<br />
<br />
==== 使用 binderfs 进行配置 ====<br />
<br />
并不是每个人都对 Linux 中的 binder 模块感到满意。为了解决这些问题,binderfs诞生了。编译内核时必须在新旧两种方式之间进行选择。比如下面的选项就是针对于 binderfs 的。<br />
<br />
内核源代码还提供了一个简单的脚本来设置配置选项。它不会进行依赖项检查。当您在 {{ic|.config}} 文件所在的同一目录中时,执行以下命令:<br />
<br />
{{bc|<br />
scripts/config --module CONFIG_ASHMEM<br />
scripts/config --enable CONFIG_ANDROID<br />
scripts/config --enable CONFIG_ANDROID_BINDER_IPC<br />
scripts/config --enable CONFIG_ANDROID_BINDERFS<br />
scripts/config --set-str CONFIG_ANDROID_BINDER_DEVICES ""<br />
}}<br />
<br />
当您正在从从 AUR 构建内核时,这个脚本很方便,因为只需要在 PKGBUILD 中的正确位置插入这些命令就足够了。<br />
<br />
=== 启动新内核 ===<br />
<br />
请参阅引导加载程序的 wiki 页面了解如何使用新内核引导。您应该在启动 Anbox 之前切换到心的内核。<br />
<br />
== 安装 ==<br />
<br />
=== 加载模块 ===<br />
<br />
Anbox 不会自动加载模块,但是如果您在使用 linux-ken,就可以跳过此步骤。<br />
<br />
要临时加载,请使用:<br />
<br />
# modprobe -a binder-linux ashmem-linux<br />
<br />
要始终在启动时加载它们,可以通过 {{ic|systemd-modules-load.service}} 文件来实现。 为此,请在 {{ic|/etc/modules-load.d/}} 创建一个包含以下内容的 anbox.conf文件:<br />
<br />
{{hc|/etc/modules-load.d/anbox.conf|<br />
ashmem_linux<br />
binder_linux<br />
}}<br />
<br />
=== 挂载 binderfs ===<br />
<br />
{{Note | {{pkg|linux-zen}} 内核必须挂载 binderfs。 }}<br />
<br />
如果您的内核正在使用 binderfs,则还有一个步骤要做:挂载 binderfs 文件。<br />
<br />
首先,您需要一个挂载点。默认情况下,Anbox 将使用 {{ic|/dev/binderfs}}。 您可以直接创建该目录,但它会在启动时被删除。所以这里建议使用 [[systemd-tmpfiles]] 实现在启动时创建 {{ic|/dev/binderfs}}。为此,您需要在 {{ic|/etc/tmpfiles.d/}} 创建一个包含以下内容的文件:<br />
<br />
{{hc|/etc/tmpfiles.d/anbox.conf|<br />
d! /dev/binderfs 0755 root root<br />
}}<br />
<br />
其次您需要挂载 binder 文件系统。 这可以通过:<br />
<br />
# mount -t binder none /dev/binderfs<br />
<br />
如果想要在启动时挂载它,只需要在 [[fstab]] 中添加下面这一行。<br />
<br />
{{hc|/etc/fstab|<br />
none /dev/binderfs binder nofail 0 0<br />
}}<br />
<br />
{{警告|添加 {{ic|nofail}} 参数后,当您启动没有 binderfs 支持的内核时,您将无法进入恢复 shell。}}<br />
<br />
== 安装 Android 镜像 ==<br />
<br />
{{Note|现在的镜像均以过时 (基于 Android 7.1). 目前,上游没有可用的更新的镜像。另请参阅 [[Talk:Anbox#Anbox-Images outdated]].}}<br />
<br />
选择一个镜像来安装:<br />
<br />
* {{AUR|anbox-image}} (官方镜像)<br />
* {{AUR|anbox-image-houdini}} (包含 Houdini)<br />
* {{AUR|anbox-image-houdini-rooted}} (包含 Houdini 和 SuperSU) <br />
* {{AUR|anbox-image-gapps}} (包含 Houdini 和 OpenGApps) <br />
* {{AUR|anbox-image-gapps-rooted}} (包含 Houdini, OpenGApps 和 SuperSU) <br />
* 您也可以通过在 [[AUR]] 内搜索 [https://aur.archlinux.org/packages/?K=anbox-image anbox-image]找到更多的镜像。<br />
<br />
{{Tip |<br />
* 通常,在 x86_64 计算机上运行 ARM 应用程序需要 Houdini。<br />
* 如果您使用 GMS,OpenGApps 是一个不错的选择。}}<br />
<br />
=== 安装 Anbox ===<br />
<br />
安装 {{AUR|anbox-git}}。<br />
<br />
然后, [[start/enable]] {{ic|anbox-container-manager.service}}.<br />
<br />
恭喜您现在已经完成了使用 Anbox 所需的所有步骤!在您的桌面环境菜单中,您应该会在 Others 类别中找到 anbox。<br />
第一次启动将花费很长的时间,anbox session-manager将会被自动打开。当然,您也可以手动执行 {{ic|anbox session-manager}} 。如果 anbox 崩溃并且您想报告或修复这个错误,这将'''非常'''有用。只需启动它,然后等到它崩溃。<br />
<br />
还有一个给用户使用的''systemd'' unit,可用于在开机时启动 session-manager;如果你想这么干,只需要 [[start/enable]] {{ic|anbox-session-manager.service}}。该 unit 的一个优点是可以在崩溃时找到日志:<br />
<br />
$ journalctl --user -b -u anbox-session-manager<br />
<br />
但是请记住,如果您打开一个 Android app 时崩溃崩溃了,它将会再启动一个独立于''systemed''的 session-manager。<br />
<br />
== 网络 ==<br />
<br />
=== 使用 NetworkManager ===<br />
<br />
如果您正在使用 [[NetworkManager]] ,则可以使用它来配置网络。<br />
<br />
执行以下命令来创建 bridge connection:<br />
<br />
$ nmcli con add type bridge ifname anbox0 -- connection.id anbox-net ipv4.method shared ipv4.addresses 192.168.250.1/24<br />
<br />
* {{ic|ifname anbox0}} 指定网桥接口名称,在本例中为 {{ic|anbox0}}. 不要改变这个名称,因为 Anbox 仅会在名为 {{ic|anbox0}} 的网桥接口。<br />
* {{ic|connection.id anbox-net}} specifies the name of the connection to be {{ic|anbox-net}} when it appears in [[NetworkManager]]. You can change this if you wish.<br />
* {{ic|ipv4.method shared}} instructs [[NetworkManager]] to create a NAT network and route outgoing packets according to the system routing rules. For that, the {{Pkg|dnsmasq}} package is required. [[dnsmasq]] does not needs to be configured or be started as systemd service, it will be used behind the scenes by NetworkManager — if it is not available, this step will fail silently. You can leave this and the {{ic|ipv4.addresses}} parameter out if you wish to attach the Anbox container directly to a specific network, see [[Network bridge#With NetworkManager]]. If you choose this option, you must also change the network configuration of the container in {{ic|anbox-container-manager.service}}, see the next bullet point.<br />
* {{ic|ipv4.addresses 192.168.250.1/24}} specifies the default gateway and subnet of the NAT network. If you wish to change this (e.g. to {{ic|192.168.42.1/24}}) you must also indicate the new subnet to anbox in the {{ic|anbox-container-manager.service}} using: {{ic|1=--container-network-address=192.168.42.2/24 --container-network-gateway=192.168.42.1}}<br />
<br />
[[NetworkManager]] 将在每次重新启动时自动设置网桥,因此您只需要执行一次命令。<br />
=== Via systemd-networkd ===<br />
<br />
The package {{AUR|anbox-git}} provides configuration files for {{ic|systemd-networkd}} in {{ic|/usr/lib/systemd/network/}} to enable networking in anbox.<br />
<br />
Therefore, you can [[start/enable]] {{ic|systemd-networkd}} before starting {{ic|anbox-container-manager.service}}.<br />
<br />
=== Via anbox-bridge script ===<br />
<br />
Alternatively you can use the anbox-bridge script [https://raw.githubusercontent.com/anbox/anbox/master/scripts/anbox-bridge.sh used by the project].<br />
<br />
You must execute {{ic|anbox-bridge}} every time before starting {{ic|anbox-container-manager.service}} in order to get network working in Anbox. The easiest solution for that is to create a drop-in file for the service.<br />
<br />
{{hc|/etc/systemd/system/anbox-container-manager.service.d/enable-anbox-bridge.conf|2= <br />
[Service]<br />
ExecStartPre=/usr/bin/anbox-bridge start<br />
ExecStopPost=/usr/bin/anbox-bridge stop<br />
}}<br />
<br />
== Usage ==<br />
<br />
You can run the Android applications on your desktop's launcher on '''Other''' category.<br />
<br />
If you want to use [[adb]] to debug, install {{Pkg|android-tools}}. The {{ic|anbox session-manager}} must already be running when launching it.<br />
<br />
$ adb shell<br />
<br />
=== Installing apps ===<br />
<br />
Unless you picked an image with Houdini, Anbox does not have support for ARM applications. So apps must have a x86_64 architecture.<br />
<br />
==== Through adb ====<br />
<br />
To install {{ic|''/path/to/app.apk''}}<br />
<br />
$ adb install ''/path/to/app.apk''<br />
<br />
To get the list of installed applications<br />
<br />
$ adb shell pm list packages<br />
<br />
Note that output will be similar to {{ic|''package:app.name''}}, where {{ic|''app.name''}} is different from the one displayed in the Anbox container.<br />
<br />
To uninstall {{ic|''app.name''}}<br />
<br />
$ adb uninstall ''app.name''<br />
<br />
If {{ic|''app.name''}} is a system app<br />
<br />
$ adb uninstall --user 0 ''app.name''<br />
<br />
==== Through apps stores ====<br />
<br />
Apps can be easily installed through apps stores. In {{AUR|anbox-image-gapps}} PlayStore is included.<br />
<br />
=== Sensor data ===<br />
<br />
Via dbus different sensors can be set. Documentation on that can be found at<br />
[https://github.com/anbox/anbox/blob/master/docs/dbus.md dbus.md].<br />
<br />
==== Temperature data ====<br />
<br />
That is the example from the author (PRs [https://github.com/anbox/anbox/pull/1522 #1522] & [https://github.com/anbox/anbox/pull/1522 #1540]):<br />
<br />
$ dbus-send --session --dest=org.anbox --print-reply /org/anbox org.freedesktop.DBus.Properties.Set string:org.anbox.Sensors string:Temperature variant:double:25.1<br />
<br />
==== GPS data ====<br />
<br />
(introduced by PR [https://github.com/anbox/anbox/pull/1606 #1606])<br />
<br />
GPS sensor data can also be manipulated. <br />
<br />
If your PC has a WWAN card, you can use {{Pkg|gpsd}} and the code from the PR to feed Anbox with GPS data. You do not need to have a SIM-Card for GPS.<br />
<br />
Otherwise, you can also look at the PR to learn how to feed it fake data with the help of [https://www.nmeagen.org].<br />
<br />
=== Root shell ===<br />
<br />
With this [https://github.com/anbox/anbox/blob/master/scripts/anbox-shell.sh script] from the Anbox project one can get a root shell inside the Android container.<br />
<br />
It is not part of the {{AUR|anbox-git}} package, and it also does not use [[adb]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Android developer options ===<br />
<br />
Some extra steps need to be done besides unlocking them the same way you do on an android phone.<br />
When installing the [[#Install Android Image|android image]], some modifications to {{ic|products/anbox.xml}} are required:<br />
<br />
* {{ic|1=<unavailable-feature name="android.hardware.usb.host" />}} is the reason why they are not available.<br />
* {{ic|1=<feature name="android.software.backup" />}} will be needed too, to avoid a NullPointerException.<br />
<br />
(reference: [https://github.com/anbox/anbox/issues/444 Github issue #444])<br />
<br />
=== Getting debugging information ===<br />
<br />
Obviously, it is helpful to have debugging symbols in the Anbox build. For that, when [[#Install Anbox|compiling Anbox]], add {{ic|1=options=('!strip')}} to the PKGBUILD, as by default they are removed. And, use either {{ic|1=-DCMAKE_BUILD_TYPE=RelWithDebInfo}} or {{ic|1=-DCMAKE_BUILD_TYPE=Debug}} in the cmake call.<br />
<br />
But there is more to it! Anbox uses [https://github.com/anbox/anbox/tree/master/external/backward-cpp backward-cpp]. If you do not delete the build files for Anbox, it will print pretty stack traces when crashing, which point out the places in the source code.<br />
<br />
Also see the remarks in [[#Install Anbox|Install Anbox]].<br />
<br />
== Troubleshooting ==<br />
<br />
If you run into issues, take a look at the official Issue Tracker: [https://github.com/anbox/anbox/issues]<br />
<br />
=== Old CPUs ===<br />
<br />
Anbox requires support for SSE 4.1/4.2 and SSSE 3, because Android wants that too.<br />
Some older CPUs do not provide that, so you probably cannot use Anbox, see:<br />
[https://github.com/anbox/anbox/issues/499#issuecomment-399118684 Anbox Github Issue 499].<br />
<br />
=== Old kernels ===<br />
<br />
Before the kernel modules were mainlined, they were out of tree modules, which needed to be installed seperately from the kernel (Like it is the case for the nvidia kernel modules). They are not compatible with kernel 5.7 or newer.<br />
<br />
It is still possible to use that approach with the {{Pkg|linux-lts}} or other old kernels. The package to install the modules via [[DKMS]] is not available in the AUR anymore, but can be retrieved with {{ic|<nowiki>git clone https://aur.archlinux.org/anbox-modules-dkms</nowiki>}}, or resurected from [https://aur.archlinux.org/cgit/aur.git/commit/?h=anbox-git&id=0c9a9385694e680f5b277ca6f9326ad5d5df7dd3].<br />
<br />
=== Secure Boot error ===<br />
<br />
If you get this error message:<br />
<br />
modprobe: ERROR: could not insert 'ashmem_linux': Operation not permitted<br />
<br />
[[Secure Boot]] is likely blocking the module.<br />
You can either disable Secure Boot or sign the ashmem module yourself.<br />
<br />
More info can be found in the [https://github.com/anbox/anbox/blob/master/docs/install.md#on-ubuntu-1904-and-later Anbox Github Docs].<br />
<br />
== See also ==<br />
<br />
* [https://github.com/anbox/anbox Official Anbox Github Repo]<br />
* [https://anbox.io/ Anbox Website]<br />
* [https://mm.gravedo.de/blog/posts/2020-01-21-taking-the-anbox-journey-to-the-next-level Posting by the main Anbox developer]<br />
* [https://brauner.github.io/2019/01/09/android-binderfs.html Explanation about binderfs]</div>Puroflehttps://wiki.archlinux.org/index.php?title=Anbox_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=690300Anbox (简体中文)2021-08-02T01:08:13Z<p>Purofle: 删除重复内容</p>
<hr />
<div>[[Category:Virtualization_(简体中文)]]<br />
[[Category:Android (简体中文)]]<br />
[[en:Anbox]]<br />
[[ja:Anbox]]<br />
[[ru:Anbox]]<br />
[[zh-hans:Anbox]]<br />
{{Related articles start}}<br />
{{Related|Linux Containers}}<br />
{{Related articles end}}<br />
{{Bad translation (简体中文)|部分内容可能由机器翻译。}}<br />
{{TranslationStatus (简体中文)|Anbox|2021-08-02|28657}}<br />
Anbox 是一个可以在 GNU/Linux 发行版上运行 Android App 的一个 [[Linux_Containers|容器]]。<br />
<br />
== 准备工作 ==<br />
<br />
{{Note|Anbox 的 dkms 模块在内核版本 ≥5.7 下不会工作。请按照以下说明进行操作。 对于较老的内核请参阅 [[#较老的内核|较老的内核]]。}}<br />
<br />
您需要运行带有 ashmem 和 binder 模块的内核。但是它们不是 Arch Linux 的默认内核 ( linux ) 的一部分,所以您需要安装一个包含这些模块的内核。<br />
<br />
您可能还需要配置引导加载程序以使用不同的内核。<br />
<br />
您有多种选择:<br />
<br />
=== 使用 Linux-Zen ===<br />
<br />
{{Pkg|linux-zen}} 内核自带 Anbox 需要的模块。这可能是最简单的方式,因为您不必编译内核并且版本会定期更新。<br />
<br />
=== 编译内核 ===<br />
<br />
当然,您也可以自己重新编译 {{Pkg|linux}} 内核。请阅读 [[Kernel_(简体中文)#编译]] and [[#配置模块|配置模块]] 。<br />
<br />
您还可以从[[AUR]]里构建一个已经包含特定补丁的内核包, 请参阅 [https://aur.archlinux.org/packages/?K=linux+anbox AUR search "linux+anbox"].<br />
<br />
==== 配置模块 ====<br />
<br />
模块同样也可以被编译进内核里 ({{ic|y}}), 模块里 ({{ic|m}}), 或者不编译 ({{ic|n}}).此外,并非配置中的所有组合都是可能的,某些选项将需要其他选项。<br />
<br />
下面的的内核配置将把 ashmem 和 binder 编译为模块,而最后一个选项指定在 {{ic|/dev/}} 加载 binder 模块时在目录中创建三个设备。<br />
<br />
{{bc|1=<br />
CONFIG_ASHMEM=m <br />
CONFIG_ANDROID=y<br />
CONFIG_ANDROID_BINDER_IPC=m<br />
CONFIG_ANDROID_BINDERFS=n<br />
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"<br />
}}<br />
<br />
如果您要从 AUR 构建内核,那么您可以参考下面的步骤:<br />
<br />
# 运行 {{ic|makepkg --nobuild}}, 它将下载源代码,验证并提取。最后运行 {{ic|prepare()}} 函数.<br />
# 编辑位于内核目录底部的 {{ic|.config}} 文件。<br />
# 在 {{ic|prepare()}} 函数的末尾可能是一个命令,它使用来自配置的信息重新生成 makefile,也可能是 {{ic|make olddefconfig}}. 将它移动到 {{ic|build()}} 函数内,或自己执行一遍。<br />
# 运行 {{ic|makepkg --noextract}}, 它将在 {{ic|makepkg --nobuild}} 停止的地方继续。<br />
<br />
==== 使用 binderfs 进行配置 ====<br />
<br />
并不是每个人都对 Linux 中的 binder 模块感到满意。为了解决这些问题,binderfs诞生了。编译内核时必须在新旧两种方式之间进行选择。比如下面的选项就是针对于 binderfs 的。<br />
<br />
内核源代码还提供了一个简单的脚本来设置配置选项。它不会进行依赖项检查。当您在 {{ic|.config}} 文件所在的同一目录中时,执行以下命令:<br />
<br />
{{bc|<br />
scripts/config --module CONFIG_ASHMEM<br />
scripts/config --enable CONFIG_ANDROID<br />
scripts/config --enable CONFIG_ANDROID_BINDER_IPC<br />
scripts/config --enable CONFIG_ANDROID_BINDERFS<br />
scripts/config --set-str CONFIG_ANDROID_BINDER_DEVICES ""<br />
}}<br />
<br />
当您正在从从 AUR 构建内核时,这个脚本很方便,因为只需要在 PKGBUILD 中的正确位置插入这些命令就足够了。<br />
<br />
=== 启动新内核 ===<br />
<br />
请参阅引导加载程序的 wiki 页面了解如何使用新内核引导。您应该在启动 Anbox 之前切换到心的内核。<br />
<br />
== 安装 ==<br />
<br />
=== 加载模块 ===<br />
<br />
Anbox 不会自动加载模块,但是如果您在使用 linux-ken,就可以跳过此步骤。<br />
<br />
要临时加载,请使用:<br />
<br />
# modprobe -a binder-linux ashmem-linux<br />
<br />
要始终在启动时加载它们,可以通过 {{ic|systemd-modules-load.service}} 文件来实现。 为此,请在 {{ic|/etc/modules-load.d/}} 创建一个包含以下内容的 anbox.conf文件:<br />
<br />
{{hc|/etc/modules-load.d/anbox.conf|<br />
ashmem_linux<br />
binder_linux<br />
}}<br />
<br />
=== 挂载 binderfs ===<br />
<br />
{{Note | {{pkg|linux-zen}} 内核必须挂载 binderfs。 }}<br />
<br />
如果您的内核正在使用 binderfs,则还有一个步骤要做:挂载 binderfs 文件。<br />
<br />
首先,您需要一个挂载点。默认情况下,Anbox 将使用 {{ic|/dev/binderfs}}。 您可以直接创建该目录,但它会在启动时被删除。所以这里建议使用 [[systemd-tmpfiles]] 实现在启动时创建 {{ic|/dev/binderfs}}。为此,您需要在 {{ic|/etc/tmpfiles.d/}} 创建一个包含以下内容的文件:<br />
<br />
{{hc|/etc/tmpfiles.d/anbox.conf|<br />
d! /dev/binderfs 0755 root root<br />
}}<br />
<br />
其次您需要挂载 binder 文件系统。 这可以通过:<br />
<br />
# mount -t binder none /dev/binderfs<br />
<br />
如果想要在启动时挂载它,只需要在 [[fstab]] 中添加下面这一行。<br />
<br />
{{hc|/etc/fstab|<br />
none /dev/binderfs binder nofail 0 0<br />
}}<br />
<br />
{{警告|添加 {{ic|nofail}} 参数后,当您启动没有 binderfs 支持的内核时,您将无法进入恢复 shell。}}<br />
<br />
== 安装 Android 镜像 ==<br />
<br />
{{Note|现在的镜像均以过时 (基于 Android 7.1). 目前,上游没有可用的更新的镜像。另请参阅 [[Talk:Anbox#Anbox-Images outdated]].}}<br />
<br />
选择一个镜像来安装:<br />
<br />
* {{AUR|anbox-image}} (官方镜像)<br />
* {{AUR|anbox-image-houdini}} (包含 Houdini)<br />
* {{AUR|anbox-image-houdini-rooted}} (包含 Houdini 和 SuperSU) <br />
* {{AUR|anbox-image-gapps}} (包含 Houdini 和 OpenGApps) <br />
* {{AUR|anbox-image-gapps-rooted}} (包含 Houdini, OpenGApps 和 SuperSU) <br />
* 您也可以通过在 [[AUR]] 内搜索 [https://aur.archlinux.org/packages/?K=anbox-image anbox-image]找到更多的镜像。<br />
<br />
{{Tip |<br />
* 通常,在 x86_64 计算机上运行 ARM 应用程序需要 Houdini。<br />
* 如果您使用 GMS,OpenGApps 是一个不错的选择。}}<br />
<br />
=== 安装 Anbox ===<br />
<br />
安装 {{AUR|anbox-git}}。<br />
<br />
Afterwards, [[start/enable]] {{ic|anbox-container-manager.service}}.<br />
<br />
You have now all the required steps done to use Anbox! In the menu of your desktop environment, you should find several entries in the category ''Others'', which can now be launched.<br />
<br />
The first call will take longer. Behind the scenes, {{ic|anbox session-manager}} will be launched. For testing purposes, you can also execute {{ic|anbox session-manager}} manually in a terminal. That is '''very''' useful if anbox crashes and you want to report or fix the bug. Just launch it, and wait until it crashes (if ever).<br />
<br />
There is also a ''systemd'' unit for users, which can be used to start the session-manager on bootup; [[start/enable]] the {{ic|anbox-session-manager.service}} user unit. An advantage of this unit is that logs can be found in the event of a crash:<br />
<br />
$ journalctl --user -b -u anbox-session-manager<br />
<br />
Keep in mind though, that when it crashes and you start a new app, it will also start the session-manager, but it will be run independently from ''systemd''.<br />
<br />
== Network ==<br />
<br />
=== Via NetworkManager ===<br />
<br />
If you are using [[NetworkManager]] you can use it to configure the networking.<br />
<br />
Execute the following command to create the bridge connection:<br />
<br />
$ nmcli con add type bridge ifname anbox0 -- connection.id anbox-net ipv4.method shared ipv4.addresses 192.168.250.1/24<br />
<br />
* {{ic|ifname anbox0}} specifies the bridge interface name, in this case {{ic|anbox0}}. Do not change this as Anbox will only detect the bridge interface if it is named {{ic|anbox0}}.<br />
* {{ic|connection.id anbox-net}} specifies the name of the connection to be {{ic|anbox-net}} when it appears in [[NetworkManager]]. You can change this if you wish.<br />
* {{ic|ipv4.method shared}} instructs [[NetworkManager]] to create a NAT network and route outgoing packets according to the system routing rules. For that, the {{Pkg|dnsmasq}} package is required. [[dnsmasq]] does not needs to be configured or be started as systemd service, it will be used behind the scenes by NetworkManager — if it is not available, this step will fail silently. You can leave this and the {{ic|ipv4.addresses}} parameter out if you wish to attach the Anbox container directly to a specific network, see [[Network bridge#With NetworkManager]]. If you choose this option, you must also change the network configuration of the container in {{ic|anbox-container-manager.service}}, see the next bullet point.<br />
* {{ic|ipv4.addresses 192.168.250.1/24}} specifies the default gateway and subnet of the NAT network. If you wish to change this (e.g. to {{ic|192.168.42.1/24}}) you must also indicate the new subnet to anbox in the {{ic|anbox-container-manager.service}} using: {{ic|1=--container-network-address=192.168.42.2/24 --container-network-gateway=192.168.42.1}}<br />
<br />
[[NetworkManager]] will automatically setup the bridge every reboot so you only need to execute the command once.<br />
<br />
=== Via systemd-networkd ===<br />
<br />
The package {{AUR|anbox-git}} provides configuration files for {{ic|systemd-networkd}} in {{ic|/usr/lib/systemd/network/}} to enable networking in anbox.<br />
<br />
Therefore, you can [[start/enable]] {{ic|systemd-networkd}} before starting {{ic|anbox-container-manager.service}}.<br />
<br />
=== Via anbox-bridge script ===<br />
<br />
Alternatively you can use the anbox-bridge script [https://raw.githubusercontent.com/anbox/anbox/master/scripts/anbox-bridge.sh used by the project].<br />
<br />
You must execute {{ic|anbox-bridge}} every time before starting {{ic|anbox-container-manager.service}} in order to get network working in Anbox. The easiest solution for that is to create a drop-in file for the service.<br />
<br />
{{hc|/etc/systemd/system/anbox-container-manager.service.d/enable-anbox-bridge.conf|2= <br />
[Service]<br />
ExecStartPre=/usr/bin/anbox-bridge start<br />
ExecStopPost=/usr/bin/anbox-bridge stop<br />
}}<br />
<br />
== Usage ==<br />
<br />
You can run the Android applications on your desktop's launcher on '''Other''' category.<br />
<br />
If you want to use [[adb]] to debug, install {{Pkg|android-tools}}. The {{ic|anbox session-manager}} must already be running when launching it.<br />
<br />
$ adb shell<br />
<br />
=== Installing apps ===<br />
<br />
Unless you picked an image with Houdini, Anbox does not have support for ARM applications. So apps must have a x86_64 architecture.<br />
<br />
==== Through adb ====<br />
<br />
To install {{ic|''/path/to/app.apk''}}<br />
<br />
$ adb install ''/path/to/app.apk''<br />
<br />
To get the list of installed applications<br />
<br />
$ adb shell pm list packages<br />
<br />
Note that output will be similar to {{ic|''package:app.name''}}, where {{ic|''app.name''}} is different from the one displayed in the Anbox container.<br />
<br />
To uninstall {{ic|''app.name''}}<br />
<br />
$ adb uninstall ''app.name''<br />
<br />
If {{ic|''app.name''}} is a system app<br />
<br />
$ adb uninstall --user 0 ''app.name''<br />
<br />
==== Through apps stores ====<br />
<br />
Apps can be easily installed through apps stores. In {{AUR|anbox-image-gapps}} PlayStore is included.<br />
<br />
=== Sensor data ===<br />
<br />
Via dbus different sensors can be set. Documentation on that can be found at<br />
[https://github.com/anbox/anbox/blob/master/docs/dbus.md dbus.md].<br />
<br />
==== Temperature data ====<br />
<br />
That is the example from the author (PRs [https://github.com/anbox/anbox/pull/1522 #1522] & [https://github.com/anbox/anbox/pull/1522 #1540]):<br />
<br />
$ dbus-send --session --dest=org.anbox --print-reply /org/anbox org.freedesktop.DBus.Properties.Set string:org.anbox.Sensors string:Temperature variant:double:25.1<br />
<br />
==== GPS data ====<br />
<br />
(introduced by PR [https://github.com/anbox/anbox/pull/1606 #1606])<br />
<br />
GPS sensor data can also be manipulated. <br />
<br />
If your PC has a WWAN card, you can use {{Pkg|gpsd}} and the code from the PR to feed Anbox with GPS data. You do not need to have a SIM-Card for GPS.<br />
<br />
Otherwise, you can also look at the PR to learn how to feed it fake data with the help of [https://www.nmeagen.org].<br />
<br />
=== Root shell ===<br />
<br />
With this [https://github.com/anbox/anbox/blob/master/scripts/anbox-shell.sh script] from the Anbox project one can get a root shell inside the Android container.<br />
<br />
It is not part of the {{AUR|anbox-git}} package, and it also does not use [[adb]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Android developer options ===<br />
<br />
Some extra steps need to be done besides unlocking them the same way you do on an android phone.<br />
When installing the [[#Install Android Image|android image]], some modifications to {{ic|products/anbox.xml}} are required:<br />
<br />
* {{ic|1=<unavailable-feature name="android.hardware.usb.host" />}} is the reason why they are not available.<br />
* {{ic|1=<feature name="android.software.backup" />}} will be needed too, to avoid a NullPointerException.<br />
<br />
(reference: [https://github.com/anbox/anbox/issues/444 Github issue #444])<br />
<br />
=== Getting debugging information ===<br />
<br />
Obviously, it is helpful to have debugging symbols in the Anbox build. For that, when [[#Install Anbox|compiling Anbox]], add {{ic|1=options=('!strip')}} to the PKGBUILD, as by default they are removed. And, use either {{ic|1=-DCMAKE_BUILD_TYPE=RelWithDebInfo}} or {{ic|1=-DCMAKE_BUILD_TYPE=Debug}} in the cmake call.<br />
<br />
But there is more to it! Anbox uses [https://github.com/anbox/anbox/tree/master/external/backward-cpp backward-cpp]. If you do not delete the build files for Anbox, it will print pretty stack traces when crashing, which point out the places in the source code.<br />
<br />
Also see the remarks in [[#Install Anbox|Install Anbox]].<br />
<br />
== Troubleshooting ==<br />
<br />
If you run into issues, take a look at the official Issue Tracker: [https://github.com/anbox/anbox/issues]<br />
<br />
=== Old CPUs ===<br />
<br />
Anbox requires support for SSE 4.1/4.2 and SSSE 3, because Android wants that too.<br />
Some older CPUs do not provide that, so you probably cannot use Anbox, see:<br />
[https://github.com/anbox/anbox/issues/499#issuecomment-399118684 Anbox Github Issue 499].<br />
<br />
=== Old kernels ===<br />
<br />
Before the kernel modules were mainlined, they were out of tree modules, which needed to be installed seperately from the kernel (Like it is the case for the nvidia kernel modules). They are not compatible with kernel 5.7 or newer.<br />
<br />
It is still possible to use that approach with the {{Pkg|linux-lts}} or other old kernels. The package to install the modules via [[DKMS]] is not available in the AUR anymore, but can be retrieved with {{ic|<nowiki>git clone https://aur.archlinux.org/anbox-modules-dkms</nowiki>}}, or resurected from [https://aur.archlinux.org/cgit/aur.git/commit/?h=anbox-git&id=0c9a9385694e680f5b277ca6f9326ad5d5df7dd3].<br />
<br />
=== Secure Boot error ===<br />
<br />
If you get this error message:<br />
<br />
modprobe: ERROR: could not insert 'ashmem_linux': Operation not permitted<br />
<br />
[[Secure Boot]] is likely blocking the module.<br />
You can either disable Secure Boot or sign the ashmem module yourself.<br />
<br />
More info can be found in the [https://github.com/anbox/anbox/blob/master/docs/install.md#on-ubuntu-1904-and-later Anbox Github Docs].<br />
<br />
== See also ==<br />
<br />
* [https://github.com/anbox/anbox Official Anbox Github Repo]<br />
* [https://anbox.io/ Anbox Website]<br />
* [https://mm.gravedo.de/blog/posts/2020-01-21-taking-the-anbox-journey-to-the-next-level Posting by the main Anbox developer]<br />
* [https://brauner.github.io/2019/01/09/android-binderfs.html Explanation about binderfs]</div>Puroflehttps://wiki.archlinux.org/index.php?title=Anbox_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=690120Anbox (简体中文)2021-08-01T17:17:46Z<p>Purofle: 增加 TranslationStatus</p>
<hr />
<div>[[Category:Virtualization_(简体中文)]]<br />
[[Category:Android (简体中文)]]<br />
[[en:Anbox]]<br />
[[ja:Anbox]]<br />
[[ru:Anbox]]<br />
[[zh-hans:Anbox]]<br />
{{Related articles start}}<br />
{{Related|Linux Containers}}<br />
{{Related articles end}}<br />
{{Bad translation (简体中文)|部分内容可能由机器翻译。}}<br />
{{TranslationStatus (简体中文)|Anbox|2021-08-02|28657}}<br />
Anbox 是一个可以在 GNU/Linux 发行版上运行 Android App 的一个 [[Linux_Containers|容器]]。<br />
<br />
== 准备工作 ==<br />
<br />
{{Note|Anbox 的 dkms 模块在内核版本 ≥5.7 下不会工作。请按照以下说明进行操作。 对于较老的内核请参阅 [[#较老的内核|较老的内核]]。}}<br />
<br />
您需要运行带有 ashmem 和 binder 模块的内核。但是它们不是 Arch Linux 的默认内核 ( linux ) 的一部分,所以您需要安装一个包含这些模块的内核。<br />
<br />
您可能还需要配置引导加载程序以使用不同的内核。<br />
<br />
您有多种选择:<br />
<br />
=== 使用 Linux-Zen ===<br />
<br />
{{Pkg|linux-zen}} 内核自带 Anbox 需要的模块。这可能是最简单的方式,因为您不必编译内核并且版本会定期更新。<br />
<br />
=== 编译内核 ===<br />
<br />
当然,您也可以自己重新编译 {{Pkg|linux}} 内核。请阅读 [[Kernel_(简体中文)#编译]] and [[#配置模块|配置模块]] 。<br />
<br />
您还可以从[[AUR]]里构建一个已经包含特定补丁的内核包, 请参阅 [https://aur.archlinux.org/packages/?K=linux+anbox AUR search "linux+anbox"].<br />
<br />
==== 配置模块 ====<br />
<br />
模块同样也可以被编译进内核里 ({{ic|y}}), 模块里 ({{ic|m}}), 或者不编译 ({{ic|n}}).此外,并非配置中的所有组合都是可能的,某些选项将需要其他选项。<br />
<br />
下面的的内核配置将把 ashmem 和 binder 编译为模块,而最后一个选项指定在 {{ic|/dev/}} 加载 binder 模块时在目录中创建三个设备。<br />
<br />
{{bc|1=<br />
CONFIG_ASHMEM=m <br />
CONFIG_ANDROID=y<br />
CONFIG_ANDROID_BINDER_IPC=m<br />
CONFIG_ANDROID_BINDERFS=n<br />
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"<br />
}}<br />
<br />
如果您要从 AUR 构建内核,那么您可以参考下面的步骤:<br />
<br />
# 运行 {{ic|makepkg --nobuild}}, 它将下载源代码,验证并提取。最后运行 {{ic|prepare()}} 函数.<br />
# 编辑位于内核目录底部的 {{ic|.config}} 文件。<br />
# 在 {{ic|prepare()}} 函数的末尾可能是一个命令,它使用来自配置的信息重新生成 makefile,也可能是 {{ic|make olddefconfig}}. 将它移动到 {{ic|build()}} 函数内,或自己执行一遍。<br />
# 运行 {{ic|makepkg --noextract}}, 它将在 {{ic|makepkg --nobuild}} 停止的地方继续。<br />
<br />
==== 使用 binderfs 进行配置 ====<br />
<br />
并不是每个人都对 Linux 中的 binder 模块感到满意。为了解决这些问题,binderfs诞生了。编译内核时必须在新旧两种方式之间进行选择。比如下面的选项就是针对于 binderfs 的。<br />
<br />
内核源代码还提供了一个简单的脚本来设置配置选项。它不会进行依赖项检查。当您在 {{ic|.config}} 文件所在的同一目录中时,执行以下命令:<br />
<br />
{{bc|<br />
scripts/config --module CONFIG_ASHMEM<br />
scripts/config --enable CONFIG_ANDROID<br />
scripts/config --enable CONFIG_ANDROID_BINDER_IPC<br />
scripts/config --enable CONFIG_ANDROID_BINDERFS<br />
scripts/config --set-str CONFIG_ANDROID_BINDER_DEVICES ""<br />
}}<br />
<br />
当您正在从从 AUR 构建内核时,这个脚本很方便,因为只需要在 PKGBUILD 中的正确位置插入这些命令就足够了。<br />
<br />
=== 启动新内核 ===<br />
<br />
请参阅引导加载程序的 wiki 页面了解如何使用新内核引导。您应该在启动 Anbox 之前切换到心的内核。<br />
<br />
== 安装 ==<br />
<br />
=== 加载模块 ===<br />
<br />
Anbox 不会自动加载模块,但是如果您在使用 linux-ken,就可以跳过此步骤。<br />
<br />
要临时加载,请使用:<br />
<br />
# modprobe -a binder-linux ashmem-linux<br />
<br />
要始终在启动时加载它们,可以通过 {{ic|systemd-modules-load.service}} 文件来实现。 为此,请在 {{ic|/etc/modules-load.d/}} 创建一个包含以下内容的 anbox.conf文件:<br />
<br />
{{hc|/etc/modules-load.d/anbox.conf|<br />
ashmem_linux<br />
binder_linux<br />
}}<br />
<br />
=== 挂载 binderfs ===<br />
<br />
{{Note | {{pkg|linux-zen}} 内核必须挂载 binderfs。 }}<br />
<br />
如果您的内核正在使用 binderfs,则还有一个步骤要做:挂载 binderfs 文件。<br />
<br />
Firstly, you will need a mountpoint. By default, Anbox will look at {{ic|/dev/binderfs}}. You can create that directory now, but it will be removed at boot time.<br />
首先,您需要一个挂载点。默认情况下,Anbox 将使用 {{ic|/dev/binderfs}}。 您可以直接创建该目录,但它会在启动时被删除。所以这里建议使用 [[systemd-tmpfiles]] 实现在启动时创建 {{ic|/dev/binderfs}}。为此,您需要在 {{ic|/etc/tmpfiles.d/}} 创建一个包含以下内容的文件:<br />
<br />
{{hc|/etc/tmpfiles.d/anbox.conf|<br />
d! /dev/binderfs 0755 root root<br />
}}<br />
<br />
其次您需要挂载 binder 文件系统。 这可以通过:<br />
<br />
# mount -t binder none /dev/binderfs<br />
<br />
如果想要在启动时挂载它,只需要在 [[fstab]] 中添加下面这一行。<br />
<br />
{{hc|/etc/fstab|<br />
none /dev/binderfs binder nofail 0 0<br />
}}<br />
<br />
{{警告|添加 {{ic|nofail}} 参数后,当您启动没有 binderfs 支持的内核时,您将无法进入恢复 shell。}}<br />
<br />
== 安装 Android 镜像 ==<br />
<br />
{{Note|现在的镜像均以过时 (基于 Android 7.1). 目前,上游没有可用的更新的镜像。另请参阅 [[Talk:Anbox#Anbox-Images outdated]].}}<br />
<br />
选择一个镜像来安装:<br />
<br />
* {{AUR|anbox-image}} (官方镜像)<br />
* {{AUR|anbox-image-houdini}} (包含 Houdini)<br />
* {{AUR|anbox-image-houdini-rooted}} (包含 Houdini 和 SuperSU) <br />
* {{AUR|anbox-image-gapps}} (包含 Houdini 和 OpenGApps) <br />
* {{AUR|anbox-image-gapps-rooted}} (包含 Houdini, OpenGApps 和 SuperSU) <br />
* 您也可以通过在 [[AUR]] 内搜索 [https://aur.archlinux.org/packages/?K=anbox-image anbox-image]找到更多的镜像。<br />
<br />
{{Tip |<br />
* 通常,在 x86_64 计算机上运行 ARM 应用程序需要 Houdini。<br />
* 如果您使用 GMS,OpenGApps 是一个不错的选择。}}<br />
<br />
=== 安装 Anbox ===<br />
<br />
安装 {{AUR|anbox-git}}。<br />
<br />
Afterwards, [[start/enable]] {{ic|anbox-container-manager.service}}.<br />
<br />
You have now all the required steps done to use Anbox! In the menu of your desktop environment, you should find several entries in the category ''Others'', which can now be launched.<br />
<br />
The first call will take longer. Behind the scenes, {{ic|anbox session-manager}} will be launched. For testing purposes, you can also execute {{ic|anbox session-manager}} manually in a terminal. That is '''very''' useful if anbox crashes and you want to report or fix the bug. Just launch it, and wait until it crashes (if ever).<br />
<br />
There is also a ''systemd'' unit for users, which can be used to start the session-manager on bootup; [[start/enable]] the {{ic|anbox-session-manager.service}} user unit. An advantage of this unit is that logs can be found in the event of a crash:<br />
<br />
$ journalctl --user -b -u anbox-session-manager<br />
<br />
Keep in mind though, that when it crashes and you start a new app, it will also start the session-manager, but it will be run independently from ''systemd''.<br />
<br />
== Network ==<br />
<br />
=== Via NetworkManager ===<br />
<br />
If you are using [[NetworkManager]] you can use it to configure the networking.<br />
<br />
Execute the following command to create the bridge connection:<br />
<br />
$ nmcli con add type bridge ifname anbox0 -- connection.id anbox-net ipv4.method shared ipv4.addresses 192.168.250.1/24<br />
<br />
* {{ic|ifname anbox0}} specifies the bridge interface name, in this case {{ic|anbox0}}. Do not change this as Anbox will only detect the bridge interface if it is named {{ic|anbox0}}.<br />
* {{ic|connection.id anbox-net}} specifies the name of the connection to be {{ic|anbox-net}} when it appears in [[NetworkManager]]. You can change this if you wish.<br />
* {{ic|ipv4.method shared}} instructs [[NetworkManager]] to create a NAT network and route outgoing packets according to the system routing rules. For that, the {{Pkg|dnsmasq}} package is required. [[dnsmasq]] does not needs to be configured or be started as systemd service, it will be used behind the scenes by NetworkManager — if it is not available, this step will fail silently. You can leave this and the {{ic|ipv4.addresses}} parameter out if you wish to attach the Anbox container directly to a specific network, see [[Network bridge#With NetworkManager]]. If you choose this option, you must also change the network configuration of the container in {{ic|anbox-container-manager.service}}, see the next bullet point.<br />
* {{ic|ipv4.addresses 192.168.250.1/24}} specifies the default gateway and subnet of the NAT network. If you wish to change this (e.g. to {{ic|192.168.42.1/24}}) you must also indicate the new subnet to anbox in the {{ic|anbox-container-manager.service}} using: {{ic|1=--container-network-address=192.168.42.2/24 --container-network-gateway=192.168.42.1}}<br />
<br />
[[NetworkManager]] will automatically setup the bridge every reboot so you only need to execute the command once.<br />
<br />
=== Via systemd-networkd ===<br />
<br />
The package {{AUR|anbox-git}} provides configuration files for {{ic|systemd-networkd}} in {{ic|/usr/lib/systemd/network/}} to enable networking in anbox.<br />
<br />
Therefore, you can [[start/enable]] {{ic|systemd-networkd}} before starting {{ic|anbox-container-manager.service}}.<br />
<br />
=== Via anbox-bridge script ===<br />
<br />
Alternatively you can use the anbox-bridge script [https://raw.githubusercontent.com/anbox/anbox/master/scripts/anbox-bridge.sh used by the project].<br />
<br />
You must execute {{ic|anbox-bridge}} every time before starting {{ic|anbox-container-manager.service}} in order to get network working in Anbox. The easiest solution for that is to create a drop-in file for the service.<br />
<br />
{{hc|/etc/systemd/system/anbox-container-manager.service.d/enable-anbox-bridge.conf|2= <br />
[Service]<br />
ExecStartPre=/usr/bin/anbox-bridge start<br />
ExecStopPost=/usr/bin/anbox-bridge stop<br />
}}<br />
<br />
== Usage ==<br />
<br />
You can run the Android applications on your desktop's launcher on '''Other''' category.<br />
<br />
If you want to use [[adb]] to debug, install {{Pkg|android-tools}}. The {{ic|anbox session-manager}} must already be running when launching it.<br />
<br />
$ adb shell<br />
<br />
=== Installing apps ===<br />
<br />
Unless you picked an image with Houdini, Anbox does not have support for ARM applications. So apps must have a x86_64 architecture.<br />
<br />
==== Through adb ====<br />
<br />
To install {{ic|''/path/to/app.apk''}}<br />
<br />
$ adb install ''/path/to/app.apk''<br />
<br />
To get the list of installed applications<br />
<br />
$ adb shell pm list packages<br />
<br />
Note that output will be similar to {{ic|''package:app.name''}}, where {{ic|''app.name''}} is different from the one displayed in the Anbox container.<br />
<br />
To uninstall {{ic|''app.name''}}<br />
<br />
$ adb uninstall ''app.name''<br />
<br />
If {{ic|''app.name''}} is a system app<br />
<br />
$ adb uninstall --user 0 ''app.name''<br />
<br />
==== Through apps stores ====<br />
<br />
Apps can be easily installed through apps stores. In {{AUR|anbox-image-gapps}} PlayStore is included.<br />
<br />
=== Sensor data ===<br />
<br />
Via dbus different sensors can be set. Documentation on that can be found at<br />
[https://github.com/anbox/anbox/blob/master/docs/dbus.md dbus.md].<br />
<br />
==== Temperature data ====<br />
<br />
That is the example from the author (PRs [https://github.com/anbox/anbox/pull/1522 #1522] & [https://github.com/anbox/anbox/pull/1522 #1540]):<br />
<br />
$ dbus-send --session --dest=org.anbox --print-reply /org/anbox org.freedesktop.DBus.Properties.Set string:org.anbox.Sensors string:Temperature variant:double:25.1<br />
<br />
==== GPS data ====<br />
<br />
(introduced by PR [https://github.com/anbox/anbox/pull/1606 #1606])<br />
<br />
GPS sensor data can also be manipulated. <br />
<br />
If your PC has a WWAN card, you can use {{Pkg|gpsd}} and the code from the PR to feed Anbox with GPS data. You do not need to have a SIM-Card for GPS.<br />
<br />
Otherwise, you can also look at the PR to learn how to feed it fake data with the help of [https://www.nmeagen.org].<br />
<br />
=== Root shell ===<br />
<br />
With this [https://github.com/anbox/anbox/blob/master/scripts/anbox-shell.sh script] from the Anbox project one can get a root shell inside the Android container.<br />
<br />
It is not part of the {{AUR|anbox-git}} package, and it also does not use [[adb]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Android developer options ===<br />
<br />
Some extra steps need to be done besides unlocking them the same way you do on an android phone.<br />
When installing the [[#Install Android Image|android image]], some modifications to {{ic|products/anbox.xml}} are required:<br />
<br />
* {{ic|1=<unavailable-feature name="android.hardware.usb.host" />}} is the reason why they are not available.<br />
* {{ic|1=<feature name="android.software.backup" />}} will be needed too, to avoid a NullPointerException.<br />
<br />
(reference: [https://github.com/anbox/anbox/issues/444 Github issue #444])<br />
<br />
=== Getting debugging information ===<br />
<br />
Obviously, it is helpful to have debugging symbols in the Anbox build. For that, when [[#Install Anbox|compiling Anbox]], add {{ic|1=options=('!strip')}} to the PKGBUILD, as by default they are removed. And, use either {{ic|1=-DCMAKE_BUILD_TYPE=RelWithDebInfo}} or {{ic|1=-DCMAKE_BUILD_TYPE=Debug}} in the cmake call.<br />
<br />
But there is more to it! Anbox uses [https://github.com/anbox/anbox/tree/master/external/backward-cpp backward-cpp]. If you do not delete the build files for Anbox, it will print pretty stack traces when crashing, which point out the places in the source code.<br />
<br />
Also see the remarks in [[#Install Anbox|Install Anbox]].<br />
<br />
== Troubleshooting ==<br />
<br />
If you run into issues, take a look at the official Issue Tracker: [https://github.com/anbox/anbox/issues]<br />
<br />
=== Old CPUs ===<br />
<br />
Anbox requires support for SSE 4.1/4.2 and SSSE 3, because Android wants that too.<br />
Some older CPUs do not provide that, so you probably cannot use Anbox, see:<br />
[https://github.com/anbox/anbox/issues/499#issuecomment-399118684 Anbox Github Issue 499].<br />
<br />
=== Old kernels ===<br />
<br />
Before the kernel modules were mainlined, they were out of tree modules, which needed to be installed seperately from the kernel (Like it is the case for the nvidia kernel modules). They are not compatible with kernel 5.7 or newer.<br />
<br />
It is still possible to use that approach with the {{Pkg|linux-lts}} or other old kernels. The package to install the modules via [[DKMS]] is not available in the AUR anymore, but can be retrieved with {{ic|<nowiki>git clone https://aur.archlinux.org/anbox-modules-dkms</nowiki>}}, or resurected from [https://aur.archlinux.org/cgit/aur.git/commit/?h=anbox-git&id=0c9a9385694e680f5b277ca6f9326ad5d5df7dd3].<br />
<br />
=== Secure Boot error ===<br />
<br />
If you get this error message:<br />
<br />
modprobe: ERROR: could not insert 'ashmem_linux': Operation not permitted<br />
<br />
[[Secure Boot]] is likely blocking the module.<br />
You can either disable Secure Boot or sign the ashmem module yourself.<br />
<br />
More info can be found in the [https://github.com/anbox/anbox/blob/master/docs/install.md#on-ubuntu-1904-and-later Anbox Github Docs].<br />
<br />
== See also ==<br />
<br />
* [https://github.com/anbox/anbox Official Anbox Github Repo]<br />
* [https://anbox.io/ Anbox Website]<br />
* [https://mm.gravedo.de/blog/posts/2020-01-21-taking-the-anbox-journey-to-the-next-level Posting by the main Anbox developer]<br />
* [https://brauner.github.io/2019/01/09/android-binderfs.html Explanation about binderfs]</div>Puroflehttps://wiki.archlinux.org/index.php?title=Anbox_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=690119Anbox (简体中文)2021-08-01T17:09:48Z<p>Purofle: </p>
<hr />
<div>[[Category:Virtualization_(简体中文)]]<br />
[[Category:Android (简体中文)]]<br />
[[en:Anbox]]<br />
[[ja:Anbox]]<br />
[[ru:Anbox]]<br />
[[zh-hans:Anbox]]<br />
{{Related articles start}}<br />
{{Bad translation (简体中文)|部分内容可能由机器翻译。}}<br />
{{Related|Linux Containers}}<br />
{{Related articles end}}<br />
Anbox 是一个可以在 GNU/Linux 发行版上运行 Android App 的一个 [[Linux_Containers|容器]]。<br />
<br />
== 准备工作 ==<br />
<br />
{{Note|Anbox 的 dkms 模块在内核版本 ≥5.7 下不会工作。请按照以下说明进行操作。 对于较老的内核请参阅 [[#较老的内核|较老的内核]]。}}<br />
<br />
您需要运行带有 ashmem 和 binder 模块的内核。但是它们不是 Arch Linux 的默认内核 ( linux ) 的一部分,所以您需要安装一个包含这些模块的内核。<br />
<br />
您可能还需要配置引导加载程序以使用不同的内核。<br />
<br />
您有多种选择:<br />
<br />
=== 使用 Linux-Zen ===<br />
<br />
{{Pkg|linux-zen}} 内核自带 Anbox 需要的模块。这可能是最简单的方式,因为您不必编译内核并且版本会定期更新。<br />
<br />
=== 编译内核 ===<br />
<br />
当然,您也可以自己重新编译 {{Pkg|linux}} 内核。请阅读 [[Kernel_(简体中文)#编译]] and [[#配置模块|配置模块]] 。<br />
<br />
您还可以从[[AUR]]里构建一个已经包含特定补丁的内核包, 请参阅 [https://aur.archlinux.org/packages/?K=linux+anbox AUR search "linux+anbox"].<br />
<br />
==== 配置模块 ====<br />
<br />
模块同样也可以被编译进内核里 ({{ic|y}}), 模块里 ({{ic|m}}), 或者不编译 ({{ic|n}}).此外,并非配置中的所有组合都是可能的,某些选项将需要其他选项。<br />
<br />
下面的的内核配置将把 ashmem 和 binder 编译为模块,而最后一个选项指定在 {{ic|/dev/}} 加载 binder 模块时在目录中创建三个设备。<br />
<br />
{{bc|1=<br />
CONFIG_ASHMEM=m <br />
CONFIG_ANDROID=y<br />
CONFIG_ANDROID_BINDER_IPC=m<br />
CONFIG_ANDROID_BINDERFS=n<br />
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"<br />
}}<br />
<br />
如果您要从 AUR 构建内核,那么您可以参考下面的步骤:<br />
<br />
# 运行 {{ic|makepkg --nobuild}}, 它将下载源代码,验证并提取。最后运行 {{ic|prepare()}} 函数.<br />
# 编辑位于内核目录底部的 {{ic|.config}} 文件。<br />
# 在 {{ic|prepare()}} 函数的末尾可能是一个命令,它使用来自配置的信息重新生成 makefile,也可能是 {{ic|make olddefconfig}}. 将它移动到 {{ic|build()}} 函数内,或自己执行一遍。<br />
# 运行 {{ic|makepkg --noextract}}, 它将在 {{ic|makepkg --nobuild}} 停止的地方继续。<br />
<br />
==== 使用 binderfs 进行配置 ====<br />
<br />
并不是每个人都对 Linux 中的 binder 模块感到满意。为了解决这些问题,binderfs诞生了。编译内核时必须在新旧两种方式之间进行选择。比如下面的选项就是针对于 binderfs 的。<br />
<br />
内核源代码还提供了一个简单的脚本来设置配置选项。它不会进行依赖项检查。当您在 {{ic|.config}} 文件所在的同一目录中时,执行以下命令:<br />
<br />
{{bc|<br />
scripts/config --module CONFIG_ASHMEM<br />
scripts/config --enable CONFIG_ANDROID<br />
scripts/config --enable CONFIG_ANDROID_BINDER_IPC<br />
scripts/config --enable CONFIG_ANDROID_BINDERFS<br />
scripts/config --set-str CONFIG_ANDROID_BINDER_DEVICES ""<br />
}}<br />
<br />
当您正在从从 AUR 构建内核时,这个脚本很方便,因为只需要在 PKGBUILD 中的正确位置插入这些命令就足够了。<br />
<br />
=== 启动新内核 ===<br />
<br />
请参阅引导加载程序的 wiki 页面了解如何使用新内核引导。您应该在启动 Anbox 之前切换到心的内核。<br />
<br />
== 安装 ==<br />
<br />
=== 加载模块 ===<br />
<br />
Anbox 不会自动加载模块,但是如果您在使用 linux-ken,就可以跳过此步骤。<br />
<br />
要临时加载,请使用:<br />
<br />
# modprobe -a binder-linux ashmem-linux<br />
<br />
要始终在启动时加载它们,可以通过 {{ic|systemd-modules-load.service}} 文件来实现。 为此,请在 {{ic|/etc/modules-load.d/}} 创建一个包含以下内容的 anbox.conf文件:<br />
<br />
{{hc|/etc/modules-load.d/anbox.conf|<br />
ashmem_linux<br />
binder_linux<br />
}}<br />
<br />
=== 挂载 binderfs ===<br />
<br />
{{Note | {{pkg|linux-zen}} 内核必须挂载 binderfs。 }}<br />
<br />
如果您的内核正在使用 binderfs,则还有一个步骤要做:挂载 binderfs 文件。<br />
<br />
Firstly, you will need a mountpoint. By default, Anbox will look at {{ic|/dev/binderfs}}. You can create that directory now, but it will be removed at boot time.<br />
首先,您需要一个挂载点。默认情况下,Anbox 将使用 {{ic|/dev/binderfs}}。 您可以直接创建该目录,但它会在启动时被删除。所以这里建议使用 [[systemd-tmpfiles]] 实现在启动时创建 {{ic|/dev/binderfs}}。为此,您需要在 {{ic|/etc/tmpfiles.d/}} 创建一个包含以下内容的文件:<br />
<br />
{{hc|/etc/tmpfiles.d/anbox.conf|<br />
d! /dev/binderfs 0755 root root<br />
}}<br />
<br />
其次您需要挂载 binder 文件系统。 这可以通过:<br />
<br />
# mount -t binder none /dev/binderfs<br />
<br />
如果想要在启动时挂载它,只需要在 [[fstab]] 中添加下面这一行。<br />
<br />
{{hc|/etc/fstab|<br />
none /dev/binderfs binder nofail 0 0<br />
}}<br />
<br />
{{警告|添加 {{ic|nofail}} 参数后,当您启动没有 binderfs 支持的内核时,您将无法进入恢复 shell。}}<br />
<br />
== 安装 Android 镜像 ==<br />
<br />
{{Note|现在的镜像均以过时 (基于 Android 7.1). 目前,上游没有可用的更新的镜像。另请参阅 [[Talk:Anbox#Anbox-Images outdated]].}}<br />
<br />
选择一个镜像来安装:<br />
<br />
* {{AUR|anbox-image}} (官方镜像)<br />
* {{AUR|anbox-image-houdini}} (包含 Houdini)<br />
* {{AUR|anbox-image-houdini-rooted}} (包含 Houdini 和 SuperSU) <br />
* {{AUR|anbox-image-gapps}} (包含 Houdini 和 OpenGApps) <br />
* {{AUR|anbox-image-gapps-rooted}} (包含 Houdini, OpenGApps 和 SuperSU) <br />
* 您也可以通过在 [[AUR]] 内搜索 [https://aur.archlinux.org/packages/?K=anbox-image anbox-image]找到更多的镜像。<br />
<br />
{{Tip |<br />
* 通常,在 x86_64 计算机上运行 ARM 应用程序需要 Houdini。<br />
* 如果您使用 GMS,OpenGApps 是一个不错的选择。}}<br />
<br />
=== 安装 Anbox ===<br />
<br />
安装 {{AUR|anbox-git}}。<br />
<br />
Afterwards, [[start/enable]] {{ic|anbox-container-manager.service}}.<br />
<br />
You have now all the required steps done to use Anbox! In the menu of your desktop environment, you should find several entries in the category ''Others'', which can now be launched.<br />
<br />
The first call will take longer. Behind the scenes, {{ic|anbox session-manager}} will be launched. For testing purposes, you can also execute {{ic|anbox session-manager}} manually in a terminal. That is '''very''' useful if anbox crashes and you want to report or fix the bug. Just launch it, and wait until it crashes (if ever).<br />
<br />
There is also a ''systemd'' unit for users, which can be used to start the session-manager on bootup; [[start/enable]] the {{ic|anbox-session-manager.service}} user unit. An advantage of this unit is that logs can be found in the event of a crash:<br />
<br />
$ journalctl --user -b -u anbox-session-manager<br />
<br />
Keep in mind though, that when it crashes and you start a new app, it will also start the session-manager, but it will be run independently from ''systemd''.<br />
<br />
== Network ==<br />
<br />
=== Via NetworkManager ===<br />
<br />
If you are using [[NetworkManager]] you can use it to configure the networking.<br />
<br />
Execute the following command to create the bridge connection:<br />
<br />
$ nmcli con add type bridge ifname anbox0 -- connection.id anbox-net ipv4.method shared ipv4.addresses 192.168.250.1/24<br />
<br />
* {{ic|ifname anbox0}} specifies the bridge interface name, in this case {{ic|anbox0}}. Do not change this as Anbox will only detect the bridge interface if it is named {{ic|anbox0}}.<br />
* {{ic|connection.id anbox-net}} specifies the name of the connection to be {{ic|anbox-net}} when it appears in [[NetworkManager]]. You can change this if you wish.<br />
* {{ic|ipv4.method shared}} instructs [[NetworkManager]] to create a NAT network and route outgoing packets according to the system routing rules. For that, the {{Pkg|dnsmasq}} package is required. [[dnsmasq]] does not needs to be configured or be started as systemd service, it will be used behind the scenes by NetworkManager — if it is not available, this step will fail silently. You can leave this and the {{ic|ipv4.addresses}} parameter out if you wish to attach the Anbox container directly to a specific network, see [[Network bridge#With NetworkManager]]. If you choose this option, you must also change the network configuration of the container in {{ic|anbox-container-manager.service}}, see the next bullet point.<br />
* {{ic|ipv4.addresses 192.168.250.1/24}} specifies the default gateway and subnet of the NAT network. If you wish to change this (e.g. to {{ic|192.168.42.1/24}}) you must also indicate the new subnet to anbox in the {{ic|anbox-container-manager.service}} using: {{ic|1=--container-network-address=192.168.42.2/24 --container-network-gateway=192.168.42.1}}<br />
<br />
[[NetworkManager]] will automatically setup the bridge every reboot so you only need to execute the command once.<br />
<br />
=== Via systemd-networkd ===<br />
<br />
The package {{AUR|anbox-git}} provides configuration files for {{ic|systemd-networkd}} in {{ic|/usr/lib/systemd/network/}} to enable networking in anbox.<br />
<br />
Therefore, you can [[start/enable]] {{ic|systemd-networkd}} before starting {{ic|anbox-container-manager.service}}.<br />
<br />
=== Via anbox-bridge script ===<br />
<br />
Alternatively you can use the anbox-bridge script [https://raw.githubusercontent.com/anbox/anbox/master/scripts/anbox-bridge.sh used by the project].<br />
<br />
You must execute {{ic|anbox-bridge}} every time before starting {{ic|anbox-container-manager.service}} in order to get network working in Anbox. The easiest solution for that is to create a drop-in file for the service.<br />
<br />
{{hc|/etc/systemd/system/anbox-container-manager.service.d/enable-anbox-bridge.conf|2= <br />
[Service]<br />
ExecStartPre=/usr/bin/anbox-bridge start<br />
ExecStopPost=/usr/bin/anbox-bridge stop<br />
}}<br />
<br />
== Usage ==<br />
<br />
You can run the Android applications on your desktop's launcher on '''Other''' category.<br />
<br />
If you want to use [[adb]] to debug, install {{Pkg|android-tools}}. The {{ic|anbox session-manager}} must already be running when launching it.<br />
<br />
$ adb shell<br />
<br />
=== Installing apps ===<br />
<br />
Unless you picked an image with Houdini, Anbox does not have support for ARM applications. So apps must have a x86_64 architecture.<br />
<br />
==== Through adb ====<br />
<br />
To install {{ic|''/path/to/app.apk''}}<br />
<br />
$ adb install ''/path/to/app.apk''<br />
<br />
To get the list of installed applications<br />
<br />
$ adb shell pm list packages<br />
<br />
Note that output will be similar to {{ic|''package:app.name''}}, where {{ic|''app.name''}} is different from the one displayed in the Anbox container.<br />
<br />
To uninstall {{ic|''app.name''}}<br />
<br />
$ adb uninstall ''app.name''<br />
<br />
If {{ic|''app.name''}} is a system app<br />
<br />
$ adb uninstall --user 0 ''app.name''<br />
<br />
==== Through apps stores ====<br />
<br />
Apps can be easily installed through apps stores. In {{AUR|anbox-image-gapps}} PlayStore is included.<br />
<br />
=== Sensor data ===<br />
<br />
Via dbus different sensors can be set. Documentation on that can be found at<br />
[https://github.com/anbox/anbox/blob/master/docs/dbus.md dbus.md].<br />
<br />
==== Temperature data ====<br />
<br />
That is the example from the author (PRs [https://github.com/anbox/anbox/pull/1522 #1522] & [https://github.com/anbox/anbox/pull/1522 #1540]):<br />
<br />
$ dbus-send --session --dest=org.anbox --print-reply /org/anbox org.freedesktop.DBus.Properties.Set string:org.anbox.Sensors string:Temperature variant:double:25.1<br />
<br />
==== GPS data ====<br />
<br />
(introduced by PR [https://github.com/anbox/anbox/pull/1606 #1606])<br />
<br />
GPS sensor data can also be manipulated. <br />
<br />
If your PC has a WWAN card, you can use {{Pkg|gpsd}} and the code from the PR to feed Anbox with GPS data. You do not need to have a SIM-Card for GPS.<br />
<br />
Otherwise, you can also look at the PR to learn how to feed it fake data with the help of [https://www.nmeagen.org].<br />
<br />
=== Root shell ===<br />
<br />
With this [https://github.com/anbox/anbox/blob/master/scripts/anbox-shell.sh script] from the Anbox project one can get a root shell inside the Android container.<br />
<br />
It is not part of the {{AUR|anbox-git}} package, and it also does not use [[adb]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Android developer options ===<br />
<br />
Some extra steps need to be done besides unlocking them the same way you do on an android phone.<br />
When installing the [[#Install Android Image|android image]], some modifications to {{ic|products/anbox.xml}} are required:<br />
<br />
* {{ic|1=<unavailable-feature name="android.hardware.usb.host" />}} is the reason why they are not available.<br />
* {{ic|1=<feature name="android.software.backup" />}} will be needed too, to avoid a NullPointerException.<br />
<br />
(reference: [https://github.com/anbox/anbox/issues/444 Github issue #444])<br />
<br />
=== Getting debugging information ===<br />
<br />
Obviously, it is helpful to have debugging symbols in the Anbox build. For that, when [[#Install Anbox|compiling Anbox]], add {{ic|1=options=('!strip')}} to the PKGBUILD, as by default they are removed. And, use either {{ic|1=-DCMAKE_BUILD_TYPE=RelWithDebInfo}} or {{ic|1=-DCMAKE_BUILD_TYPE=Debug}} in the cmake call.<br />
<br />
But there is more to it! Anbox uses [https://github.com/anbox/anbox/tree/master/external/backward-cpp backward-cpp]. If you do not delete the build files for Anbox, it will print pretty stack traces when crashing, which point out the places in the source code.<br />
<br />
Also see the remarks in [[#Install Anbox|Install Anbox]].<br />
<br />
== Troubleshooting ==<br />
<br />
If you run into issues, take a look at the official Issue Tracker: [https://github.com/anbox/anbox/issues]<br />
<br />
=== Old CPUs ===<br />
<br />
Anbox requires support for SSE 4.1/4.2 and SSSE 3, because Android wants that too.<br />
Some older CPUs do not provide that, so you probably cannot use Anbox, see:<br />
[https://github.com/anbox/anbox/issues/499#issuecomment-399118684 Anbox Github Issue 499].<br />
<br />
=== Old kernels ===<br />
<br />
Before the kernel modules were mainlined, they were out of tree modules, which needed to be installed seperately from the kernel (Like it is the case for the nvidia kernel modules). They are not compatible with kernel 5.7 or newer.<br />
<br />
It is still possible to use that approach with the {{Pkg|linux-lts}} or other old kernels. The package to install the modules via [[DKMS]] is not available in the AUR anymore, but can be retrieved with {{ic|<nowiki>git clone https://aur.archlinux.org/anbox-modules-dkms</nowiki>}}, or resurected from [https://aur.archlinux.org/cgit/aur.git/commit/?h=anbox-git&id=0c9a9385694e680f5b277ca6f9326ad5d5df7dd3].<br />
<br />
=== Secure Boot error ===<br />
<br />
If you get this error message:<br />
<br />
modprobe: ERROR: could not insert 'ashmem_linux': Operation not permitted<br />
<br />
[[Secure Boot]] is likely blocking the module.<br />
You can either disable Secure Boot or sign the ashmem module yourself.<br />
<br />
More info can be found in the [https://github.com/anbox/anbox/blob/master/docs/install.md#on-ubuntu-1904-and-later Anbox Github Docs].<br />
<br />
== See also ==<br />
<br />
* [https://github.com/anbox/anbox Official Anbox Github Repo]<br />
* [https://anbox.io/ Anbox Website]<br />
* [https://mm.gravedo.de/blog/posts/2020-01-21-taking-the-anbox-journey-to-the-next-level Posting by the main Anbox developer]<br />
* [https://brauner.github.io/2019/01/09/android-binderfs.html Explanation about binderfs]</div>Puroflehttps://wiki.archlinux.org/index.php?title=Anbox_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=690118Anbox (简体中文)2021-08-01T17:09:11Z<p>Purofle: Created page with "Category:Virtualization_(简体中文) Category:Android (简体中文) en:Anbox ja:Anbox ru:Anbox zh-hans:Anbox {{Related articles start}} {{Bad transl..."</p>
<hr />
<div>[[Category:Virtualization_(简体中文)]]<br />
[[Category:Android (简体中文)]]<br />
[[en:Anbox]]<br />
[[ja:Anbox]]<br />
[[ru:Anbox]]<br />
[[zh-hans:Anbox]]<br />
{{Related articles start}}<br />
{{Bad translation (简体中文)|部分内容可能由机器翻译。}}<br />
{{Related|Linux Containers}}<br />
{{Related articles end}}<br />
Anbox 是一个可以在 GNU/Linux 发行版上运行 Android App 的 [[Linux_Containers|容器]]。<br />
<br />
== 准备工作 ==<br />
<br />
{{Note|Anbox 的 dkms 模块在内核版本 ≥5.7 下不会工作。请按照以下说明进行操作。 对于较老的内核请参阅 [[#较老的内核|较老的内核]]。}}<br />
<br />
您需要运行带有 ashmem 和 binder 模块的内核。但是它们不是 Arch Linux 的默认内核 ( linux ) 的一部分,所以您需要安装一个包含这些模块的内核。<br />
<br />
您可能还需要配置引导加载程序以使用不同的内核。<br />
<br />
您有多种选择:<br />
<br />
=== 使用 Linux-Zen ===<br />
<br />
{{Pkg|linux-zen}} 内核自带 Anbox 需要的模块。这可能是最简单的方式,因为您不必编译内核并且版本会定期更新。<br />
<br />
=== 编译内核 ===<br />
<br />
当然,您也可以自己重新编译 {{Pkg|linux}} 内核。请阅读 [[Kernel_(简体中文)#编译]] and [[#配置模块|配置模块]] 。<br />
<br />
您还可以从[[AUR]]里构建一个已经包含特定补丁的内核包, 请参阅 [https://aur.archlinux.org/packages/?K=linux+anbox AUR search "linux+anbox"].<br />
<br />
==== 配置模块 ====<br />
<br />
模块同样也可以被编译进内核里 ({{ic|y}}), 模块里 ({{ic|m}}), 或者不编译 ({{ic|n}}).此外,并非配置中的所有组合都是可能的,某些选项将需要其他选项。<br />
<br />
下面的的内核配置将把 ashmem 和 binder 编译为模块,而最后一个选项指定在 {{ic|/dev/}} 加载 binder 模块时在目录中创建三个设备。<br />
<br />
{{bc|1=<br />
CONFIG_ASHMEM=m <br />
CONFIG_ANDROID=y<br />
CONFIG_ANDROID_BINDER_IPC=m<br />
CONFIG_ANDROID_BINDERFS=n<br />
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"<br />
}}<br />
<br />
如果您要从 AUR 构建内核,那么您可以参考下面的步骤:<br />
<br />
# 运行 {{ic|makepkg --nobuild}}, 它将下载源代码,验证并提取。最后运行 {{ic|prepare()}} 函数.<br />
# 编辑位于内核目录底部的 {{ic|.config}} 文件。<br />
# 在 {{ic|prepare()}} 函数的末尾可能是一个命令,它使用来自配置的信息重新生成 makefile,也可能是 {{ic|make olddefconfig}}. 将它移动到 {{ic|build()}} 函数内,或自己执行一遍。<br />
# 运行 {{ic|makepkg --noextract}}, 它将在 {{ic|makepkg --nobuild}} 停止的地方继续。<br />
<br />
==== 使用 binderfs 进行配置 ====<br />
<br />
并不是每个人都对 Linux 中的 binder 模块感到满意。为了解决这些问题,binderfs诞生了。编译内核时必须在新旧两种方式之间进行选择。比如下面的选项就是针对于 binderfs 的。<br />
<br />
内核源代码还提供了一个简单的脚本来设置配置选项。它不会进行依赖项检查。当您在 {{ic|.config}} 文件所在的同一目录中时,执行以下命令:<br />
<br />
{{bc|<br />
scripts/config --module CONFIG_ASHMEM<br />
scripts/config --enable CONFIG_ANDROID<br />
scripts/config --enable CONFIG_ANDROID_BINDER_IPC<br />
scripts/config --enable CONFIG_ANDROID_BINDERFS<br />
scripts/config --set-str CONFIG_ANDROID_BINDER_DEVICES ""<br />
}}<br />
<br />
当您正在从从 AUR 构建内核时,这个脚本很方便,因为只需要在 PKGBUILD 中的正确位置插入这些命令就足够了。<br />
<br />
=== 启动新内核 ===<br />
<br />
请参阅引导加载程序的 wiki 页面了解如何使用新内核引导。您应该在启动 Anbox 之前切换到心的内核。<br />
<br />
== 安装 ==<br />
<br />
=== 加载模块 ===<br />
<br />
Anbox 不会自动加载模块,但是如果您在使用 linux-ken,就可以跳过此步骤。<br />
<br />
要临时加载,请使用:<br />
<br />
# modprobe -a binder-linux ashmem-linux<br />
<br />
要始终在启动时加载它们,可以通过 {{ic|systemd-modules-load.service}} 文件来实现。 为此,请在 {{ic|/etc/modules-load.d/}} 创建一个包含以下内容的 anbox.conf文件:<br />
<br />
{{hc|/etc/modules-load.d/anbox.conf|<br />
ashmem_linux<br />
binder_linux<br />
}}<br />
<br />
=== 挂载 binderfs ===<br />
<br />
{{Note | {{pkg|linux-zen}} 内核必须挂载 binderfs。 }}<br />
<br />
如果您的内核正在使用 binderfs,则还有一个步骤要做:挂载 binderfs 文件。<br />
<br />
Firstly, you will need a mountpoint. By default, Anbox will look at {{ic|/dev/binderfs}}. You can create that directory now, but it will be removed at boot time.<br />
首先,您需要一个挂载点。默认情况下,Anbox 将使用 {{ic|/dev/binderfs}}。 您可以直接创建该目录,但它会在启动时被删除。所以这里建议使用 [[systemd-tmpfiles]] 实现在启动时创建 {{ic|/dev/binderfs}}。为此,您需要在 {{ic|/etc/tmpfiles.d/}} 创建一个包含以下内容的文件:<br />
<br />
{{hc|/etc/tmpfiles.d/anbox.conf|<br />
d! /dev/binderfs 0755 root root<br />
}}<br />
<br />
其次您需要挂载 binder 文件系统。 这可以通过:<br />
<br />
# mount -t binder none /dev/binderfs<br />
<br />
如果想要在启动时挂载它,只需要在 [[fstab]] 中添加下面这一行。<br />
<br />
{{hc|/etc/fstab|<br />
none /dev/binderfs binder nofail 0 0<br />
}}<br />
<br />
{{警告|添加 {{ic|nofail}} 参数后,当您启动没有 binderfs 支持的内核时,您将无法进入恢复 shell。}}<br />
<br />
== 安装 Android 镜像 ==<br />
<br />
{{Note|现在的镜像均以过时 (基于 Android 7.1). 目前,上游没有可用的更新的镜像。另请参阅 [[Talk:Anbox#Anbox-Images outdated]].}}<br />
<br />
选择一个镜像来安装:<br />
<br />
* {{AUR|anbox-image}} (官方镜像)<br />
* {{AUR|anbox-image-houdini}} (包含 Houdini)<br />
* {{AUR|anbox-image-houdini-rooted}} (包含 Houdini 和 SuperSU) <br />
* {{AUR|anbox-image-gapps}} (包含 Houdini 和 OpenGApps) <br />
* {{AUR|anbox-image-gapps-rooted}} (包含 Houdini, OpenGApps 和 SuperSU) <br />
* 您也可以通过在 [[AUR]] 内搜索 [https://aur.archlinux.org/packages/?K=anbox-image anbox-image]找到更多的镜像。<br />
<br />
{{Tip |<br />
* 通常,在 x86_64 计算机上运行 ARM 应用程序需要 Houdini。<br />
* 如果您使用 GMS,OpenGApps 是一个不错的选择。}}<br />
<br />
=== 安装 Anbox ===<br />
<br />
安装 {{AUR|anbox-git}}。<br />
<br />
Afterwards, [[start/enable]] {{ic|anbox-container-manager.service}}.<br />
<br />
You have now all the required steps done to use Anbox! In the menu of your desktop environment, you should find several entries in the category ''Others'', which can now be launched.<br />
<br />
The first call will take longer. Behind the scenes, {{ic|anbox session-manager}} will be launched. For testing purposes, you can also execute {{ic|anbox session-manager}} manually in a terminal. That is '''very''' useful if anbox crashes and you want to report or fix the bug. Just launch it, and wait until it crashes (if ever).<br />
<br />
There is also a ''systemd'' unit for users, which can be used to start the session-manager on bootup; [[start/enable]] the {{ic|anbox-session-manager.service}} user unit. An advantage of this unit is that logs can be found in the event of a crash:<br />
<br />
$ journalctl --user -b -u anbox-session-manager<br />
<br />
Keep in mind though, that when it crashes and you start a new app, it will also start the session-manager, but it will be run independently from ''systemd''.<br />
<br />
== Network ==<br />
<br />
=== Via NetworkManager ===<br />
<br />
If you are using [[NetworkManager]] you can use it to configure the networking.<br />
<br />
Execute the following command to create the bridge connection:<br />
<br />
$ nmcli con add type bridge ifname anbox0 -- connection.id anbox-net ipv4.method shared ipv4.addresses 192.168.250.1/24<br />
<br />
* {{ic|ifname anbox0}} specifies the bridge interface name, in this case {{ic|anbox0}}. Do not change this as Anbox will only detect the bridge interface if it is named {{ic|anbox0}}.<br />
* {{ic|connection.id anbox-net}} specifies the name of the connection to be {{ic|anbox-net}} when it appears in [[NetworkManager]]. You can change this if you wish.<br />
* {{ic|ipv4.method shared}} instructs [[NetworkManager]] to create a NAT network and route outgoing packets according to the system routing rules. For that, the {{Pkg|dnsmasq}} package is required. [[dnsmasq]] does not needs to be configured or be started as systemd service, it will be used behind the scenes by NetworkManager — if it is not available, this step will fail silently. You can leave this and the {{ic|ipv4.addresses}} parameter out if you wish to attach the Anbox container directly to a specific network, see [[Network bridge#With NetworkManager]]. If you choose this option, you must also change the network configuration of the container in {{ic|anbox-container-manager.service}}, see the next bullet point.<br />
* {{ic|ipv4.addresses 192.168.250.1/24}} specifies the default gateway and subnet of the NAT network. If you wish to change this (e.g. to {{ic|192.168.42.1/24}}) you must also indicate the new subnet to anbox in the {{ic|anbox-container-manager.service}} using: {{ic|1=--container-network-address=192.168.42.2/24 --container-network-gateway=192.168.42.1}}<br />
<br />
[[NetworkManager]] will automatically setup the bridge every reboot so you only need to execute the command once.<br />
<br />
=== Via systemd-networkd ===<br />
<br />
The package {{AUR|anbox-git}} provides configuration files for {{ic|systemd-networkd}} in {{ic|/usr/lib/systemd/network/}} to enable networking in anbox.<br />
<br />
Therefore, you can [[start/enable]] {{ic|systemd-networkd}} before starting {{ic|anbox-container-manager.service}}.<br />
<br />
=== Via anbox-bridge script ===<br />
<br />
Alternatively you can use the anbox-bridge script [https://raw.githubusercontent.com/anbox/anbox/master/scripts/anbox-bridge.sh used by the project].<br />
<br />
You must execute {{ic|anbox-bridge}} every time before starting {{ic|anbox-container-manager.service}} in order to get network working in Anbox. The easiest solution for that is to create a drop-in file for the service.<br />
<br />
{{hc|/etc/systemd/system/anbox-container-manager.service.d/enable-anbox-bridge.conf|2= <br />
[Service]<br />
ExecStartPre=/usr/bin/anbox-bridge start<br />
ExecStopPost=/usr/bin/anbox-bridge stop<br />
}}<br />
<br />
== Usage ==<br />
<br />
You can run the Android applications on your desktop's launcher on '''Other''' category.<br />
<br />
If you want to use [[adb]] to debug, install {{Pkg|android-tools}}. The {{ic|anbox session-manager}} must already be running when launching it.<br />
<br />
$ adb shell<br />
<br />
=== Installing apps ===<br />
<br />
Unless you picked an image with Houdini, Anbox does not have support for ARM applications. So apps must have a x86_64 architecture.<br />
<br />
==== Through adb ====<br />
<br />
To install {{ic|''/path/to/app.apk''}}<br />
<br />
$ adb install ''/path/to/app.apk''<br />
<br />
To get the list of installed applications<br />
<br />
$ adb shell pm list packages<br />
<br />
Note that output will be similar to {{ic|''package:app.name''}}, where {{ic|''app.name''}} is different from the one displayed in the Anbox container.<br />
<br />
To uninstall {{ic|''app.name''}}<br />
<br />
$ adb uninstall ''app.name''<br />
<br />
If {{ic|''app.name''}} is a system app<br />
<br />
$ adb uninstall --user 0 ''app.name''<br />
<br />
==== Through apps stores ====<br />
<br />
Apps can be easily installed through apps stores. In {{AUR|anbox-image-gapps}} PlayStore is included.<br />
<br />
=== Sensor data ===<br />
<br />
Via dbus different sensors can be set. Documentation on that can be found at<br />
[https://github.com/anbox/anbox/blob/master/docs/dbus.md dbus.md].<br />
<br />
==== Temperature data ====<br />
<br />
That is the example from the author (PRs [https://github.com/anbox/anbox/pull/1522 #1522] & [https://github.com/anbox/anbox/pull/1522 #1540]):<br />
<br />
$ dbus-send --session --dest=org.anbox --print-reply /org/anbox org.freedesktop.DBus.Properties.Set string:org.anbox.Sensors string:Temperature variant:double:25.1<br />
<br />
==== GPS data ====<br />
<br />
(introduced by PR [https://github.com/anbox/anbox/pull/1606 #1606])<br />
<br />
GPS sensor data can also be manipulated. <br />
<br />
If your PC has a WWAN card, you can use {{Pkg|gpsd}} and the code from the PR to feed Anbox with GPS data. You do not need to have a SIM-Card for GPS.<br />
<br />
Otherwise, you can also look at the PR to learn how to feed it fake data with the help of [https://www.nmeagen.org].<br />
<br />
=== Root shell ===<br />
<br />
With this [https://github.com/anbox/anbox/blob/master/scripts/anbox-shell.sh script] from the Anbox project one can get a root shell inside the Android container.<br />
<br />
It is not part of the {{AUR|anbox-git}} package, and it also does not use [[adb]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Android developer options ===<br />
<br />
Some extra steps need to be done besides unlocking them the same way you do on an android phone.<br />
When installing the [[#Install Android Image|android image]], some modifications to {{ic|products/anbox.xml}} are required:<br />
<br />
* {{ic|1=<unavailable-feature name="android.hardware.usb.host" />}} is the reason why they are not available.<br />
* {{ic|1=<feature name="android.software.backup" />}} will be needed too, to avoid a NullPointerException.<br />
<br />
(reference: [https://github.com/anbox/anbox/issues/444 Github issue #444])<br />
<br />
=== Getting debugging information ===<br />
<br />
Obviously, it is helpful to have debugging symbols in the Anbox build. For that, when [[#Install Anbox|compiling Anbox]], add {{ic|1=options=('!strip')}} to the PKGBUILD, as by default they are removed. And, use either {{ic|1=-DCMAKE_BUILD_TYPE=RelWithDebInfo}} or {{ic|1=-DCMAKE_BUILD_TYPE=Debug}} in the cmake call.<br />
<br />
But there is more to it! Anbox uses [https://github.com/anbox/anbox/tree/master/external/backward-cpp backward-cpp]. If you do not delete the build files for Anbox, it will print pretty stack traces when crashing, which point out the places in the source code.<br />
<br />
Also see the remarks in [[#Install Anbox|Install Anbox]].<br />
<br />
== Troubleshooting ==<br />
<br />
If you run into issues, take a look at the official Issue Tracker: [https://github.com/anbox/anbox/issues]<br />
<br />
=== Old CPUs ===<br />
<br />
Anbox requires support for SSE 4.1/4.2 and SSSE 3, because Android wants that too.<br />
Some older CPUs do not provide that, so you probably cannot use Anbox, see:<br />
[https://github.com/anbox/anbox/issues/499#issuecomment-399118684 Anbox Github Issue 499].<br />
<br />
=== Old kernels ===<br />
<br />
Before the kernel modules were mainlined, they were out of tree modules, which needed to be installed seperately from the kernel (Like it is the case for the nvidia kernel modules). They are not compatible with kernel 5.7 or newer.<br />
<br />
It is still possible to use that approach with the {{Pkg|linux-lts}} or other old kernels. The package to install the modules via [[DKMS]] is not available in the AUR anymore, but can be retrieved with {{ic|<nowiki>git clone https://aur.archlinux.org/anbox-modules-dkms</nowiki>}}, or resurected from [https://aur.archlinux.org/cgit/aur.git/commit/?h=anbox-git&id=0c9a9385694e680f5b277ca6f9326ad5d5df7dd3].<br />
<br />
=== Secure Boot error ===<br />
<br />
If you get this error message:<br />
<br />
modprobe: ERROR: could not insert 'ashmem_linux': Operation not permitted<br />
<br />
[[Secure Boot]] is likely blocking the module.<br />
You can either disable Secure Boot or sign the ashmem module yourself.<br />
<br />
More info can be found in the [https://github.com/anbox/anbox/blob/master/docs/install.md#on-ubuntu-1904-and-later Anbox Github Docs].<br />
<br />
== See also ==<br />
<br />
* [https://github.com/anbox/anbox Official Anbox Github Repo]<br />
* [https://anbox.io/ Anbox Website]<br />
* [https://mm.gravedo.de/blog/posts/2020-01-21-taking-the-anbox-journey-to-the-next-level Posting by the main Anbox developer]<br />
* [https://brauner.github.io/2019/01/09/android-binderfs.html Explanation about binderfs]</div>Puroflehttps://wiki.archlinux.org/index.php?title=Anbox&diff=690112Anbox2021-08-01T16:07:47Z<p>Purofle: </p>
<hr />
<div>[[Category:Virtualization]]<br />
[[Category:Android]]<br />
[[ja:Anbox]]<br />
[[ru:Anbox]]<br />
[[zh-hans:Anbox]]<br />
{{Related articles start}}<br />
{{Related|Linux Containers}}<br />
{{Related articles end}}<br />
Anbox is a [[Linux_Containers|container-based]] software for running Android on GNU/Linux distributions.<br />
<br />
== Prerequisite ==<br />
<br />
{{Note|The dkms modules do not work on kernels ≥5.7 anymore. Follow the instructions below instead. For older kernels see [[#Old kernels|Old kernels]].}}<br />
<br />
You need to run a kernel which comes with the ashmem and binder modules. They are not part of Arch Linux's default kernel ({{Pkg|linux}}), thus you need to install a kernel which ships these modules.<br />
<br />
You might also need to configure your bootloader to use a different kernel.<br />
<br />
You have multiple options:<br />
<br />
=== Using Linux-Zen ===<br />
<br />
The {{Pkg|linux-zen}} kernel includes the necessary modules. This might be the most comfortable way, as you do not have to compile the kernel (which takes a long time) and will receive updated versions regularly.<br />
<br />
=== Building a kernel ===<br />
<br />
Alternatively, you can recompile the {{Pkg|linux}} kernel — or other kernel packages (>=5.7) — with the necessary options. Please read [[Kernel#Compilation]] and [[#Necessary config options|Necessary config options]] below.<br />
<br />
You can also build a kernel package that already includes the specific patches from [[AUR]], see [https://aur.archlinux.org/packages/?K=linux+anbox AUR search "linux+anbox"].<br />
<br />
==== Necessary config options ====<br />
<br />
Modules can either be compiled into the kernel ({{ic|y}}), into modules ({{ic|m}}), or not at all ({{ic|n}}). Also, not all combinations in the config are possible, and some options will require other options.<br />
<br />
The config options below will compile ashmem and binder as modules, while the last option specifies that there will be three devices created in the {{ic|/dev/}} directory, when the binder module is loaded.<br />
<br />
{{bc|1=<br />
CONFIG_ASHMEM=m <br />
CONFIG_ANDROID=y<br />
CONFIG_ANDROID_BINDER_IPC=m<br />
CONFIG_ANDROID_BINDERFS=n<br />
CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"<br />
}}<br />
<br />
When building a kernel from the AUR, one can do it with these steps:<br />
<br />
# run {{ic|makepkg --nobuild}}, which will download the sources, verify and extract them and run the {{ic|prepare()}} function.<br />
# edit the {{ic|.config}} file (with the dot in the filename), which is located at the base of the kernel directory.<br />
# at the end of the {{ic|prepare()}} function was probably a command which regenerates the makefiles with information from the config, possibly {{ic|make olddefconfig}}. Move that to the {{ic|build()}} function, or execute it yourself.<br />
# run {{ic|makepkg --noextract}}, which will continue from the place where {{ic|makepkg --nobuild}} stopped.<br />
<br />
==== config using binderfs ====<br />
<br />
Not everybody was happy with the binder module in Linux. To address the issues, binderfs was created. One has to choose between the old and the new way when compiling the kernel. With the options below one will use binderfs instead.<br />
<br />
With the kernel sources comes also a simple script to set config options. It will not do dependency checks, just like when editing the config by hand. When being in the same directory where the {{ic|.config}} file lies, one can execute the following commands:<br />
<br />
{{bc|<br />
scripts/config --module CONFIG_ASHMEM<br />
scripts/config --enable CONFIG_ANDROID<br />
scripts/config --enable CONFIG_ANDROID_BINDER_IPC<br />
scripts/config --enable CONFIG_ANDROID_BINDERFS<br />
scripts/config --set-str CONFIG_ANDROID_BINDER_DEVICES ""<br />
}}<br />
<br />
This script is handy when building a kernel from the AUR, as it is enough to insert these lines at the right place in the PKGBUILD.<br />
<br />
=== Booting the new kernel ===<br />
<br />
Please refer to the wiki page of your bootloader, to find out, how to boot with the new kernel. Booting into a newer kernel (version) is one of the few occasions when you have to reboot a Linux system. You should do that before starting Anbox.<br />
<br />
== Installation ==<br />
<br />
=== Loading the modules ===<br />
<br />
Anbox does not load the modules on demand, starting an app will fail if they are not loaded. Linux-zen kernel provide them built in and you do not need to load.<br />
<br />
To load them right now, use:<br />
<br />
# modprobe -a binder-linux ashmem-linux<br />
<br />
To load them always at boot, one can load them via the {{ic|systemd-modules-load.service}}. To do so, create a file inside {{ic|/etc/modules-load.d/}}, which contains the lines:<br />
<br />
{{hc|/etc/modules-load.d/anbox.conf|<br />
ashmem_linux<br />
binder_linux<br />
}}<br />
<br />
=== Mounting binderfs ===<br />
<br />
{{Note | The {{pkg|linux-zen}} kernel is using binderfs (for reference: [https://github.com/archlinux/svntogit-packages/commit/ec47edcc45f73b4946015e9f28a419e27db2fda3#diff-3e341d2d9c67be01819b25b25d5e53ea3cdf3a38d28846cda85a195eb9b7203a commit for android modules implementation]). }}<br />
<br />
If your kernel uses binderfs, there is one more step to do: Mounting a binder filesystem.<br />
<br />
Firstly, you will need a mountpoint. By default, Anbox will look at {{ic|/dev/binderfs}}. You can create that directory now, but it will be removed at boot time.<br />
You can use [[systemd-tmpfiles]] to create this directory at boot time. For that, create a file in {{ic|/etc/tmpfiles.d/}} with the content:<br />
<br />
{{hc|/etc/tmpfiles.d/anbox.conf|<br />
d! /dev/binderfs 0755 root root<br />
}}<br />
<br />
Secondly, you need to mount the binder filesystem. This can be done by<br />
<br />
# mount -t binder none /dev/binderfs<br />
<br />
To mount it always at boot, add a line in the [[fstab]]. Using the option {{ic|nofail}} here will not greet you with a recovery shell when you are booting a kernel without binderfs support (such as the standard kernel).<br />
<br />
{{hc|/etc/fstab|<br />
none /dev/binderfs binder nofail 0 0<br />
}}<br />
<br />
=== Install Android Image ===<br />
<br />
{{Note|The images are outdated (based on Android 7.1). For now there are no newer images available from upstream. See also [[Talk:Anbox#Anbox-Images outdated]].}}<br />
<br />
[[Install]] one of these images:<br />
<br />
* {{AUR|anbox-image}} (official Anbox image)<br />
* {{AUR|anbox-image-houdini}} (includes Houdini)<br />
* {{AUR|anbox-image-houdini-rooted}} (includes Houdini and SuperSU) <br />
* {{AUR|anbox-image-gapps}} (includes Houdini and OpenGApps) <br />
* {{AUR|anbox-image-gapps-rooted}} (includes Houdini, OpenGApps and SuperSU) <br />
* You can find more images in the [[AUR]], search for [https://aur.archlinux.org/packages/?K=anbox-image anbox-image].<br />
<br />
{{Tip |<br />
* Generally, one needs Houdini to run ARM applications on a x86_64 computer. <br />
* If you want Google apps, OpenGApps is a good way to go. }}<br />
<br />
=== Install Anbox ===<br />
<br />
[[Install]] the {{AUR|anbox-git}} package.<br />
<br />
Afterwards, [[start/enable]] {{ic|anbox-container-manager.service}}.<br />
<br />
You have now all the required steps done to use Anbox! In the menu of your desktop environment, you should find several entries in the category ''Others'', which can now be launched.<br />
<br />
The first call will take longer. Behind the scenes, {{ic|anbox session-manager}} will be launched. For testing purposes, you can also execute {{ic|anbox session-manager}} manually in a terminal. That is '''very''' useful if anbox crashes and you want to report or fix the bug. Just launch it, and wait until it crashes (if ever).<br />
<br />
There is also a ''systemd'' unit for users, which can be used to start the session-manager on bootup; [[start/enable]] the {{ic|anbox-session-manager.service}} user unit. An advantage of this unit is that logs can be found in the event of a crash:<br />
<br />
$ journalctl --user -b -u anbox-session-manager<br />
<br />
Keep in mind though, that when it crashes and you start a new app, it will also start the session-manager, but it will be run independently from ''systemd''.<br />
<br />
== Network ==<br />
<br />
=== Via NetworkManager ===<br />
<br />
If you are using [[NetworkManager]] you can use it to configure the networking.<br />
<br />
Execute the following command to create the bridge connection:<br />
<br />
$ nmcli con add type bridge ifname anbox0 -- connection.id anbox-net ipv4.method shared ipv4.addresses 192.168.250.1/24<br />
<br />
* {{ic|ifname anbox0}} specifies the bridge interface name, in this case {{ic|anbox0}}. Do not change this as Anbox will only detect the bridge interface if it is named {{ic|anbox0}}.<br />
* {{ic|connection.id anbox-net}} specifies the name of the connection to be {{ic|anbox-net}} when it appears in [[NetworkManager]]. You can change this if you wish.<br />
* {{ic|ipv4.method shared}} instructs [[NetworkManager]] to create a NAT network and route outgoing packets according to the system routing rules. For that, the {{Pkg|dnsmasq}} package is required. [[dnsmasq]] does not needs to be configured or be started as systemd service, it will be used behind the scenes by NetworkManager — if it is not available, this step will fail silently. You can leave this and the {{ic|ipv4.addresses}} parameter out if you wish to attach the Anbox container directly to a specific network, see [[Network bridge#With NetworkManager]]. If you choose this option, you must also change the network configuration of the container in {{ic|anbox-container-manager.service}}, see the next bullet point.<br />
* {{ic|ipv4.addresses 192.168.250.1/24}} specifies the default gateway and subnet of the NAT network. If you wish to change this (e.g. to {{ic|192.168.42.1/24}}) you must also indicate the new subnet to anbox in the {{ic|anbox-container-manager.service}} using: {{ic|1=--container-network-address=192.168.42.2/24 --container-network-gateway=192.168.42.1}}<br />
<br />
[[NetworkManager]] will automatically setup the bridge every reboot so you only need to execute the command once.<br />
<br />
=== Via systemd-networkd ===<br />
<br />
The package {{AUR|anbox-git}} provides configuration files for {{ic|systemd-networkd}} in {{ic|/usr/lib/systemd/network/}} to enable networking in anbox.<br />
<br />
Therefore, you can [[start/enable]] {{ic|systemd-networkd}} before starting {{ic|anbox-container-manager.service}}.<br />
<br />
=== Via anbox-bridge script ===<br />
<br />
Alternatively you can use the anbox-bridge script [https://raw.githubusercontent.com/anbox/anbox/master/scripts/anbox-bridge.sh used by the project].<br />
<br />
You must execute {{ic|anbox-bridge}} every time before starting {{ic|anbox-container-manager.service}} in order to get network working in Anbox. The easiest solution for that is to create a drop-in file for the service.<br />
<br />
{{hc|/etc/systemd/system/anbox-container-manager.service.d/enable-anbox-bridge.conf|2= <br />
[Service]<br />
ExecStartPre=/usr/bin/anbox-bridge start<br />
ExecStopPost=/usr/bin/anbox-bridge stop<br />
}}<br />
<br />
== Usage ==<br />
<br />
You can run the Android applications on your desktop's launcher on '''Other''' category.<br />
<br />
If you want to use [[adb]] to debug, install {{Pkg|android-tools}}. The {{ic|anbox session-manager}} must already be running when launching it.<br />
<br />
$ adb shell<br />
<br />
=== Installing apps ===<br />
<br />
Unless you picked an image with Houdini, Anbox does not have support for ARM applications. So apps must have a x86_64 architecture.<br />
<br />
==== Through adb ====<br />
<br />
To install {{ic|''/path/to/app.apk''}}<br />
<br />
$ adb install ''/path/to/app.apk''<br />
<br />
To get the list of installed applications<br />
<br />
$ adb shell pm list packages<br />
<br />
Note that output will be similar to {{ic|''package:app.name''}}, where {{ic|''app.name''}} is different from the one displayed in the Anbox container.<br />
<br />
To uninstall {{ic|''app.name''}}<br />
<br />
$ adb uninstall ''app.name''<br />
<br />
If {{ic|''app.name''}} is a system app<br />
<br />
$ adb uninstall --user 0 ''app.name''<br />
<br />
==== Through apps stores ====<br />
<br />
Apps can be easily installed through apps stores. In {{AUR|anbox-image-gapps}} PlayStore is included.<br />
<br />
=== Sensor data ===<br />
<br />
Via dbus different sensors can be set. Documentation on that can be found at<br />
[https://github.com/anbox/anbox/blob/master/docs/dbus.md dbus.md].<br />
<br />
==== Temperature data ====<br />
<br />
That is the example from the author (PRs [https://github.com/anbox/anbox/pull/1522 #1522] & [https://github.com/anbox/anbox/pull/1522 #1540]):<br />
<br />
$ dbus-send --session --dest=org.anbox --print-reply /org/anbox org.freedesktop.DBus.Properties.Set string:org.anbox.Sensors string:Temperature variant:double:25.1<br />
<br />
==== GPS data ====<br />
<br />
(introduced by PR [https://github.com/anbox/anbox/pull/1606 #1606])<br />
<br />
GPS sensor data can also be manipulated. <br />
<br />
If your PC has a WWAN card, you can use {{Pkg|gpsd}} and the code from the PR to feed Anbox with GPS data. You do not need to have a SIM-Card for GPS.<br />
<br />
Otherwise, you can also look at the PR to learn how to feed it fake data with the help of [https://www.nmeagen.org].<br />
<br />
=== Root shell ===<br />
<br />
With this [https://github.com/anbox/anbox/blob/master/scripts/anbox-shell.sh script] from the Anbox project one can get a root shell inside the Android container.<br />
<br />
It is not part of the {{AUR|anbox-git}} package, and it also does not use [[adb]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Android developer options ===<br />
<br />
Some extra steps need to be done besides unlocking them the same way you do on an android phone.<br />
When installing the [[#Install Android Image|android image]], some modifications to {{ic|products/anbox.xml}} are required:<br />
<br />
* {{ic|1=<unavailable-feature name="android.hardware.usb.host" />}} is the reason why they are not available.<br />
* {{ic|1=<feature name="android.software.backup" />}} will be needed too, to avoid a NullPointerException.<br />
<br />
(reference: [https://github.com/anbox/anbox/issues/444 Github issue #444])<br />
<br />
=== Getting debugging information ===<br />
<br />
Obviously, it is helpful to have debugging symbols in the Anbox build. For that, when [[#Install Anbox|compiling Anbox]], add {{ic|1=options=('!strip')}} to the PKGBUILD, as by default they are removed. And, use either {{ic|1=-DCMAKE_BUILD_TYPE=RelWithDebInfo}} or {{ic|1=-DCMAKE_BUILD_TYPE=Debug}} in the cmake call.<br />
<br />
But there is more to it! Anbox uses [https://github.com/anbox/anbox/tree/master/external/backward-cpp backward-cpp]. If you do not delete the build files for Anbox, it will print pretty stack traces when crashing, which point out the places in the source code.<br />
<br />
Also see the remarks in [[#Install Anbox|Install Anbox]].<br />
<br />
== Troubleshooting ==<br />
<br />
If you run into issues, take a look at the official Issue Tracker: [https://github.com/anbox/anbox/issues]<br />
<br />
=== Old CPUs ===<br />
<br />
Anbox requires support for SSE 4.1/4.2 and SSSE 3, because Android wants that too.<br />
Some older CPUs do not provide that, so you probably cannot use Anbox, see:<br />
[https://github.com/anbox/anbox/issues/499#issuecomment-399118684 Anbox Github Issue 499].<br />
<br />
=== Old kernels ===<br />
<br />
Before the kernel modules were mainlined, they were out of tree modules, which needed to be installed seperately from the kernel (Like it is the case for the nvidia kernel modules). They are not compatible with kernel 5.7 or newer.<br />
<br />
It is still possible to use that approach with the {{Pkg|linux-lts}} or other old kernels. The package to install the modules via [[DKMS]] is not available in the AUR anymore, but can be retrieved with {{ic|<nowiki>git clone https://aur.archlinux.org/anbox-modules-dkms</nowiki>}}, or resurected from [https://aur.archlinux.org/cgit/aur.git/commit/?h=anbox-git&id=0c9a9385694e680f5b277ca6f9326ad5d5df7dd3].<br />
<br />
=== Secure Boot error ===<br />
<br />
If you get this error message:<br />
<br />
modprobe: ERROR: could not insert 'ashmem_linux': Operation not permitted<br />
<br />
[[Secure Boot]] is likely blocking the module.<br />
You can either disable Secure Boot or sign the ashmem module yourself.<br />
<br />
More info can be found in the [https://github.com/anbox/anbox/blob/master/docs/install.md#on-ubuntu-1904-and-later Anbox Github Docs].<br />
<br />
== See also ==<br />
<br />
* [https://github.com/anbox/anbox Official Anbox Github Repo]<br />
* [https://anbox.io/ Anbox Website]<br />
* [https://mm.gravedo.de/blog/posts/2020-01-21-taking-the-anbox-journey-to-the-next-level Posting by the main Anbox developer]<br />
* [https://brauner.github.io/2019/01/09/android-binderfs.html Explanation about binderfs]</div>Puroflehttps://wiki.archlinux.org/index.php?title=Installation_guide_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=671061Installation guide (简体中文)2021-05-14T14:29:06Z<p>Purofle: add dhcpcd and iwd</p>
<hr />
<div>[[Category:Installation process (简体中文)]]<br />
[[ar:Installation guide]]<br />
[[bg:Installation guide]]<br />
[[bs:Installation guide]]<br />
[[cs:Installation guide]]<br />
[[da:Installation guide]]<br />
[[de:Arch Install Scripts]]<br />
[[el:Installation guide]]<br />
[[en:Installation guide]]<br />
[[es:Installation guide]]<br />
[[fa:راهنمای تازهکاران]]<br />
[[fi:Installation guide]]<br />
[[fr:Arch install scripts]]<br />
[[hr:Installation guide]]<br />
[[hu:Installation guide]]<br />
[[id:Installation guide]]<br />
[[it:Installation guide]]<br />
[[ja:インストールガイド]]<br />
[[ko:Installation guide]]<br />
[[lt:Installation guide]]<br />
[[nl:Installation guide]]<br />
[[pl:Installation guide]]<br />
[[pt:Installation guide]]<br />
[[ru:Installation guide]]<br />
[[sk:Installation guide]]<br />
[[sr:Installation guide]]<br />
[[sv:Installation guide]]<br />
[[th:Installation guide]]<br />
[[tr:Installation guide]]<br />
[[uk:Installation guide]]<br />
[[zh-hant:Installation guide]]<br />
{{TranslationStatus (简体中文)|Installation guide|2021-4-30|659704}}<br />
本文将指导如何用官方安装镜像启动的 Live 系统安装 [[Arch Linux (简体中文)|Arch Linux]]。安装介质现提供无障碍辅助功能,对此 [[Install Arch Linux with accessibility options|使用无障碍辅助选项安装 Arch Linux (英文)]] 页面有详细描述。关于其它的安装方法, 请参阅 [[:Category:Installation process]]。<br />
<br />
建议在安装前阅读 [[FAQ (简体中文)|FAQ]]。对于本文中使用的惯用术语,请参阅 [[Help:Reading (简体中文)|Help:Reading]]。请注意,代码段可能会有占位符(格式是 {{ic|''italics''}}),您可能需要手动去掉它们。<br />
<br />
有关更详细的说明,请阅读本指南内相应的 [[ArchWiki:About (简体中文)|ArchWiki]] 文章或各类程序的[[Man page (简体中文)|手册]]。有关配置的概述,请参阅 {{man|7|archlinux}}{{Dead link (简体中文)|2021|02|08}}。若需要交互帮助,可以使用 [[IRC channel|IRC 频道]]和[https://bbs.archlinux.org/ 论坛]。<br />
<br />
Arch Linux 能运行在最少 512 MiB 内存的 [[w:zh:X86-64|x86_64]] 机器上,但从安装媒介启动系统并成功安装需要更多的内存。[https://lists.archlinux.org/pipermail/arch-releng/2020-May/003957.html] 基本安装将占用小于 2 GiB 的存储空间。由于安装过程中需要从远程存储库获取软件包,计算机将需要一个有效的互联网连接。<br />
<br />
== 安装前的准备 ==<br />
<br />
=== 获取安装映像 ===<br />
<br />
访问 [https://archlinux.org/download/ 下载] 页面,并根据需要的引导方式,获取 ISO 文件或 netboot 映像以及相应的 [[GnuPG]] 签名。<br />
<br />
=== 验证签名 ===<br />
<br />
建议使用前先验证所下载文件的签名,特别是从 ''HTTP 镜像源'' 下载的文件,因为 HTTP 连接一般来说容易遭到拦截而 [http://www2.cs.arizona.edu/stork/packagemanagersecurity/attacks-on-package-managers.html 提供恶意镜像]。<br />
<br />
在一台已经安装 [[GnuPG]] 的系统上,可通过下载 ''PGP 签名'' (在 [https://archlinux.org/download/ 下载] 页面的 ''Checksums'' 下方) 到 ISO 文件所在的路径,然后用以下方式 [[GnuPG#Verify a signature|验证]]:<br />
<br />
$ gpg --keyserver-options auto-key-retrieve --verify archlinux-''version''-x86_64.iso.sig<br />
<br />
另外,在一台已经安装 Arch Linux 的计算机上可以通过以下方式验证:<br />
<br />
$ pacman-key -v archlinux-''version''-x86_64.iso.sig<br />
<br />
{{注意|<br />
* 如果安装映像是从镜像站点下载,而不是从 [https://archlinux.org/download/ archlinux.org] 下载的话,则签名是可以被伪造的。在这种情况下,请确保用来解码签名的公钥是被另一个可信的密钥签署的。{{ic|gpg}} 命令将会输出公钥的指纹。<br />
* 另一种验证签名的方法是确保公钥的指纹等于其中一位签署了 ISO 文件 [https://archlinux.org/people/developers/ Arch Linux 开发者]的指纹。请参阅 [[Wikipedia:Public-key_cryptography]] 获取更多关于公钥加密的信息。<br />
}}<br />
<br />
=== 准备安装映像 ===<br />
<br />
安装映像可以通过 [[USB flash installation medium|USB 闪存盘]]、[[Optical disc drive#Burning|光盘]]和带 [[PXE]] 的网络提供给目标机器:请按照合适的文章,使用所选映像为自己准备安装介质。<br />
<br />
=== 启动到 Live 环境 ===<br />
<br />
{{注意|Arch Linux 安装镜像不支持安全启动(Secure Boot)。要引导安装媒介,需要 [[Unified Extensible Firmware Interface/Secure Boot#Disabling Secure Boot|禁用安全启动]]。如果需要,可在完成安装后重新配置 [[Secure Boot|安全启动]]。}}<br />
<br />
# 选择从带有 Arch 安装文件的媒介启动,通常是要在 [[w:Power-on self test|计算机开机自检]] 时按下某个按键,一般在启动画面会有提示。具体情况请参考主板说明书。<br />
# 当引导加载程序菜单出现时,选择 ''Arch Linux install medium'' 并按 {{ic|Enter}} 进入安装环境。{{提示|安装映像使用 [[systemd-boot]] 在 UEFI 模式下引导,使用 [[syslinux]] 在 BIOS 模式下引导。请参阅 [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/docs/README.bootparams README.bootparams] 获取 [[Kernel parameters#Configuration|引导参数]] 列表。}}<br />
# 您将会以 root 身份登录进一个[[Wikipedia:Virtual console|虚拟控制台]],默认的 Shell 是 [[Zsh]]。<br />
<br />
如果想一边安装,一边使用 [https://lynx.invisible-island.net/lynx_help/Lynx_users_guide.html Lynx] 查看本指南,可以使用 {{ic|Alt+''箭头''}} [[Keyboard shortcuts|快捷键]]切换不同的控制台。要[[textedit|编辑]]配置文件,可以使用 {{man|1|mcedit}}、[[nano#Usage|nano]] 和 [[vim#Usage|vim]]。请参阅 [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/packages.x86_64 packages.x86_64] 获取安装介质中包含的软件包列表。<br />
<br />
=== 键盘布局 ===<br />
<br />
[[Keyboard_configuration_in_console|控制台键盘布局]]默认为 {{ic|us}}(美式键盘映射)。列出所有可用的键盘布局,可以使用:<br />
<br />
# ls /usr/share/kbd/keymaps/**/*.map.gz<br />
<br />
如果您想要更改键盘布局,可以将一致的文件名添加进 {{man|1|loadkeys}},但请省略路径和扩展名。比如,要添加 [[Wikipedia:File:KB_Germany.svg|German]] 键盘布局:<br />
<br />
# loadkeys de-latin1<br />
<br />
[[Console fonts|控制台字体]] 位于 {{ic|/usr/share/kbd/consolefonts/}} 目录中,设置方式请参考 {{man|8|setfont}}。<br />
<br />
根据 [[Getting and installing Arch (简体中文)|获取和安装 Arch Linux]] 中所述,下载并引导安装介质。启动完成后将会自动以 root 身份登录虚拟控制台并进入 [[Zsh (简体中文)|Zsh]] 命令提示符。<br />
<br />
=== 验证启动模式 ===<br />
<br />
要验证启动模式,请用下列命令列出 [[efivars]] 目录:<br />
<br />
# ls /sys/firmware/efi/efivars<br />
<br />
如果命令没有错误地显示了目录,则系统以 UEFI 模式启动。 如果目录不存在,系统可能以 [[w:BIOS|BIOS]] 模式 (或 [[Wikipedia:Compatibility Support Module|CSM]] 模式) 启动。如果系统未以您想要的模式引导启动,请参考您的主板手册。<br />
<br />
=== 连接到因特网 ===<br />
<br />
要在 Live 环境中配置网络连接,请跟随以下步骤:<br />
<br />
* 确保系统已经启用了 [[Network configuration#Network interfaces|网络接口]],用 {{man|8|ip-link}} 检查: <br>{{bc|# ip link}}<br />
<br />
* 对于无线局域网(Wi-Fi)和无线广域网(WWAN),请确保网卡未被 [[rfkill]] 禁用。<br />
<br />
* 要连接到网络:<br />
** 有线以太网 —— 连接网线。<br />
** WiFi —— 使用 [[iwctl]] 验证无线网络。<br />
** 移动宽带调制解调器(移动网卡) - 使用 [[mmcli]] 实用程序连接到移动网络。<br />
<br />
* 配置网络连接:<br />
** [[DHCP]]: 动态 IP 地址和 DNS 服务器分配(由 [[systemd-networkd]] 和 [[systemd-resolved]] 提供机能)对于 [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/systemd/network/20-ethernet.network 有线以太网]、[https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/systemd/network/20-wlan.network 无线局域网(WLAN)] 和 [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/systemd/network/20-wwan.network 无线广域网(WWAN)] 网络接口来说应该能开箱即用。<br />
** 静态 IP 地址: 按照 [[Network configuration#Static IP address]] 进行操作。<br />
<br />
* 用 [[w:ping (networking utility)|ping]] 检查网络连接: {{bc|# ping archlinux.org}}<br />
<br />
{{注意|默认情况下,安装映像已预配置好并启用了 [[systemd-networkd]]、[[systemd-resolved]]、[[iwd (简体中文)|iwd]] 和 [[ModemManager]]。但已经安装好了的系统并非如此。}}<br />
<br />
=== 更新系统时间 ===<br />
<br />
使用 {{man|1|timedatectl}} 确保系统时间是准确的:<br />
<br />
# timedatectl set-ntp true<br />
<br />
可以使用 {{ic|timedatectl status}} 检查服务状态。<br />
<br />
=== 建立硬盘分区 ===<br />
<br />
磁盘若被系统识别到,就会被分配为一个[[Wikipedia:zh:设备文件系统#命名约定|块设备]],如 {{ic|/dev/sda}}, {{ic|/dev/nvme0n1}} 或 {{ic|/dev/mmcblk0}}。可以使用 [[lsblk]] 或者 ''fdisk'' 查看:<br />
<br />
# fdisk -l<br />
<br />
结果中以 {{ic|rom}},{{ic|loop}} 或者 {{ic|airoot}} 结束的可以被忽略。<br />
<br />
对于一个选定的设备,以下的''分区''是必须要有的:<br />
<br />
* 一个根分区(挂载在 [[Wikipedia:Root directory|根目录]]){{ic|/}};<br />
* 要在 [[UEFI]] 模式中启动,还需要一个 [[EFI system partition|EFI 系统分区]]。<br />
<br />
如果需要创建多级存储例如 [[LVM]]、[[disk encryption]] 或 [[RAID]],请在此时完成。<br />
<br />
请使用 [[Fdisk (简体中文)|fdisk]] 或 [[Parted (简体中文)|parted]] 修改分区表。例如:<br />
<br />
# fdisk ''/dev/the_disk_to_be_partitioned(要被分区的磁盘)''<br />
<br />
==== 分区示例 ====<br />
<br />
{| class="wikitable"<br />
|+ BIOS 与 [[Partitioning (简体中文)#Master_Boot_Record|MBR]]<br />
|-<br />
! 挂载点<br />
! 分区<br />
! [[w:Partition type|分区类型]]<br />
! 建议大小<br />
|-<br />
| {{ic|[SWAP]}}<br />
| {{ic|/dev/''swap_partition(交换空间分区)''}}<br />
| Linux swap (交换空间)<br />
| 大于 512 MiB<br />
|-<br />
| {{ic|/mnt}}<br />
| {{ic|/dev/''root_partition(根分区)''}}<br />
| Linux<br />
| 剩余空间<br />
|}<br />
<br />
{| class="wikitable"<br />
|+ UEFI 与 [[Partitioning (简体中文)#GUID 分区表|GPT]]<br />
|-<br />
! 挂载点<br />
! 分区<br />
! [[w:GUID_Partition_Table#Partition_type_GUIDs|分区类型]]<br />
! 建议大小<br />
|-<br />
| {{ic|/mnt/boot}} 或 {{ic|/mnt/efi}}<br />
| {{ic|/dev/''efi_system_partition(efi 系统分区)''}}<br />
| [[EFI_system_partition (简体中文)|EFI 系统分区]]<br />
| 至少 260 MiB<br />
|-<br />
| {{ic|[SWAP]}}<br />
| {{ic|/dev/''swap_partition(交换空间分区)''}}<br />
| Linux swap (交换空间)<br />
| 大于 512 MiB<br />
|-<br />
| {{ic|/mnt}}<br />
| {{ic|/dev/''root_partition(根分区)''}}<br />
| Linux x86-64 根目录 (/)<br />
| 剩余空间<br />
|}<br />
<br />
另请参阅 [[Partitioning (简体中文)#布局示例|布局示例]]。<br />
<br />
{{注意|<br />
* 如果文件系统支持,[[Swap (简体中文)|交换空间]]也可以设在[[Swap (简体中文)#交换文件|交换文件]]上。<br />
* 如果想要引导的磁盘上 [[EFI system partition#Check for an existing partition|已经有一个 EFI 系统分区]] 了,请不要再创建一个,而是使用现有的分区。<br />
}}<br />
<br />
=== 格式化分区 ===<br />
<br />
当分区建立好了,每个新建立的分区都需要使用适当的 [[file systems (简体中文)|文件系统]] 进行格式化。举个例子,要在根分区 {{ic|/dev/''root_partition''}} 上创建一个 Ext4 文件系统,运行:<br />
<br />
# mkfs.ext4 /dev/''root_partition(根分区)''<br />
<br />
如果创建了 [[Swap (简体中文)|交换分区]] (例如 {{ic|/dev/''sda3''}}),请使用 {{man|8|mkswap}} 将其初始化:<br />
<br />
# mkswap /dev/''swap_partition(交换空间分区)''<br />
<br />
详情请参阅 [[File systems (简体中文)#创建文件系统|文件系统]]。<br />
<br />
{{注意|对于堆叠式块设备(stacked block devices)请使用恰当的块设备路径替换上文中的 {{ic|/dev/''*_partition''}} 处。}}<br />
<br />
=== 挂载分区 ===<br />
<br />
将根磁盘卷 [[Mount|挂载]] 到 {{ic|/mnt}},例如:<br />
<br />
# mount /dev/''root_partition'' /mnt<br />
<br />
然后使用 {{man|1|mkdir}} 创建其他剩余的挂载点(比如 {{ic|/mnt/efi}})并挂载其相应的磁盘卷。<br />
<br />
如果你创建了一个 [[swap]] 交换空间卷,请使用 {{man|8|swapon}} 启用它:<br />
<br />
# swapon /dev/''swap_partition(交换空间分区)''<br />
<br />
稍后 {{man|8|genfstab}} 将自动检测挂载的文件系统和交换空间。<br />
<br />
=== 注意事项 ===<br />
<br />
挂载分区的时候,如果boot单独分区,要首先挂载root 即 / 分区,然后挂载boot 分区,最后再挂载其它分区,不然后续安装会出现问题。<br />
<br />
== 安装 ==<br />
<br />
=== 选择镜像 ===<br />
<br />
文件 {{ic|/etc/pacman.d/mirrorlist}} 定义了软件包会从哪个[[Mirrors|镜像源]]下载。在 LiveCD 启动的系统上,在连接到因特网后,[[reflector]] 会通过选择 20 个最新同步的 HTTPS 镜像并按下载速率对其进行排序来更新镜像列表。[https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/xdg/reflector/reflector.conf]<br />
<br />
在列表中越前的镜像在下载软件包时有越高的优先权。您或许想检查一下文件,看看是否满意。如果不满意,可以相应的修改 {{ic|/etc/pacman.d/mirrorlist}} 文件,并将地理位置最近的镜像源挪到文件的头部,同时也应该考虑一些其他标准。<br />
<br />
这个文件接下来还会被 ''pacstrap'' 拷贝到新系统里,所以请确保设置正确。<br />
<br />
=== 安装必须的软件包 ===<br />
<br />
使用 [https://git.archlinux.org/arch-install-scripts.git/tree/pacstrap.in pacstrap] 脚本,安装 {{Pkg|base}} 软件包和 Linux [[kernel|内核]]以及常规硬件的固件:<br />
<br />
# pacstrap /mnt base linux linux-firmware<br />
<br />
{{提示|<br />
* 可以将 {{Pkg|linux}} 替换为 [[kernel]] 页面中介绍的内核软件包。<br />
* 在虚拟机或容器中安装时,可以不安装固件软件包。<br />
}}<br />
<br />
{{Pkg|base}} 软件包并没有包含 Live 环境中的全部程序。因此要获得一个功能齐全的基本系统,可能需要安装其他软件包。特别要考虑安装:<br />
<br />
* 管理所用[[file systems|文件系统]]的用户工具 xfs btrfs 需要安装相应的管理工具;<br />
* 访问 [[RAID]] 或 [[LVM]] 分区的工具;<br />
* 未包含在 {{Pkg|linux-firmware}} 中的额外固件;<br />
* [[networking|联网]] 所需要的程序 比如 dhcpcd iwd;<br />
* [[text editor|文本编辑器]] 比如 nano vim;<br />
* 访问 [[man]] 和 [[info]] 页面的工具:{{Pkg|man-db}}, {{Pkg|man-pages}} 和 {{Pkg|texinfo}}。<br />
<br />
要 [[install|安装]] 其他软件包或软件包组 (比如 {{Grp|base-devel}}),请将它们的名字追加到上文的 ''pacstrap'' 命令后 (用空格分隔),或者也可以在 [[#Chroot|Chroot 进新系统]]后使用 [[pacman]] 手动安装软件包或软件包组。[https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/packages.x86_64 packages.x86_64] 中可以看到不同软件包或软件包组间的差异。<br />
<br />
== 配置系统 ==<br />
<br />
=== Fstab ===<br />
<br />
用以下命令生成 [[fstab]] 文件 (用 {{ic|-U}} 或 {{ic|-L}} 选项设置UUID 或卷标):<br />
<br />
# genfstab -U /mnt >> /mnt/etc/fstab<br />
<br />
'''强烈建议'''在执行完以上命令后,后检查一下生成的 {{ic|/mnt/etc/fstab}} 文件是否正确。<br />
<br />
=== Chroot ===<br />
<br />
[[Change root (简体中文)|Change root]] 到新安装的系统:<br />
<br />
# arch-chroot /mnt<br />
<br />
=== 时区 ===<br />
<br />
设置[[time zone|时区]]:<br />
# ln -sf /usr/share/zoneinfo/''Region''/''City'' /etc/localtime<br />
<br />
例如:<br />
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime<br />
<br />
运行 {{man|8|hwclock}} 以生成 {{ic|/etc/adjtime}}:<br />
<br />
# hwclock --systohc<br />
<br />
这个命令假定硬件时间已经被设置为 [[Wikipedia:UTC|UTC 时间]]。详细信息请查看 [[System time#Time standard]]。<br />
<br />
=== 本地化 ===<br />
<br />
本地化的程序与库若要本地化文本,都依赖 [[Locale]],后者明确规定地域、货币、时区日期的格式、字符排列方式和其他本地化标准。<br />
<br />
需在这两个文件设置:{{ic|locale.gen}} 与 {{ic|locale.conf}}。<br />
<br />
编辑{{ic|/etc/locale.gen}} 然后移除需要的 [[Locale (简体中文)|地区]] 前的注释符号 {{ic|#}}。<br />
<br />
接着执行 {{ic|locale-gen}} 以生成 locale 信息:<br />
<br />
# locale-gen<br />
<br />
然后创建 {{man|5|locale.conf}} 文件,并 [[Locale#Setting the system locale|编辑设定 LANG 变量]],比如:<br />
<br />
{{hc|1=/etc/locale.conf|2=<br />
LANG=''en_US.UTF-8''<br />
}}<br />
<br />
另外对于中文用户:<br />
{{提示|<br />
<br />
* 用户可以设置自己的 locale,详情请参阅 [[Locale#Overriding system locale per user session]] 或 [[Locale (简体中文)##设置当前区域]];<br />
* 将系统 locale 设置为 {{ic|en_US.UTF-8}} ,系统的 log 就会用英文显示,这样更容易判断和处理问题;<br />
** 也可以设置为 {{ic|en_GB.UTF-8}} 或 {{ic|en_SG.UTF-8}},附带以下优点:<br />
*** 进入桌面环境后以 24 小时制显示时间;<br />
*** LibreOffice 等办公软件的纸张尺寸会默认为 {{ic|A4}} 而非 {{ic|Letter(US)}};<br />
*** 可尽量避免不必要且可能造成处理麻烦的英制单位。<br />
<br />
}}<br />
<br />
{{警告|不推荐在此设置任何中文 locale,会导致 tty 乱码。}}<br />
<br />
如果需要修改 [[#键盘布局]],并想让这个设置持续生效,编辑 {{man|5|vconsole.conf}},例如:<br />
<br />
{{hc|1=/etc/vconsole.conf|2=<br />
KEYMAP=''de-latin1''<br />
}}<br />
<br />
=== 网络配置 ===<br />
<br />
[[Create|创建]] [[Network configuration (简体中文)#设置计算机名|hostname]] 文件:<br />
<br />
{{hc|/etc/hostname|<br />
''myhostname(主机名)''<br />
}}<br />
<br />
添加对应的信息到 {{man|5|hosts}}:<br />
<br />
{{hc|/etc/hosts|<br />
127.0.0.1 localhost<br />
::1 localhost<br />
127.0.1.1 ''myhostname''.''localdomain'' ''myhostname'' # ''主机名.本地域名'' ''主机名''<br />
}}<br />
<br />
如果系统有一个永久的 IP 地址,请使用这个永久的 IP 地址而不是 {{ic|127.0.1.1}}。<br />
<br />
请注意,目前的 {{Pkg|base}} 不含有任何网络管理工具。针对新安装的系统环境,请完成[[网络配置]],配置过程中可能包括要安装合适的[[网络管理]]软件。<br />
<br />
=== Initramfs ===<br />
<br />
通常不需要自己创建新的 ''initramfs'',因为在执行 ''pacstrap'' 时已经安装 {{Pkg|linux}},这时 [[mkinitcpio]] 会被自动运行。<br />
<br />
对于 [[Install Arch Linux on LVM#Adding mkinitcpio hooks|LVM]]、 [[dm-crypt|system encryption]] 或 [[RAID#Configure_mkinitcpio|RAID]],修改 [[mkinitcpio (简体中文)|mkinitcpio.conf]] 并用以下命令重新创建一个 Initramfs:<br />
<br />
# mkinitcpio -P<br />
<br />
=== Root 密码 ===<br />
<br />
设置 Root [[password|密码]]:<br />
# passwd<br />
<br />
=== 安装引导程序 ===<br />
<br />
需要安装 Linux 引导加载程序,才能在安装后启动系统,可以使用的的引导程序已在 [[Boot loaders (简体中文)|启动加载器]] 中列出,请选择一个安装并配置它,[[GRUB (简体中文)]] 是最常见的选择。<br />
<br />
如果有 Intel 或 AMD 的 CPU,请另外启用 [[Microcode (简体中文)|微码]] 更新。<br />
<br />
{{警告|这是安装的最后但也至关重要的一步,请按上述指引正确安装好引导加载程序后再重新启动。否则将无法正常进入系统。}}<br />
<br />
== 重启 ==<br />
<br />
输入 {{ic|exit}} 或按 {{ic|Ctrl+d}} 退出 chroot 环境。<br />
<br />
可选用 {{ic|umount -R /mnt}} 手动卸载被挂载的分区:这有助于发现任何「繁忙」的分区,并通过 {{man|1|fuser}} 查找原因。<br />
<br />
最后,通过执行 {{ic|reboot}} 重启系统,''systemd'' 将自动卸载仍然挂载的任何分区。不要忘记移除安装介质,然后使用 root 帐户登录到新系统。<br />
<br />
== 安装后的工作 ==<br />
<br />
系统管理引导,图形用户界面的安装、声音管理、触摸板支持等后期工作参见 [[General recommendations (简体中文)]]。<br />
<br />
感兴趣的各类程序,请参见 [[List of applications (简体中文)]]。</div>Purofle