UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 10.4 Free with a free account
How Virtual Machines Replicate an OS
Introduction to Operating Systems · Chapter 10: Virtualization and Virtual MachinesSection 10.4 · lesson 81 of 838 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Setting Up VirtualBox →← Types of VirtualizationNext lesson: Setting Up VirtualBox →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
How hypervisors imitate processors, memory, disks, networks, and devices.
- Explain how virtual CPUs are scheduled onto real processor cores
- Describe the two-level address translation used for guest memory
- Explain how a virtual disk image and dynamic allocation work
- Compare NAT and bridged networking and emulated versus paravirtual devices
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,161 words). Read along, or search it.
Opening Question
A Computer Built Entirely from Software
Inside a VM, you can open a window, save a file, play a sound, and browse the web, exactly as on a real computer. Yet no real sound card, no real disk, and no real network cable belongs to that guest. Everything it touches is built from software. So how can software pretend to be a processor, memory, a disk, and a network card, so well that an operating system never doubts it? Let's look behind the curtain.
Virtual CPUs
Streams of Work on Real Cores
Start with the processor. When you create a VM, you choose how many virtual CPUs it gets. A virtual CPU isn't a chip. It's a stream of work that the hypervisor schedules onto a real core, just as the scheduler of lesson 2.6 schedules threads. The guest believes it has, say, two processors, and it schedules its own processes on them. Underneath, each virtual CPU gets turns on whichever real core is free. Most guest instructions are ordinary ones, like adding, comparing, and jumping. They run directly on the real processor, at full speed. Only the sensitive ones need the hypervisor, with the hardware help from lesson 10.3. That's why a VM can feel almost as fast as a real computer.
Common Mistake
Too Many Virtual CPUs
A common mistake is to give a VM as many virtual CPUs as the host has cores. The host itself, and the hypervisor, need time too, and a guest with too many virtual CPUs can end up waiting for free cores. Start small, with one or two, and add more only if the guest is truly starved.
Quick Check
Six Virtual CPUs on Four Cores
Quick check. Ivy, who looks after the computers at a school, has a host with four real cores. She runs three guests, each with two virtual CPUs. Can all three guests run at once? Pause, and decide. Yes. A virtual CPU is a stream of work, not a chip, so six of them take turns on four real cores. They only slow down when all of them are busy at once. A core of its own for each is the tempting idea. But the hypervisor schedules, the same way an operating system runs more threads than it has cores.
Memory
Two Maps from Guest to Host
Next, memory. In lesson 4.8, every process used virtual addresses, and a page table mapped them to real memory frames. A guest system does exactly that too. But the physical memory it believes in is itself pretend. So a VM adds a second map. The guest's page table turns a guest virtual address into a guest physical address. Then the hypervisor's own table turns that into a host physical address: a real spot in the real memory chips. Modern chips walk both maps in hardware. Intel calls it extended page tables, and AMD calls it nested paging.
Why Two Maps
Isolation and On-Demand Memory
Why bother with a second map? It lets the hypervisor place each guest in different real frames, and forbid any guest to reach another's. It can also hand out less real memory than the guests were promised, and fill it in only when a guest first touches a page, just like demand paging from lesson 4.7.
Virtual Disks
One Disk Image File That Grows
Now the disk. The guest sees a disk with blocks and partitions, and formats it with a file system, as in lessons 6.1 to 6.4. The hypervisor keeps all of that inside one big file on the host, called a disk image. When the guest reads block 5,000, the hypervisor reads a spot inside that file. Many images are dynamically allocated. They promise a large size, but take real space only as the guest writes data. We tried the idea on a Mac, with a plain file. Set to a size of one gigabyte, in binary units, it used no real space at all. After writing four megabytes into it, it used 4,096 kilobytes: just what was written.
Disk as a File
Copy, Move, and Snapshot
And because a disk is a file, you can copy it, back it up, move it to another host, or throw it away, like any other file. Snapshots, from lesson 10.2, work the same way. They record the changes made after a chosen moment.
Networking
NAT Versus Bridged Mode
Each VM also gets one or more virtual network cards. The hypervisor connects them to the real network in one of two main ways. NAT, or network address translation: the VM sits behind the host, like a family sharing one mailbox. It can reach the internet, and replies come back. But outsiders can't start a connection to it. The host rewrites the addresses in between. It's simple, safe, and the default in VirtualBox. Bridged: the VM's virtual card is joined to the real network card. So the VM appears on your network as its own computer, with its own address, from lesson 7.4.
Quick Check
Letting a Laptop Reach the Test Site
Quick check. Sam, who runs a small online bakery, has a guest running a test copy of the shop's website. Lee, one of Sam's helpers, wants to open it from a laptop on the bakery's Wi-Fi. Which mode should the guest's network card use? Pause, and decide. Bridged. Lee's laptop has to start the connection, so the guest needs its own address on the bakery's network. Under NAT, outsiders can't start a connection, so Lee is shut out, unless someone sets up port forwarding on the host. So pick NAT when a VM only browses or downloads, and bridged when another computer must reach it. A VM open to the network needs updates and a firewall, like any computer.
Devices
Emulated and Paravirtual Devices
What about the keyboard, sound, the screen, and USB? For each, the hypervisor can use device emulation. It presents a common device, like a standard network card, and software that acts like it. The guest already has a driver for it, from lesson 5.6, so it just works. The cost is speed, because every operation is imitated in software. The faster way is a paravirtual device: a made-up device designed for VMs. It needs a special driver in the guest, but wastes less time pretending.
Guest Add-Ons
Guest Additions and VMware Tools
Hypervisors ship those special drivers as an add-on that you install inside the guest: Guest Additions in VirtualBox, and VMware Tools in VMware's products. They bring a screen that resizes with the window, a mouse that moves smoothly in and out, a shared clipboard, shared folders, and faster graphics, disk, and network. Without them, a guest usually still works, but it feels clumsy.
Story Ending
The Basic Outfit and the Add-Ons
Back to Sam, whose very first guest showed only a small, blurry screen. The mouse seemed to get stuck in the window. It works, Ivy laughed, but it's wearing the basic outfit. Install the add-ons, and it will resize, share the clipboard, and let the mouse roam free. You'll install them yourself in lesson 10.5.
Key Takeaways
Virtual Hardware Reviewed
To recap. A virtual CPU is a stream of work that takes turns on real cores. Memory goes through two maps: the guest's, then the hypervisor's. A virtual disk is one file on the host, often growing as data is written. NAT hides a VM behind the host, and bridged puts it on the network. And guest add-ons swap slow imitated devices for fast paravirtual drivers.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About How Virtual Machines Replicate an OS
How many virtual CPUs should a virtual machine have?
How does memory virtualization work with two page tables?
What is a dynamically allocated virtual disk?
What is the difference between NAT and bridged networking in a VM?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →