
하이퍼바이저: Type 1 vs Type 2
가상 머신들의 조율자. 사장님이 직접 운영하느냐(Type 1), 매니저를 두느냐(Type 2)의 차이.

가상 머신들의 조율자. 사장님이 직접 운영하느냐(Type 1), 매니저를 두느냐(Type 2)의 차이.
내 서버는 왜 걸핏하면 뻗을까? OS가 한정된 메모리를 쪼개 쓰는 처절한 사투. 단편화(Fragmentation)와의 전쟁.

미로를 탈출하는 두 가지 방법. 넓게 퍼져나갈 것인가(BFS), 한 우물만 팔 것인가(DFS). 최단 경로는 누가 찾을까?

이름부터 빠릅니다. 피벗(Pivot)을 기준으로 나누고 또 나누는 분할 정복 알고리즘. 왜 최악엔 느린데도 가장 많이 쓰일까요?

매번 3-Way Handshake 하느라 지쳤나요? 한 번 맺은 인연(TCP 연결)을 소중히 유지하는 법. HTTP 최적화의 기본.

가상화가 필요하다는 건 알겠는데, "하드웨어 하나를 어떻게 여러 OS가 나눠 쓰지?"라는 의문이 생긴다. 내 로컬 맥북에서 VirtualBox로 우분투를 돌리면 맥OS와 우분투가 동시에 실행되는데, 둘 다 CPU를 써야 하고 메모리도 써야 한다. 누가 이걸 조율하는 걸까?
처음 VirtualBox를 설치했을 때 VM에 CPU 코어를 몇 개 할당할지, 메모리를 얼마나 줄지 설정하는 화면이 나왔다. "아, 이 소프트웨어가 하드웨어 자원을 나눠주는구나." 그런데 회사 서버실에 가보니 서버 한 대에 OS가 아예 없고, 부팅하면 바로 VM 관리 화면이 뜬다. 이건 또 다른 방식인 것 같았다.
하이퍼바이저는 가상 머신(VM)을 생성하고 관리하는 소프트웨어 계층이다. 물리 하드웨어 자원(CPU, 메모리, 디스크, 네트워크)을 여러 VM에게 나눠주고, 각 VM이 독립적인 OS처럼 동작하게 만든다. 중요한 건 하이퍼바이저가 어디에 설치되느냐인데, 이에 따라 Type 1과 Type 2로 나뉜다.
Type 1 하이퍼바이저는 하드웨어 위에 직접 설치된다. 일반 OS가 없다. 부팅하면 하이퍼바이저가 뜬다. 마치 하이퍼바이저 자체가 OS처럼 동작한다.
┌─────────────────────────────────────┐
│ VM 1 (Ubuntu) │ VM 2 (Windows) │
│ Guest OS │ Guest OS │
├─────────────────────────────────────┤
│ Type 1 Hypervisor (ESXi) │ ← 직접 하드웨어 제어
├─────────────────────────────────────┤
│ Physical Hardware (CPU, RAM) │
└─────────────────────────────────────┘
대표적인 예가 VMware ESXi, Microsoft Hyper-V(서버용), Xen, KVM(Kernel-based Virtual Machine) 등이다. 클라우드 제공자들(AWS, GCP, Azure)은 대부분 Type 1을 사용한다. AWS EC2는 예전엔 Xen을 썼고, 지금은 Nitro 하이퍼바이저(KVM 기반)를 쓴다.
중간 매개체가 없다. VM에서 디스크를 읽으려면 하이퍼바이저가 바로 하드웨어에 명령을 보낸다. 일반 OS가 거치지 않으므로 오버헤드가 최소화된다.
# KVM 예시 (Ubuntu 서버)
# 1. KVM 설치
sudo apt install qemu-kvm libvirt-daemon-system
# 2. VM 생성
virt-install \
--name ubuntu-vm \
--ram 2048 \
--disk path=/var/lib/libvirt/images/ubuntu-vm.img,size=20 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu20.04 \
--network bridge=virbr0 \
--graphics none \
--cdrom /path/to/ubuntu.iso
# 3. VM 시작
virsh start ubuntu-vm
# 4. VM 목록 확인
virsh list --all
KVM은 리눅스 커널 자체가 하이퍼바이저 역할을 한다. 커널 모듈(kvm-intel 또는 kvm-amd)을 로드하면 CPU의 하드웨어 가상화 기능(Intel VT-x, AMD-V)을 활용해 VM을 실행한다. Host OS가 있긴 하지만, 커널 레벨에서 직접 가상화를 처리하므로 Type 1에 가깝다. (학술적으론 하이브리드라고도 부른다.)
Intel VT-x와 AMD-V는 CPU가 하드웨어 레벨에서 가상화를 지원하는 기술이다. 예전엔 하이퍼바이저가 소프트웨어적으로 Guest OS의 특권 명령어(privileged instructions)를 가로채야 했다. 이걸 Binary Translation 방식이라고 하는데, 느렸다. VT-x/AMD-V가 나오면서 CPU가 직접 VM의 명령어를 처리할 수 있게 됐다.
# VT-x/AMD-V 지원 확인 (Linux)
egrep -o '(vmx|svm)' /proc/cpuinfo
# vmx → Intel VT-x
# svm → AMD-V
요즘은 하드웨어 지원 가상화가 보편화되어 Full Virtualization이 대세다.
Type 1의 장점 중 하나가 Live Migration이다. VM을 끄지 않고 다른 물리 서버로 옮길 수 있다. 서버 유지보수를 해야 할 때, VM을 다른 서버로 옮기고 기존 서버를 끈다. 사용자는 서비스 중단을 느끼지 못한다.
# KVM에서 Live Migration (libvirt)
virsh migrate --live ubuntu-vm qemu+ssh://target-host/system
내부적으론 메모리 페이지를 점진적으로 복사하고, 마지막 순간 아주 짧은 시간(수십 ms) 동안만 VM을 멈춰서 나머지 메모리를 동기화한 뒤 대상 서버에서 재개한다.
Type 2는 Host OS(Windows, macOS, Linux) 위에 소프트웨어로 설치된다. VirtualBox, VMware Workstation, Parallels가 여기 속한다. 우리가 "VM 소프트웨어 설치했다"고 할 때 대부분 Type 2다.
┌────────────────────────────────────────┐
│ VM (Ubuntu) │
│ Guest OS │
├────────────────────────────────────────┤
│ Type 2 Hypervisor (VirtualBox) │ ← 애플리케이션 계층
├────────────────────────────────────────┤
│ Host OS (macOS) │ ← 이 OS가 하드웨어 제어
├────────────────────────────────────────┤
│ Physical Hardware (CPU, RAM) │
└────────────────────────────────────────┘
VM이 디스크를 읽으려면:
경로가 길다. 오버헤드가 크다.
# VirtualBox 예시 (macOS/Linux/Windows)
# 1. VM 생성
VBoxManage createvm --name "Ubuntu-VM" --ostype "Ubuntu_64" --register
# 2. 메모리와 CPU 할당
VBoxManage modifyvm "Ubuntu-VM" --memory 2048 --cpus 2
# 3. 가상 디스크 생성
VBoxManage createhd --filename ~/VirtualBox\ VMs/Ubuntu-VM/Ubuntu-VM.vdi --size 20480
# 4. 디스크 연결
VBoxManage storagectl "Ubuntu-VM" --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach "Ubuntu-VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/Ubuntu-VM/Ubuntu-VM.vdi
# 5. ISO 연결
VBoxManage storageattach "Ubuntu-VM" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium ~/ubuntu-20.04.iso
# 6. VM 시작
VBoxManage startvm "Ubuntu-VM" --type headless
# 7. VM 목록 확인
VBoxManage list vms
VirtualBox는 CLI(VBoxManage)와 GUI를 모두 제공한다. 개발자는 CLI로 VM을 자동화할 수 있다(예: Vagrant가 VirtualBox CLI를 사용).
일반인도 쓸 수 있다. 맥에서 VirtualBox 설치 파일(.dmg) 다운로드하고 더블클릭하면 끝이다. VM에 리눅스를 깔아서 웹 서버를 띄우고, Host macOS에선 브라우저로 접속해본다. 개발 환경 실험에 최적이다.
Host OS가 자원을 먼저 쓴다. 내 맥북 RAM이 16GB인데, macOS가 8GB를 쓰고 있으면 VM에 줄 수 있는 건 최대 8GB다. 실제론 덜 준다. VM에서 무거운 작업을 하면 Host OS까지 느려진다.
Type 2의 강력한 기능이 Snapshot이다. VM의 상태를 저장해두고, 나중에 그 시점으로 되돌릴 수 있다. "이 실험 하다가 망가뜨리면 어쩌지?" → 스냅샷 찍어놓고 시도한다.
# VirtualBox 스냅샷
VBoxManage snapshot "Ubuntu-VM" take "before-experiment" --description "Clean state"
# 나중에 복원
VBoxManage snapshot "Ubuntu-VM" restore "before-experiment"
Type 1도 스냅샷을 지원하지만, Type 2가 개인 실험용으로 더 직관적이다.
VM 안에서 또 VM을 돌리는 걸 Nested Virtualization이라고 한다. 예를 들어, VirtualBox(Type 2) 안에서 KVM(Type 1)을 돌려서 VM을 만드는 것. 성능은 끔찍하지만, 교육이나 테스트 목적으론 유용하다.
# VirtualBox에서 Nested Virtualization 활성화
VBoxManage modifyvm "Ubuntu-VM" --nested-hw-virt on
클라우드에서도 Nested Virtualization을 지원한다. AWS의 *.metal 인스턴스나 Azure의 Dv3/Ev3 시리즈에서 가능하다.
Docker를 쓰다 보면 "이것도 가상화 아닌가?"라는 생각이 든다. 비슷해 보이지만 다르다.
하이퍼바이저 (VM)
┌────────────┬────────────┐
│ VM 1 │ VM 2 │
│ Full OS │ Full OS │ ← 각각 커널 포함
├────────────┴────────────┤
│ Hypervisor │
├─────────────────────────┤
│ Host OS / Hardware │
└─────────────────────────┘
컨테이너 런타임 (Docker)
┌────────────┬────────────┐
│ Container 1│ Container 2│
│ App + Libs │ App + Libs │ ← 커널 공유
├────────────┴────────────┤
│ Container Runtime │
├─────────────────────────┤
│ Host OS (Linux Kernel) │
└─────────────────────────┘
클라우드에선 VM과 컨테이너를 함께 쓴다. VM으로 인프라를 격리하고, VM 안에서 Docker 컨테이너를 실행한다.
하이퍼바이저는 물리 자원을 가상 자원으로 변환한다.
# KVM에서 vCPU/vRAM 할당
virt-install \
--name test-vm \
--ram 4096 \ # vRAM 4GB
--vcpus 2 \ # vCPU 2개
--disk size=10 \
--os-variant ubuntu20.04
오버커밋(Over-commit)은 물리 자원보다 많은 가상 자원을 할당하는 것. 예를 들어 물리 CPU 코어 4개에 vCPU를 총 8개 할당. 모든 VM이 동시에 100% CPU를 쓰지 않는다는 가정 하에 작동한다. 클라우드 제공자들은 이걸 활용해서 비용을 절감한다.
최근에는 Type 1과 Type 2, 그리고 컨테이너의 장점을 합친 MicroVM이 뜨고 있습니다. 대표적인 예가 AWS의 Firecracker입니다.
이제 "VM은 무겁다"는 편견도 깨지고 있습니다. 기술은 계속 돌고 돕니다.
보안 관점에서 Type 1이 Type 2보다 훨씬 안전합니다.
그래서 기업 환경에서는 절대 Type 2를 메인 서버로 쓰지 않는 것입니다.
CPU 가상화보다 더 복잡한 게 메모리 가상화입니다. 게스트 OS는 자기가 물리 메모리(0번지~)를 독점한다고 착각하지만, 실제로는 호스트 메모리의 일부일 뿐입니다.
도커가 OS를 공유해서 가볍다면, Unikernel은 아예 OS를 라이브러리처럼 애플리케이션에 링크해버립니다. 불필요한 커널 기능을 싹 걷어내고, 내 앱에 필요한 기능(예: 네트워크 스택)만 넣어서 컴파일합니다. 부팅 시간이 밀리초 단위고, 보안성도 뛰어납니다. 아직은 실험적이지만 클라우드 네이티브의 끝판왕이 될 수도 있습니다.
하이퍼바이저를 이해하니 클라우드의 작동 원리가 보인다. AWS에서 EC2 인스턴스를 띄우면, 사실 Nitro 하이퍼바이저가 물리 서버 하나에서 내 VM을 만들어주는 것이다. 내가 t3.medium을 선택하면 vCPU 2개, vRAM 4GB를 할당받는다. 이 서버엔 내 VM 말고도 수십 개의 다른 VM이 돌고 있을 것이다.
로컬에선 Type 2를 쓴다. VirtualBox에 우분투 VM을 만들어서 쿠버네티스 클러스터를 실험해본다. 망가뜨려도 스냅샷으로 복구하면 된다. 이 환경에서 충분히 테스트한 뒤, 실제 서비스는 클라우드의 Type 1 환경(EC2)에 배포한다.
Type 1은 속도와 효율을 위해, Type 2는 편의성과 실험을 위해 존재한다. 둘 다 "하드웨어 자원을 여러 OS가 나눠 쓰게 한다"는 목표는 같지만, 설치 위치와 성능 트레이드오프가 다르다. 이제 "하이퍼바이저가 뭐야?"라는 질문엔 "어디에 설치되냐에 따라 다르다"고 답할 수 있다.
I was setting up a local development environment. I needed to test a Linux server configuration before deploying it to production. Someone suggested VirtualBox. I installed it, created an Ubuntu VM, allocated 2 CPU cores and 4GB RAM, and it worked. But it was slow. Opening a terminal in the VM had noticeable lag.
Then I visited a data center. A server had no operating system. I pressed the power button, and instead of Windows or Linux, a VM management interface appeared. I could create VMs directly from there. No host OS. The technician said, "This is ESXi. We run 30 VMs on this one server. It's fast." Same concept—virtualization—but completely different architecture.
That's when I realized: hypervisors come in two types, and the difference matters.
A hypervisor is software that creates and manages virtual machines. It takes physical hardware resources (CPU, memory, disk, network) and divides them among multiple VMs, allowing each VM to run its own operating system independently. The critical distinction is where the hypervisor is installed, which determines whether it's Type 1 or Type 2.
Type 1 runs directly on hardware. No host OS. You boot the machine, and the hypervisor starts. The hypervisor itself acts as the operating system.
┌─────────────────────────────────────┐
│ VM 1 (Ubuntu) │ VM 2 (Windows) │
│ Guest OS │ Guest OS │
├─────────────────────────────────────┤
│ Type 1 Hypervisor (ESXi) │ ← Controls hardware directly
├─────────────────────────────────────┤
│ Physical Hardware (CPU, RAM) │
└─────────────────────────────────────┘
Examples: VMware ESXi, Microsoft Hyper-V (Server), Xen, KVM (Kernel-based Virtual Machine). Cloud providers use Type 1. AWS EC2 used Xen, now uses Nitro Hypervisor (KVM-based). Google Cloud uses KVM. Azure uses Hyper-V.
No middleman. When a VM needs to read from disk, the hypervisor sends the command directly to hardware. No host OS in between. Minimal overhead.
# KVM Example (Ubuntu Server)
# 1. Install KVM
sudo apt install qemu-kvm libvirt-daemon-system
# 2. Create VM
virt-install \
--name ubuntu-vm \
--ram 2048 \
--disk path=/var/lib/libvirt/images/ubuntu-vm.img,size=20 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu20.04 \
--network bridge=virbr0 \
--graphics none \
--cdrom /path/to/ubuntu.iso
# 3. Start VM
virsh start ubuntu-vm
# 4. List VMs
virsh list --all
KVM is interesting. It's a Linux kernel module. Load kvm-intel or kvm-amd, and the kernel itself becomes the hypervisor. It uses CPU hardware virtualization (Intel VT-x or AMD-V) to run VMs. Technically, Linux is the host OS, but since virtualization happens at the kernel level, it's classified as Type 1 (or hybrid).
Intel VT-x and AMD-V are CPU features that enable hardware-level virtualization. Before these, hypervisors had to intercept privileged instructions using software techniques (Binary Translation). It was slow. With VT-x/AMD-V, the CPU handles VM instructions directly.
# Check VT-x/AMD-V support (Linux)
egrep -o '(vmx|svm)' /proc/cpuinfo
# vmx → Intel VT-x
# svm → AMD-V
If you don't see vmx or svm, your CPU doesn't support hardware virtualization, or it's disabled in BIOS.
Nowadays, with widespread hardware virtualization support, full virtualization is standard.
One advantage of Type 1 is live migration. You can move a running VM from one physical server to another without shutting it down. During server maintenance, you migrate all VMs to another server, then power down the original. Users experience no downtime.
# KVM Live Migration (libvirt)
virsh migrate --live ubuntu-vm qemu+ssh://target-host/system
Internally, the hypervisor copies memory pages incrementally, then pauses the VM for a very brief moment (tens of milliseconds) to synchronize the remaining memory, and resumes on the target server.
Type 2 is installed as software on top of a host OS (Windows, macOS, Linux). VirtualBox, VMware Workstation, Parallels Desktop are Type 2. When we say "I installed VM software," it's usually Type 2.
┌────────────────────────────────────────┐
│ VM (Ubuntu) │
│ Guest OS │
├────────────────────────────────────────┤
│ Type 2 Hypervisor (VirtualBox) │ ← Application layer
├────────────────────────────────────────┤
│ Host OS (macOS) │ ← Controls hardware
├────────────────────────────────────────┤
│ Physical Hardware (CPU, RAM) │
└────────────────────────────────────────┘
When a VM wants to read from disk:
Longer path. Higher overhead.
# VirtualBox Example (macOS/Linux/Windows)
# 1. Create VM
VBoxManage createvm --name "Ubuntu-VM" --ostype "Ubuntu_64" --register
# 2. Allocate memory and CPU
VBoxManage modifyvm "Ubuntu-VM" --memory 2048 --cpus 2
# 3. Create virtual disk
VBoxManage createhd --filename ~/VirtualBox\ VMs/Ubuntu-VM/Ubuntu-VM.vdi --size 20480
# 4. Attach disk
VBoxManage storagectl "Ubuntu-VM" --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach "Ubuntu-VM" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/Ubuntu-VM/Ubuntu-VM.vdi
# 5. Attach ISO
VBoxManage storageattach "Ubuntu-VM" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium ~/ubuntu-20.04.iso
# 6. Start VM
VBoxManage startvm "Ubuntu-VM" --type headless
# 7. List VMs
VBoxManage list vms
VirtualBox provides both CLI (VBoxManage) and GUI. Developers can automate VMs using CLI (Vagrant uses VirtualBox CLI).
Anyone can use it. Download VirtualBox installer, double-click, done. Install Linux in a VM, run a web server, access it from the host OS browser. Perfect for experimentation.
The host OS consumes resources first. If my MacBook has 16GB RAM and macOS is using 8GB, the VM can only get up to 8GB. Usually less. Running heavy tasks in the VM slows down the host OS too.
A powerful Type 2 feature is snapshots. You can save the VM's state and restore it later. "What if this experiment breaks the VM?" → Take a snapshot, then experiment.
# VirtualBox snapshot
VBoxManage snapshot "Ubuntu-VM" take "before-experiment" --description "Clean state"
# Restore later
VBoxManage snapshot "Ubuntu-VM" restore "before-experiment"
Type 1 also supports snapshots, but Type 2 makes it more intuitive for personal use.
Running a VM inside a VM is called nested virtualization. For example, running KVM (Type 1) inside VirtualBox (Type 2) to create VMs. Performance is terrible, but it's useful for education or testing.
# Enable nested virtualization in VirtualBox
VBoxManage modifyvm "Ubuntu-VM" --nested-hw-virt on
Cloud providers also support nested virtualization. AWS *.metal instances and Azure Dv3/Ev3 series allow it.
When using Docker, I wondered, "Isn't this also virtualization?" They look similar but are different.
Hypervisor (VM)
┌────────────┬────────────┐
│ VM 1 │ VM 2 │
│ Full OS │ Full OS │ ← Each includes kernel
├────────────┴────────────┤
│ Hypervisor │
├─────────────────────────┤
│ Host OS / Hardware │
└─────────────────────────┘
Container Runtime (Docker)
┌────────────┬────────────┐
│ Container 1│ Container 2│
│ App + Libs │ App + Libs │ ← Share kernel
├────────────┴────────────┤
│ Container Runtime │
├─────────────────────────┤
│ Host OS (Linux Kernel) │
└─────────────────────────┘
In the cloud, VMs and containers are used together. VMs isolate infrastructure, and Docker containers run inside VMs.
Hypervisors convert physical resources into virtual resources.
# KVM vCPU/vRAM allocation
virt-install \
--name test-vm \
--ram 4096 \ # 4GB vRAM
--vcpus 2 \ # 2 vCPUs
--disk size=10 \
--os-variant ubuntu20.04
Over-commit means allocating more virtual resources than physical resources. For example, 4 physical cores but 8 vCPUs total. This works because not all VMs use 100% CPU simultaneously. Cloud providers use over-commit to reduce costs.
Recently, MicroVMs have emerged, combining the best of Type 1, Type 2, and Containers. The most famous example is AWS Firecracker.
The stereotype that "VMs are heavy" is shattered. Technology cycles continue.
From a security perspective, Type 1 is vastly superior to Type 2.
This is why enterprises never use Type 2 for critical production work.
Virtualizing the CPU is hard, but virtualizing Memory is a nightmare. Guest OS thinks it owns physical memory starting from address 0, but it actually lives in a slice of Host memory.
If Docker creates a lightweight userspace, Unikernels strip down the Kernel itself. You compile your application with a minimal kernel library customized for just that app. No unused drivers, no multi-user support, no shell. Just your code and the bare metal essentials. It boots in milliseconds and has a tiny attack surface. It's still niche, but it represents the ultimate optimization of cloud workloads.