4.2.40 · HinglishOperating Systems

Virtualization — type 1 and type 2 hypervisors

2,124 words10 min readRead in English

4.2.40 · Coding › Operating Systems


Virtualization KYA hai?

Hum yeh chahte hi KYU hain?

  • Consolidation: 10 servers ka kaam 1 box par chalaao → power/space/paisa bachao.
  • Isolation: VM A mein crash ya hack ho toh VM B ko touch nahi kar sakta.
  • Portability: ek VM sirf files hoti hain → snapshot lo, clone karo, doosre host par live migrate karo.
  • Compatibility: ek hi machine par ek saath Windows + Linux chalaao.

Do types

Yeh split poori tarah stack mein hypervisor kahan rehta hai iske baare mein hai.

Figure — Virtualization — type 1 and type 2 hypervisors

Kaise kaam karta hai: hypervisor mushkil KYU hota hai

Type 1 ise kaise handle karta hai: hypervisor sabse privileged mode mein chalta hai. Guest kernel ko kam privileged level par giraya jaata hai. Jab guest koi sensitive instruction chalata hai, CPU hypervisor mein trap karta hai, jo use emulate karta hai → "trap-and-emulate".

Kyun purana x86 yeh nahi kar paata tha: kuch x86 instructions (jaise POPF) sensitive hain lekin trap nahi karti — woh user mode mein chup-chaap kuch nahi/galat karti hain. Fixes:

  • Binary translation (buri instructions on the fly rewrite karo — early VMware),
  • Paravirtualization (guest ko modify karo taaki woh explicitly hypervisor ko call kare — Xen),
  • Hardware-assisted virtualization (Intel VT-x / AMD-V ek asli "guest mode" add karte hain taaki mushkil instructions bhi cleanly trap ho sakein — modern default).

Type 1 vs Type 2 — woh comparison jo actually matter karta hai (80/20)

Aspect Type 1 (bare-metal) Type 2 (hosted)
Kis par baitha hai Hardware directly Host OS
Silicon tak layers 1 2
Performance Zyada (kam overhead) Kam (extra host hop)
Boot Machine khud boot karta hai App ki tarah launch hota hai
Use case Data centers, cloud, servers Dev/test, laptops, seekhna
Setup ki aasaani Mushkil (dedicated machine) Aasaan (install karo aur chalao)
Security surface Chhota (thin hypervisor) Bada (poora host OS bhi)

Worked examples


Common mistakes (Steel-manned)


Recall Feynman: 12-saal ke bachche ko samjhao

Socho tumhara computer ek bada ghar hai jisme kai kamre hain. Virtualization ek ghar ko pretend karata hai ki woh kai ghar hain, jisme har ek ki apni family (operating system) hai jo sochti hai poori jagah unki hai. Hypervisor woh jaadui landlord hai jo kamre deta hai aur ensure karta hai ki koi bhi family doosre ka saman na dekhe. Type 1 landlord building mein hi rehta hai — super fast, poori jagah chalata hai. Type 2 landlord ek normal building manager (host OS) se apartment rent karta hai aur phir sublet karta hai — theek kaam karta hai, lekin har request ek extra insaan se guzarti hai, toh thoda slow hota hai.


Active recall flashcards

Type 1 aur Type 2 hypervisors mein antar karne wala ek criterion kya hai?
Hardware par directly kya chalta hai — Type 1 mein hypervisor khud (bare-metal) hai; Type 2 ek host OS par app ki tarah chalta hai.
Type 1 hypervisor generally Type 2 se faster kyun hota hai?
Yeh extra host-OS layer hata deta hai; guest requests guest→hypervisor→hardware jaati hain instead of guest→hypervisor→host OS→hardware.
Type 1 aur Type 2 hypervisors ke do-do examples do.
Type 1: VMware ESXi, Hyper-V, Xen, KVM. Type 2: VirtualBox, VMware Workstation, QEMU(user), Parallels.
"Trap-and-emulate" kya hota hai?
Jab ek guest privileged/sensitive instruction chalata hai toh woh hypervisor mein trap ho jaata hai, jo effect ko safely emulate karta hai taaki guest ko hardware ka malik hone ki illusion milti rahe.
Popek & Goldberg virtualizability condition batao.
Ek machine efficiently virtualizable hai iff har sensitive instruction ek privileged (trapping) instruction bhi hai.
Classic x86 cleanly virtualizable kyun NAHI tha?
Kuch sensitive instructions (jaise POPF) user mode mein trap nahi karti thi, Popek-Goldberg violate karta tha; binary translation, paravirtualization, ya VT-x/AMD-V se fix hua.
KVM Type 1 hai ya Type 2, aur kyun?
Effectively Type 1 — yeh ek kernel module hai jo Linux ko hi bare-metal hypervisor bana deta hai (koi alag host-OS app layer nahi).
Hypervisor aur pure emulator mein kya farak hai?
Hypervisor zyatar guest instructions seedha real CPU par chalaata hai aur sirf privileged walon ko trap karta hai; emulator har instruction ko software mein interpret karta hai (slower).
Type 1 ka security attack surface aksar chhota kyun hota hai?
Iska thin hypervisor ek chhota trusted computing base hai, jabki Type 2 poore general-purpose host OS ki vulnerabilities bhi inherit karta hai.
"Guest OS" ka matlab kya hai?
Woh operating system jo virtual machine ke andar chal raha hai, yeh sochte hue ki uske paas dedicated hardware hai.

Connections

  • Operating Systems
  • Processes and Context Switching — VMs ko processes ki tarah scheduling chahiye
  • Memory Management — second-level / nested page tables (EPT/NPT) RAM ko virtualize karte hain
  • CPU Privilege Rings — kernel vs user mode aur kyun traps kaam karte hain
  • Containers vs Virtual Machines — ek kernel share karne wala lighter alternative
  • Cloud Computing — Type 1 hypervisors data centers power karte hain
  • System Calls and Traps — trap mechanism hypervisors mein reuse hota hai

Concept Map

multiplexes one machine into

creates and isolates

each runs

traps and emulates

requires

enables

classified by placement

classified by placement

runs directly on

runs as app on

owns

e.g.

e.g.

gives

Virtualization

Virtual Machines

Hypervisor / VMM

Guest OS

Privileged Instructions

Popek Goldberg 1974

Sensitive = Privileged

Trap-and-Emulate

Type 1 Bare-metal

Type 2 Hosted

Physical Hardware

Host OS

ESXi Hyper-V Xen

VirtualBox QEMU

Consolidation Isolation Portability