2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
VirtualizationService
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
VirtualizationService
는 Android 시스템에서 실행되는 여러 게스트 VM(보호 대상 포함)을 관리합니다. 관리는 주로 crosvm 인스턴스를 관리함으로써 이루어집니다.
VirtualizationService
는 시스템 서비스 또는 앱이 VM을 시작, 모니터링, 중지하는 데 사용할 수 있는 AIDL API를 노출합니다. VirtualizationService
를 사용하려면 virtmgr
를 직접 실행하거나 virtmgr
를 하위 프로세스로 실행하는 javalib 또는 rustlib를 가져옵니다.
VM 수명 주기
VM에 대한 액세스는 IVirtualMachine
객체로 추적됩니다. IVirtualMachine
객체에 대한 참조가 최소 하나 이상 존재하는 한 VM이 (비정상 종료되거나 자체적으로 종료되지 않는 한) 계속해서 실행됩니다. VM이 종료되기 전에 IVirtualMachine
객체에 대한 모든 참조가 삭제되면 VirtualizationService
가 자동으로 VM을 종료합니다. 이 프로세스는 VM을 시작한 클라이언트가 로우 메모리 킬러에 의해 종료되면 VM도 종료되어 리소스 누수가 방지된다는 사실을 암시합니다.
각 VM은 crosvm의 자체 인스턴스에서 관리합니다. crosvm 인스턴스는 VirtualizationService
가 클라이언트를 대신하여 관리합니다. virtmgr
의 VirtualizationService
는 필요에 따라 할당된 글로벌 리소스(virtualizationservice
의 VirtualizationServiceInternal
에서 부여된 CID 포함)로 이러한 crosvm 하위 프로세스를 시작하고 VM에 필요한 이미지의 파일 설명자를 전달합니다. 그러면 VirtualizationService
는 하위 프로세스가 종료될 경우 남아 있는 클라이언트에 알릴 수 있도록 하위 프로세스의 종료 여부를 모니터링합니다.
VM 패키징
crosvm은 커널 및 initrd를 제공하는 방법과 부트로더를 제공하는 방법, 이렇게 두 가지 방식으로 VM을 부팅합니다. 두 경우 모두 임의 개수의 디스크 이미지를 제공할 수 있습니다. 이는 원시 이미지일 수도 있고, 여러 파티션의 복합 이미지일 수도 있습니다. 클라이언트는 이처럼 다양한 이미지를 파일 설명자로 제공합니다.
VirtualizationService
는 복합 디스크 이미지를 주문형으로 빌드합니다. 이는 반드시 필요한 프로세스입니다. 복합 디스크 파일은 디스크를 구성하는 여러 파티션 이미지 파일을 내부적으로 참조하는데 이는 클라이언트에 의해 전달되므로 crosvm에서 직접 액세스하지 못할 수 있기 때문입니다. 이 문제를 해결하기 위해 VirtualizationService
는 crosvm에서 상속한 파일 설명자 번호가 VirtualizationService
가 복합 이미지를 만들 때 사용한 파일 설명자 번호와 동일한지 확인합니다. 복합 디스크 이미지는 /proc/self/fd/N
형식의 파일 이름을 사용하여 각 파티션 파일을 나타냅니다.
Microdroid pVM의 경우 AVF는 표준 Android 자체 검사 부팅 흐름에 따라 복합 디스크 이미지의 파티션에서 커널을 로드하는 부트로더를 포함합니다.
VM 소켓(vsock)
pVM 간 통신을 위한 기본 인터페이스는 표준 virtio 소켓 인터페이스인 vsock입니다. 각 VM은 32비트 컨텍스트 식별자(CID)로 식별됩니다. VirtualizationServiceInternal
가 VirtualizationService
가 VM을 만들 때 VM에 할당하는 CID는 IP 주소와 비슷하며 각 VM이 선택한 포트 번호에서 서비스를 노출할 수 있습니다.
CID는 VM이 실행되는 동안에는 고유하지만 CID 값은 VM이 종료되고 VM의 모든 IVirtualMachine
바인더 핸들이 삭제되면 재사용될 수 있습니다.
디버그 인터페이스
디버그 용도로 vm
명령어가 제공됩니다. 이 명령어를 사용하면 개발자가 셸에서 VM을 시작하고 로그를 보고 VM을 종료할 수 있습니다. AVF에서 제공하는 vm
명령어 또는 기타 인터페이스를 사용하면 디버그 가능 (FULL) 모드 또는 디버그 불가 (NONE) 모드로 VM을 시작할 수 있습니다. 디버그 가능한 VM을 사용하면 OS 수준 로그를 확인하고, ADB 셸에 액세스하고, 비정상 종료 덤프 또는 앱 페이로드를 캡처할 수 있습니다.
프로덕션에서는 디버그 불가능한 VM을 사용하는 것이 좋습니다. AVF에서 제공하는 명령줄 도구 및 기타 디버그 인터페이스에 관해 자세히 알아보려면 debug/README.md를 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# VirtualizationService\n\n`VirtualizationService` manages multiple guest VMs, protected or otherwise,\nrunning on an Android system, primarily by managing instances of crosvm.\n`VirtualizationService` exposes an AIDL API, which system services or apps can\nuse to start, monitor, and stop VMs. To use `VirtualizationService`, execute\n`virtmgr` directly or import [javalib](https://cs.android.com/android/platform/superproject/+/main:packages/modules/Virtualization/javalib/ \"javalib\") or [rustlib](https://cs.android.com/android/platform/superproject/+/main:packages/modules/Virtualization/vmclient/ \"rustlib\") which executes `virtmgr` as\na child process.\n\nVM lifecycle\n------------\n\nAccess to a VM is tracked by the `IVirtualMachine` object. As long as there's\nat least one reference to `IVirtualMachine` object then the VM continues to\nrun (unless it crashes or shuts down of its own accord). If all references to\nthe `IVirtualMachine` object are dropped before the VM shuts down, then\n`VirtualizationService` automatically shuts down the VM. This process implies\nthat if the client that started the VM is shut down by the low memory killer,\nthen the VM is also shut down, thus preventing resource leaks.\n\nEach VM is managed by its own instance of crosvm, which `VirtualizationService`\nin turn manages on behalf of the client. `VirtualizationService` in `virtmgr`\nstarts these crosvm child processes as required with allocated global resources\nincluding the CID granted by `VirtualizationServiceInternal` in\n`virtualizationservice`, and passes them the file descriptors for the images the\nVM needs. `VirtualizationService` then monitors the child process for when they\ndie, so it can notify any remaining clients accordingly.\n\nVM packaging\n------------\n\ncrosvm supports two different ways of booting a VM: either a kernel and initrd\nare provided or a bootloader is provided. In either case, an\narbitrary number of disk images can also be provided, which might be either\na raw image or a composite of several partitions. The various images are\nprovided by the client as file descriptors.\n\n`VirtualizationService` builds composite disk images on demand. This process is\nnecessary because the composite disk file refers internally to the various\npartition image files composing the disk, which are passed by the client and\nmight not be directly accessible by crosvm. To get around this issue,\n`VirtualizationService` ensures that the file descriptor numbers inherited by\ncrosvm are the same as the file descriptor numbers which `VirtualizationService`\nused in creating the composite images. The composite disk image uses filenames\nin the form to `/proc/self/fd/N` to represent each partition file.\n\nFor Microdroid pVMs, AVF includes a bootloader, which loads the kernel from\na partition of a composite disk image, following the standard Android\nVerified Boot flow.\n\nVM Sockets (vsock)\n------------------\n\nThe primary interface for communication between pVMs is vsock, a standard\nvirtio socket interface. Each VM is identified by a 32-bit context identifier\n(CID), which is analogous to an IP address, which\n`VirtualizationServiceInternal` assigns to the VM when `VirtualizationService`\ncreates the VM, and can expose services on whatever port numbers the VM chooses.\nThe CID is unique while the VM is running, but the CID value can be recycled\nwhen the VM is terminated and all the `IVirtualMachine` binder handles to the VM\nhave been dropped.\n\nDebug interface\n---------------\n\nThe `vm` command is provided for debug purposes. This command lets a developer\nstart a VM from the shell, view its logs, and terminate the VM. With the `vm`\ncommand or other interfaces provided by AVF, a VM can start in either\ndebuggable (FULL) or non-debuggable (NONE) mode. With a debuggable VM, you can\nsee OS-level logs, access the ADB shell, and capture crash-dump or app payload.\nIt's recommended to use a non-debuggable VM in production. For more on\nthe command line tool and other debug interfaces that AVF provides, see\n[debug/README.md](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Virtualization/docs/debug/README.md \"Debugging protected VMs\")."]]