Skip to content

Split View: [가상화] 01. 가상화 기술의 기초: Type 1 vs Type 2 하이퍼바이저

|

[가상화] 01. 가상화 기술의 기초: Type 1 vs Type 2 하이퍼바이저

들어가며

가상화(Virtualization)는 물리적 하드웨어 위에 여러 개의 독립된 가상 환경을 만드는 기술입니다. 하나의 서버에서 여러 운영체제를 동시에 실행할 수 있으며, 이를 통해 하드웨어 활용률을 극대화하고 인프라 운영 비용을 절감할 수 있습니다.

가상화가 중요한 이유

  • 하드웨어 통합: 평균 CPU 활용률 1520%인 물리 서버를 6080%까지 끌어올림
  • 격리(Isolation): 각 VM은 독립된 커널, 파일 시스템, 네트워크 스택을 보유
  • 유연한 프로비저닝: 수 분 내에 새 서버 환경 배포 가능
  • 스냅샷 및 마이그레이션: 장애 복구, 무중단 이전이 용이
  • 클라우드 컴퓨팅의 기반: AWS, Azure, GCP 모두 가상화 위에서 작동

하이퍼바이저란?

하이퍼바이저(Hypervisor)는 가상 머신(VM)을 생성하고 관리하는 소프트웨어 계층입니다. VMM(Virtual Machine Monitor)이라고도 부릅니다. 물리적 자원(CPU, 메모리, 스토리지, 네트워크)을 추상화하여 각 VM에 분배합니다.

Type 1 하이퍼바이저 (Bare-Metal)

Type 1 하이퍼바이저는 하드웨어 위에 직접 설치됩니다. 호스트 OS 없이 동작하므로 오버헤드가 적고 성능이 우수합니다.

+-------------------------------------------+
|   VM 1      |   VM 2      |   VM 3        |
|  (Ubuntu)   |  (Windows)  |  (CentOS)     |
+-------------------------------------------+
|          Type 1 Hypervisor                 |
|     (ESXi / Hyper-V / Xen)                |
+-------------------------------------------+
|          Physical Hardware                 |
|   (CPU, RAM, Storage, NIC)                |
+-------------------------------------------+

대표적인 Type 1 하이퍼바이저:

하이퍼바이저개발사특징
VMware ESXiVMware(Broadcom)엔터프라이즈 표준, vSphere 에코시스템
Microsoft Hyper-VMicrosoftWindows Server에 내장, AD 통합
XenLinux Foundation반가상화 선구자, AWS 초기 기반
KVM오픈소스(Red Hat)Linux 커널 모듈, QEMU와 결합

Type 2 하이퍼바이저 (Hosted)

Type 2 하이퍼바이저는 호스트 운영체제 위에서 일반 애플리케이션처럼 실행됩니다.

+-------------------------------------------+
|   VM 1      |   VM 2      |   VM 3        |
|  (Ubuntu)   |  (Windows)  |  (Fedora)     |
+-------------------------------------------+
|          Type 2 Hypervisor                 |
|  (VirtualBox / VMware Workstation)        |
+-------------------------------------------+
|           Host OS (Windows/macOS/Linux)    |
+-------------------------------------------+
|          Physical Hardware                 |
|   (CPU, RAM, Storage, NIC)                |
+-------------------------------------------+

대표적인 Type 2 하이퍼바이저:

하이퍼바이저개발사특징
Oracle VirtualBoxOracle오픈소스, 크로스플랫폼, 무료
VMware WorkstationVMware(Broadcom)프로페셔널 데스크톱 가상화
VMware FusionVMware(Broadcom)macOS 전용, Apple Silicon 지원
Parallels DesktopParallelsmacOS 최적화, 뛰어난 통합

KVM: 하이브리드 접근

KVM(Kernel-based Virtual Machine)은 독특한 위치를 차지합니다. Linux 커널 모듈로 동작하여 Linux 자체를 Type 1 하이퍼바이저로 변환합니다.

+-------------------------------------------+
|   VM 1      |   VM 2      |   VM 3        |
|  (Ubuntu)   |  (Windows)  |  (Fedora)     |
+-------------------------------------------+
|     QEMU (Device Emulation / Management)  |
+-------------------------------------------+
|  Linux Kernel + KVM Module (Type 1-like)  |
+-------------------------------------------+
|          Physical Hardware                 |
|   (CPU + VT-x/AMD-V, RAM, Storage, NIC)  |
+-------------------------------------------+
  • kvm.ko 모듈이 CPU의 하드웨어 가상화 확장(VT-x/AMD-V)을 직접 활용
  • 게스트 CPU 명령은 하드웨어에서 직접 실행 (near-native 성능)
  • Linux 커널이 프로세스 스케줄링, 메모리 관리, I/O를 담당
  • QEMU가 디바이스 에뮬레이션과 VM 관리를 제공
  • 기술적으로는 Type 1이지만 완전한 Linux OS 내에서 동작하므로 "하이브리드"로 분류

가상화 기법 비교

전가상화 (Full Virtualization)

전가상화에서는 게스트 OS를 수정 없이 그대로 실행합니다. 하이퍼바이저가 게스트의 특권 명령(privileged instructions)을 가로채서 변환합니다.

바이너리 변환(Binary Translation) 방식:

Guest OS (Ring 1에서 실행)
    |
    v  특권 명령 실행 시도
    |
Hypervisor (Ring 0)가 트랩
    |
    v  안전한 명령으로 변환 후 실행
    |
Physical Hardware
  • 게스트 OS 수정 불필요 (Windows, Linux 등 모두 지원)
  • 바이너리 변환으로 인한 성능 오버헤드 존재
  • VMware의 초기 접근 방식

반가상화 (Paravirtualization)

반가상화에서는 게스트 OS가 가상화 환경에서 실행됨을 인지합니다. 특권 명령 대신 하이퍼콜(Hypercall)을 사용하여 하이퍼바이저에 직접 요청합니다.

Guest OS (수정됨 - Hypercall 인터페이스 포함)
    |
    v  hypercall 호출 (trap 대신 직접 통신)
    |
Hypervisor (요청 처리)
    |
    v
Physical Hardware
  • 게스트 OS 커널 수정이 필요 (Linux 가능, 일반 Windows 불가)
  • 오버헤드가 적어 전가상화보다 성능이 우수
  • Xen의 초기 방식, VirtIO 드라이버도 반가상화 개념을 활용
  • VirtIO는 네트워크, 스토리지 등 I/O 디바이스에 대한 반가상화 표준

하드웨어 지원 가상화 (Hardware-Assisted Virtualization)

2005~2006년 Intel과 AMD가 CPU 수준에서 가상화를 지원하기 시작했습니다.

주요 기술:

  • Intel VT-x (2005): VMX root/non-root 모드 도입
  • AMD-V (2006): SVM(Secure Virtual Machine) 확장
  • Ring -1 개념: 하이퍼바이저 전용 특권 레벨 추가
  • VT-d / AMD-Vi: IOMMU 기반 DMA 리매핑, 디바이스 패스스루 지원
  • EPT / NPT: 확장 페이지 테이블로 메모리 가상화 하드웨어 가속
+--------------------------------------------------+
|  Guest OS (Ring 3: User, Ring 0: Kernel)          |
|  --> VMX non-root mode에서 실행                    |
+--------------------------------------------------+
|  Hypervisor (Ring -1 / VMX root mode)              |
|  --> VM Exit 시에만 개입                           |
+--------------------------------------------------+
|  Hardware (VT-x/AMD-V, EPT/NPT, VT-d/AMD-Vi)     |
+--------------------------------------------------+
  • 게스트 OS 수정 불필요 + 네이티브에 가까운 성능
  • VM Exit 빈도에 따라 성능 차이 발생
  • 현대 모든 x86 가상화의 기반 기술

세 가지 가상화 기법 비교표

항목전가상화반가상화HW 지원 가상화
게스트 OS 수정불필요필요불필요
CPU 오버헤드높음 (바이너리 변환)중간 (하이퍼콜)낮음 (HW 트랩)
I/O 성능에뮬레이션으로 느림하이퍼콜로 빠름VirtIO 결합 시 최적
Windows 지원가능커널 수정 어려움가능
대표 기술VMware BTXen PV, VirtIOVT-x, AMD-V
현재 사용레거시I/O 최적화에 활용주류 방식

실습: KVM 기반 가상화 확인

# CPU가 가상화를 지원하는지 확인
# Intel VT-x의 경우 vmx, AMD-V의 경우 svm 플래그를 확인
grep -E '(vmx|svm)' /proc/cpuinfo | head -1

# KVM 모듈 로드 확인
lsmod | grep kvm

# 출력 예시:
# kvm_intel            368640  0
# kvm                 1028096  1 kvm_intel

# libvirt를 통한 VM 생성 예시
virt-install \
  --name test-vm \
  --ram 2048 \
  --vcpus 2 \
  --disk size=20 \
  --os-variant ubuntu22.04 \
  --cdrom /path/to/ubuntu-22.04.iso

CPU 특권 레벨(Ring) 구조

[하드웨어 가상화 이전]            [하드웨어 가상화 이후]

Ring 3: 사용자 앱                Ring 3: 사용자 앱
Ring 2: (미사용)                 Ring 2: (미사용)
Ring 1: (Guest OS - 전가상화)    Ring 1: (미사용)
Ring 0: Hypervisor               Ring 0: Guest OS (non-root)
                                  Ring -1: Hypervisor (VMX root)

하드웨어 가상화가 도입되면서 게스트 OS가 Ring 0에서 정상적으로 동작하면서도 하이퍼바이저가 더 높은 특권 수준(Ring -1)에서 제어할 수 있게 되었습니다.

VM Exit와 성능

하드웨어 가상화에서 게스트가 특정 작업을 수행하면 CPU가 VMX non-root에서 root 모드로 전환됩니다. 이를 VM Exit라 합니다.

VM Exit가 발생하는 주요 상황:

  • I/O 포트 접근
  • 특정 MSR(Model-Specific Register) 접근
  • 인터럽트 처리
  • 페이지 폴트 (EPT 미사용 시)
  • CPUID 명령 실행

VM Exit는 수백~수천 CPU 사이클이 소요되므로 빈도를 줄이는 것이 성능의 핵심입니다. VirtIO와 같은 반가상화 드라이버가 I/O 경로에서 VM Exit를 줄여줍니다.

[VM Exit 처리 흐름]

Guest 실행 (non-root)
    |
    v  민감한 명령 실행
    |
VM Exit (non-root -> root 전환, ~수백 사이클)
    |
    v  Hypervisor가 명령 처리
    |
VM Entry (root -> non-root 전환)
    |
    v  Guest 실행 재개

정리

분류 기준Type 1Type 2
설치 위치하드웨어 직접호스트 OS 위
성능높음중간
주 용도서버 가상화, 클라우드개발, 테스트
관리 복잡도높음낮음
대표 제품ESXi, Hyper-V, KVMVirtualBox, VMware Workstation

가상화는 현대 클라우드 인프라의 근간입니다. Type 1 하이퍼바이저는 프로덕션 환경에서, Type 2는 데스크톱 환경에서 각각의 역할을 합니다. 하드웨어 가상화 지원(VT-x/AMD-V)의 등장으로 성능 오버헤드가 극적으로 줄어들어 현재의 클라우드 컴퓨팅 시대가 가능해졌습니다.


퀴즈: 가상화 기초 이해도 점검

Q1. Type 1 하이퍼바이저와 Type 2 하이퍼바이저의 가장 큰 차이점은 무엇인가요?

Type 1은 하드웨어 위에 직접 설치되어 호스트 OS가 없으며, Type 2는 기존 호스트 OS 위에서 애플리케이션으로 실행됩니다. Type 1이 오버헤드가 적어 프로덕션 환경에 적합합니다.

Q2. KVM이 "하이브리드"로 분류되는 이유는 무엇인가요?

KVM은 Linux 커널 모듈로서 Linux 자체를 Type 1 하이퍼바이저로 변환하지만, 동시에 완전한 Linux OS 환경 내에서 동작합니다. 따라서 Type 1의 성능과 Type 2의 편의성을 모두 갖습니다.

Q3. 반가상화에서 사용하는 "하이퍼콜"이란 무엇인가요?

하이퍼콜은 게스트 OS가 하이퍼바이저에 직접 서비스를 요청하는 인터페이스입니다. 시스템 콜이 커널에 요청하는 것과 유사하게, 하이퍼콜은 하이퍼바이저에 요청합니다. 트랩 방식보다 오버헤드가 적습니다.

Q4. Intel VT-x의 "Ring -1"이 해결하는 문제는 무엇인가요?

기존에는 게스트 OS(Ring 0)와 하이퍼바이저(Ring 0)가 같은 특권 레벨에서 충돌했습니다. Ring -1 (VMX root mode)을 도입하여 하이퍼바이저가 더 높은 특권에서 동작하고, 게스트 OS는 Ring 0에서 정상 실행됩니다.

Q5. VirtIO가 성능을 향상시키는 원리는 무엇인가요?

VirtIO는 I/O 디바이스(네트워크, 스토리지)에 대한 반가상화 표준으로, 게스트 OS가 가상화 환경을 인식하고 최적화된 경로로 하이퍼바이저와 통신합니다. 이를 통해 전체 하드웨어 에뮬레이션보다 VM Exit가 줄어들고 성능이 향상됩니다.

[Virtualization] 01. Virtualization Fundamentals: Type 1 vs Type 2 Hypervisors

Introduction

Virtualization is the technology of creating multiple isolated virtual environments on top of physical hardware. It enables running several operating systems simultaneously on a single server, maximizing hardware utilization and reducing infrastructure costs.

Why Virtualization Matters

  • Hardware Consolidation: Boosts average CPU utilization from 15-20% to 60-80%
  • Isolation: Each VM has its own kernel, filesystem, and network stack
  • Flexible Provisioning: Deploy new server environments within minutes
  • Snapshots and Migration: Easy disaster recovery and zero-downtime migration
  • Cloud Foundation: AWS, Azure, and GCP all run on virtualization

What Is a Hypervisor?

A hypervisor is the software layer that creates and manages virtual machines (VMs). Also called a VMM (Virtual Machine Monitor), it abstracts physical resources (CPU, memory, storage, network) and distributes them to each VM.

Type 1 Hypervisors (Bare-Metal)

Type 1 hypervisors are installed directly on hardware. They operate without a host OS, resulting in lower overhead and better performance.

+-------------------------------------------+
|   VM 1      |   VM 2      |   VM 3        |
|  (Ubuntu)   |  (Windows)  |  (CentOS)     |
+-------------------------------------------+
|          Type 1 Hypervisor                 |
|     (ESXi / Hyper-V / Xen)                |
+-------------------------------------------+
|          Physical Hardware                 |
|   (CPU, RAM, Storage, NIC)                |
+-------------------------------------------+

Notable Type 1 Hypervisors:

HypervisorVendorKey Features
VMware ESXiVMware (Broadcom)Enterprise standard, vSphere ecosystem
Microsoft Hyper-VMicrosoftBuilt into Windows Server, AD integration
XenLinux FoundationParavirtualization pioneer, early AWS foundation
KVMOpen Source (Red Hat)Linux kernel module, paired with QEMU

Type 2 Hypervisors (Hosted)

Type 2 hypervisors run as regular applications on top of a host operating system.

+-------------------------------------------+
|   VM 1      |   VM 2      |   VM 3        |
|  (Ubuntu)   |  (Windows)  |  (Fedora)     |
+-------------------------------------------+
|          Type 2 Hypervisor                 |
|  (VirtualBox / VMware Workstation)        |
+-------------------------------------------+
|           Host OS (Windows/macOS/Linux)    |
+-------------------------------------------+
|          Physical Hardware                 |
|   (CPU, RAM, Storage, NIC)                |
+-------------------------------------------+

Notable Type 2 Hypervisors:

HypervisorVendorKey Features
Oracle VirtualBoxOracleOpen-source, cross-platform, free
VMware WorkstationVMware (Broadcom)Professional desktop virtualization
VMware FusionVMware (Broadcom)macOS only, Apple Silicon support
Parallels DesktopParallelsmacOS optimized, excellent integration

KVM: A Hybrid Approach

KVM (Kernel-based Virtual Machine) occupies a unique position. It operates as a Linux kernel module that transforms Linux itself into a Type 1 hypervisor.

+-------------------------------------------+
|   VM 1      |   VM 2      |   VM 3        |
|  (Ubuntu)   |  (Windows)  |  (Fedora)     |
+-------------------------------------------+
|     QEMU (Device Emulation / Management)  |
+-------------------------------------------+
|  Linux Kernel + KVM Module (Type 1-like)  |
+-------------------------------------------+
|          Physical Hardware                 |
|   (CPU + VT-x/AMD-V, RAM, Storage, NIC)  |
+-------------------------------------------+
  • The kvm.ko module directly leverages CPU hardware virtualization extensions (VT-x/AMD-V)
  • Guest CPU instructions execute directly on hardware (near-native performance)
  • The Linux kernel handles process scheduling, memory management, and I/O
  • QEMU provides device emulation and VM management
  • Technically Type 1, but runs within a full Linux OS, hence classified as "hybrid"

Virtualization Techniques Compared

Full Virtualization

In full virtualization, the guest OS runs completely unmodified. The hypervisor intercepts and translates privileged instructions from the guest.

Binary Translation approach:

Guest OS (runs in Ring 1)
    |
    v  Attempts privileged instruction
    |
Hypervisor (Ring 0) traps it
    |
    v  Translates to safe instructions and executes
    |
Physical Hardware
  • No guest OS modification needed (supports Windows, Linux, etc.)
  • Performance overhead from binary translation
  • VMware's original approach

Paravirtualization

In paravirtualization, the guest OS is aware it runs in a virtualized environment. Instead of privileged instructions, it uses hypercalls to directly request services from the hypervisor.

Guest OS (modified - includes hypercall interface)
    |
    v  Issues hypercall (direct communication instead of traps)
    |
Hypervisor (processes request)
    |
    v
Physical Hardware
  • Requires guest OS kernel modification (Linux possible, standard Windows not)
  • Lower overhead than full virtualization, better performance
  • Xen's original approach; VirtIO drivers also leverage the paravirtualization concept
  • VirtIO is the paravirtualization standard for I/O devices (network, storage)

Hardware-Assisted Virtualization

In 2005-2006, Intel and AMD introduced CPU-level virtualization support.

Key Technologies:

  • Intel VT-x (2005): Introduced VMX root/non-root modes
  • AMD-V (2006): SVM (Secure Virtual Machine) extensions
  • Ring -1 Concept: Added a dedicated privilege level for the hypervisor
  • VT-d / AMD-Vi: IOMMU-based DMA remapping, device passthrough support
  • EPT / NPT: Extended Page Tables for hardware-accelerated memory virtualization
+--------------------------------------------------+
|  Guest OS (Ring 3: User, Ring 0: Kernel)          |
|  --> Runs in VMX non-root mode                     |
+--------------------------------------------------+
|  Hypervisor (Ring -1 / VMX root mode)              |
|  --> Only intervenes on VM Exit                    |
+--------------------------------------------------+
|  Hardware (VT-x/AMD-V, EPT/NPT, VT-d/AMD-Vi)     |
+--------------------------------------------------+
  • No guest OS modification needed + near-native performance
  • Performance varies based on VM Exit frequency
  • Foundation of all modern x86 virtualization

Comparison of Three Virtualization Techniques

AspectFull VirtualizationParavirtualizationHW-Assisted
Guest OS ModificationNot requiredRequiredNot required
CPU OverheadHigh (binary translation)Medium (hypercalls)Low (HW traps)
I/O PerformanceSlow (emulation)Fast (hypercalls)Optimal with VirtIO
Windows SupportYesKernel modification difficultYes
Key TechnologyVMware BTXen PV, VirtIOVT-x, AMD-V
Current UsageLegacyUsed for I/O optimizationMainstream

Hands-On: Verifying KVM-Based Virtualization

# Check if CPU supports virtualization
# Look for vmx (Intel VT-x) or svm (AMD-V) flags
grep -E '(vmx|svm)' /proc/cpuinfo | head -1

# Verify KVM module is loaded
lsmod | grep kvm

# Example output:
# kvm_intel            368640  0
# kvm                 1028096  1 kvm_intel

# Create a VM using libvirt
virt-install \
  --name test-vm \
  --ram 2048 \
  --vcpus 2 \
  --disk size=20 \
  --os-variant ubuntu22.04 \
  --cdrom /path/to/ubuntu-22.04.iso

CPU Privilege Level (Ring) Architecture

[Before HW Virtualization]           [After HW Virtualization]

Ring 3: User Applications            Ring 3: User Applications
Ring 2: (unused)                     Ring 2: (unused)
Ring 1: (Guest OS - full virt)       Ring 1: (unused)
Ring 0: Hypervisor                   Ring 0: Guest OS (non-root)
                                      Ring -1: Hypervisor (VMX root)

With hardware virtualization, the guest OS operates normally at Ring 0 while the hypervisor controls everything from a higher privilege level (Ring -1).

VM Exits and Performance

In hardware-assisted virtualization, when a guest performs certain operations, the CPU switches from VMX non-root to root mode. This is called a VM Exit.

Common VM Exit Triggers:

  • I/O port access
  • Certain MSR (Model-Specific Register) access
  • Interrupt handling
  • Page faults (without EPT)
  • CPUID instruction execution

VM Exits cost hundreds to thousands of CPU cycles, so reducing their frequency is key to performance. Paravirtual drivers like VirtIO reduce VM Exits in the I/O path.

[VM Exit Processing Flow]

Guest Execution (non-root)
    |
    v  Executes sensitive instruction
    |
VM Exit (non-root -> root transition, ~hundreds of cycles)
    |
    v  Hypervisor processes the instruction
    |
VM Entry (root -> non-root transition)
    |
    v  Guest execution resumes

Summary

CriterionType 1Type 2
InstallationDirectly on hardwareOn top of host OS
PerformanceHighMedium
Primary UseServer virtualization, cloudDevelopment, testing
Management ComplexityHighLow
Key ProductsESXi, Hyper-V, KVMVirtualBox, VMware Workstation

Virtualization is the foundation of modern cloud infrastructure. Type 1 hypervisors serve production environments while Type 2 serves desktop use cases. The advent of hardware virtualization support (VT-x/AMD-V) dramatically reduced performance overhead, enabling the cloud computing era we live in today.


Quiz: Virtualization Fundamentals Check

Q1. What is the primary difference between Type 1 and Type 2 hypervisors?

Type 1 installs directly on hardware without a host OS, while Type 2 runs as an application on an existing host OS. Type 1 has lower overhead and is better suited for production environments.

Q2. Why is KVM classified as a "hybrid"?

KVM is a Linux kernel module that transforms Linux itself into a Type 1 hypervisor, but it operates within a full Linux OS environment. This gives it both Type 1 performance and Type 2 convenience.

Q3. What are "hypercalls" in paravirtualization?

Hypercalls are an interface through which the guest OS directly requests services from the hypervisor. Similar to how system calls request services from the kernel, hypercalls request services from the hypervisor, with less overhead than the trap mechanism.

Q4. What problem does Intel VT-x's "Ring -1" solve?

Previously, both the guest OS (Ring 0) and the hypervisor (Ring 0) conflicted at the same privilege level. Ring -1 (VMX root mode) was introduced so the hypervisor operates at a higher privilege level while the guest OS runs normally at Ring 0.

Q5. How does VirtIO improve performance?

VirtIO is a paravirtualization standard for I/O devices (network, storage) where the guest OS recognizes the virtualized environment and communicates with the hypervisor through an optimized path. This reduces VM Exits compared to full hardware emulation, improving performance.