虚拟化相关
Docker
1.虚拟机与容器
容器: 共享宿主机硬件资源和操作系统.
LXC: https://blog.csdn.net/zhongbeida_xue/article/details/81634525
Anbox
安装过程:
https://blog.csdn.net/ZhangRelay/article/details/84465548
源码下载:
https://github.com/anbox/anbox
- 使用Anbox
1.1 安装Anbox
安装必要module
$ sudo add-apt-repository ppa:morphis/anbox-support
$ sudo apt update
$ sudo apt install anbox-modules-dkms
$ sudo modprobe ashmem_linux
$ sudo modprobe binder_linux
检查新节点是否安装上:
$ ls -1 /dev/{ashmem,binder}
/dev/ashmem
/dev/binder
安装Anbox:
$ snap install --devmode --beta anbox
升级现有Anbox:
$ snap refresh --beta --devmode anbox
查看安装信息:
$ snap info anbox
1.2 手动编译Anbox(如果可以直接安装,不需要)
1.3 编译系统镜像:
$ mkdir $HOME/anbox-work
$ cd $HOME/anbox-work
$ repo init -u https://github.com/anbox/platform_manifests.git -b anbox
$ repo sync -j4
等待下载完成:
$ . build/envsetup.sh
$ lunch anbox_x86_64-userdebug
$ make -j8
编译完成后打包img:
$ cd $HOME/anbox-work/anbox
$ scripts/create-package.sh \
$PWD/../out/target/product/x86_64/ramdisk.img \
$PWD/../out/target/product/x86_64/system.img
1.3 使用Anbox和编译的img
使用前停用anbox
$ initctl stop anbox
$ sudo systemctl stop snap.anbox.container-manager
运行anbox
$ datadir=$HOME/anbox-data
$ mkdir -p $datadir/rootfs
$ sudo anbox container-manager \
--android-image=/path/to/android.img \
--data-path=$datadir
- Anbox结构
代码路径: vendor/anbox
App:
appmgr: anbox的launcher app
Bin:
anboxd:
Lib:
Driver:
sensors: 虚拟传感器(Accelerometer, Magnetic field,
Orientation, Temperature, Proximity, Light,
Pressure, Humidity)
2.1.运行环境加载
The Anbox runtime consists mainly of two separate instances:
- container manager
- session manager
The container manager has the job of managing the container setup and maintenance
during its lifetime. It has the responsibility to start the LXC environment we’re
using to run the Android system.
The session manager runs inside the session of a user logged into the Linux system.
It will communicate over several sockets with the Android instance running inside
the container and provide integration with the Linux system. It also acts as a
multiplexer to map Android applications into single windows on the desktop
environment. Currently all application windows are owned by the same process
(the session manager). The application logic itself is still in a separate process
inside the Android container.
The following picture shows an overview over the architecture:
Application Mapping
Android applications are mapped into single windows within the desktop environment.
This is achieved by plugging into the Android hwcomposer HAL module which receives
a set of layers to composite on a screen. Anbox tells SurfaceFlinger through its
hwcomposer implementation to get a layer for each application and combines this with
additional information it receives from the Android WindowManager to map individual
layers to applications. For more details please look into the implementation at
- android/hwcomposer
- src/anbox/graphics/layer_composer.cpp
- src/anbox/wm/manager.cpp
2.2 Anbox对传感器的虚拟化
anbox.mk中:
camera.goldfish \
camera.goldfish.jpeg \
lights.goldfish \
gps.goldfish \
fingerprint.goldfish \
sensors.goldfish \
audio.primary.goldfish \
vibrator.goldfish \
power.goldfish \
以vibrator.goldfish为例:
代码路径: android/vibrator
模拟器原理:
2.3 Anbox启动运行过程
2.3.1 系统启动
cmd.command(std::make_shared<cmds::Version>())
.command(std::make_shared<cmds::SessionManager>())
.command(std::make_shared<cmds::Launch>())
.command(std::make_shared<cmds::ContainerManager>())
.command(std::make_shared<cmds::SystemInfo>())
.command(std::make_shared<cmds::WaitReady>())
.command(std::make_shared<cmds::CheckFeatures>());
Anbox Container Manager: 初始代运行环境
2.3.2 ContainerManager
ContainerManager:
1. Runtime::create();
2. rt->start();
trap->run();
rt->stop();
2.3.3 SessionManager: