How Virtual Machines Replicate an OS

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

← 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 →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

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.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
Start with one or two virtual CPUs and add more only if the guest is truly short of processing power. A virtual CPU is a stream of work that the hypervisor schedules onto real cores, so several guests can share fewer cores. Giving a VM as many virtual CPUs as the host has cores is a common mistake, because the host and hypervisor need time too.
How does memory virtualization work with two page tables?
A virtual machine uses two address maps. The guest's own page table turns a guest virtual address into a guest physical address, and the hypervisor's table then turns that into a host physical address in real memory. Modern processors walk both maps in hardware: Intel calls this extended page tables, and AMD calls it nested paging. The second map keeps guests apart and lets memory be filled on demand.
What is a dynamically allocated virtual disk?
A dynamically allocated virtual disk is a disk image file that promises a large size but takes real space only as the guest writes data. The guest sees ordinary blocks and partitions and formats them with a file system, while the hypervisor stores everything inside one file on the host. Because the disk is a file, it can be copied, backed up, moved to another host, or deleted.
What is the difference between NAT and bridged networking in a VM?
With NAT, the VM sits behind the host and can reach the internet, but outside computers cannot start connections to it. With bridged mode, the VM joins the real network as its own computer with its own address. NAT is simple, safe, and the default in VirtualBox. Bridged suits a VM that other computers must reach, such as a test website, unless port forwarding is set up.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Introduction to Operating Systems
3 credits · NCCRS
Enroll →