is now easy: VirtualBox OSE

BobBob IgoIgo – StormLogic.comStormLogic.com – mythic.tvmythic.tv

Preface

● I am not a VM guru

● All examples are for VirtualBox OSE – http://www.virtualbox.org

Goals

● BasicBasic definitiondefinition ofof VirtualVirtual MachineMachine – SimpleSimple usesuses ofof VirtualBoxVirtualBox OSEOSE ● ExpandedExpanded definitiondefinition ofof VirtualVirtual MachineMachine – OtherOther similarsimilar conceptsconcepts ● What'sWhat's itit goodgood for?for? ● What'sWhat's itit badbad for?for? ● ComplexComplex waysways toto useuse VirtualBoxVirtualBox OSEOSE

Virtual Machine: Basic Definition

● WikipediaWikipedia says:says: ”A”A virtualvirtual machinemachine (VM)(VM) isis aa softwaresoftware implementationimplementation ofof aa machinemachine (i..(i.e. aa computer)computer) thatthat executesexecutes programsprograms likelike aa physicalphysical machine.”machine.”

Virtual Machine: Basic Definition

● II say:say: AA VMVM isis likelike TheThe MatrixMatrix forfor software.software. – ””Whoah.”Whoah.” –– Neo,Neo, TheThe MatrixMatrix ● UnlessUnless itit isis designeddesigned toto check,check, softwaresoftware won'twon't knowknow it'sit's runningrunning onon aa VM.VM.

Virtual Machine: Basic Definition

● QuestionsQuestions soso far?far? ● SimpleSimple usesuses comingcoming up.up.

Simple Use #1

● RunRun aa livelive LinuxLinux ISOISO inin parallelparallel withwith youryour currentcurrent OSOS withoutwithout rebooting.rebooting. – YouYou cancan dodo thisthis withinwithin secondsseconds ofof installinginstalling VirtualBoxVirtualBox onon youryour hosthost OS.OS. – DefaultDefault networknetwork configurationconfiguration letslets thethe VMVM getget outout toto thethe WAN,WAN, butbut nothingnothing elseelse cancan getget in.in.

Simple Use #1 HOWTO

Simple Use #1 HOWTO

Simple Use #1 HOWTO

Simple Use #1 HOWTO

Simple Use #1 HOWTO

Simple Use #1 HOWTO

Simple Use #1 HOWTO

Simple Use #1

● QuestionsQuestions onon usingusing VirtualBoxVirtualBox forfor livelive ISOs?ISOs? ● AA secondsecond exampleexample isis next.next.

Simple Use #2

● InstallInstall andand runrun inin parallelparallel asas manymany OSesOSes asas youryour computercomputer cancan handle.handle. – YouYou cancan startstart installinginstalling guestguest OSesOSes withinwithin minutesminutes ofof installinginstalling VirtualBoxVirtualBox onon youryour hosthost OS.OS.

Simple Use #2 HOWTO

● AsAs before,before, exceptexcept youyou justjust needneed toto createcreate andand useuse aa virtualvirtual HDDHDD (.vdi(.vdi file).file).

Simple Use #2 HOWTO

Simple Use #2 HOWTO

Simple Uses

● QuestionsQuestions aboutabout simplesimple uses?uses? ● ExpandedExpanded definitiondefinition ofof VirtualVirtual MachineMachine isis next.next.

Virtual Machine: Expanded Definition

● AA VirtualVirtual MachineMachine isis fakefake hardware,hardware, writtenwritten inin software.software. – InIn somesome cases,cases, thethe hosthost computer'scomputer's realreal hardwarehardware cancan bebe exposed.exposed. ● AA virtualvirtual diskdisk isis justjust aa filefile accessibleaccessible fromfrom youryour hosthost computer.computer. ● TheThe VMVM mediatesmediates betweenbetween youryour realreal hardwarehardware andand softwaresoftware runningrunning inin thethe VM.VM.

Virtual Machine: Expanded Definition

● GPUGPU onon host:host: igo@demon:~/Desktop$ lspci | grep VGA 01:00.0 VGA compatible controller: nVidia Corporation GeForce 9600M GT (rev a1)

● GPUGPU inin VM:VM: igo@karmic-test:~/Desktop$ lspci | grep VGA 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter

Virtual Machine: Expanded Definition

● HowHow doesdoes softwaresoftware workwork onon realreal hardware?hardware?

Virtual Machine: Expanded Definition

Software: Applications

Software: Kernel

libraries drivers

Hardware

CPU RAM HDD DVDROM AUDIO GPU I/O

Virtual Machine: Expanded Definition

● HowHow doesdoes softwaresoftware workwork onon virtualvirtual hardware?hardware? ● First,First, rememberremember thatthat VirtualBoxVirtualBox isis justjust softwaresoftware that'sthat's runningrunning onon realreal hardware.hardware.

Virtual Machine: Expanded Definition

Software: VirtualBox Software: Applications

Software: Kernel

libraries drivers

Virtual Hardware CPU RAM HDD DVDROM AUDIO GPU I/O

Software: Kernel

libraries drivers

Hardware

CPU RAM HDD DVDROM AUDIO GPU I/O Virtual Machine: Expanded Definition

● VirtualBoxVirtualBox presentspresents fakefake hardwarehardware toto anyany softwaresoftware runningrunning inin it.it. ● VirtualBoxVirtualBox translatestranslates operationsoperations onon fakefake hardwarehardware intointo somethingsomething thethe hosthost OSOS cancan perform.perform. – E.g.E.g. FormattingFormatting aa virtualvirtual diskdisk →→ performingperforming filefile operationsoperations onon thethe .vdi.vdi filefile onon thethe hosthost OSOS

Virtual Machine: Expanded Definition

● QuestionsQuestions onon howhow VirtualVirtual MachinesMachines work?work? ● NextNext up:up: ConceptsConcepts similarsimilar toto VMs.VMs.

Emulators

● WikipediaWikipedia says:says: ”An”An emulatoremulator [...][...] duplicatesduplicates (provides(provides anan emulationemulation of)of) thethe functionsfunctions ofof oneone systemsystem usingusing aa differentdifferent system,system, soso thatthat thethe secondsecond systemsystem behavesbehaves likelike (and(and appearsappears toto be)be) thethe firstfirst system.”system.” ● ThereThere areare twotwo majormajor kindskinds ofof emulators:emulators: emulatorsemulators ofof hardware,hardware, andand OSOS emulators.emulators. ● Let'sLet's startstart withwith emulatorsemulators ofof hardware.hardware.

Example real-world emulator #1

● EarlyEarly attemptattempt atat aa birdbird flightflight emulator,emulator, inin hardwarehardware

Example real-world emulator #2

● Robocarp,Robocarp, aa fishfish swimmingswimming emulatoremulator inin hardwarehardware

Emulators of Hardware: Cousins of VMs

● WhatWhat ifif youyou neededneeded aa VirtualVirtual MachineMachine toto pretendpretend itit waswas hardwarehardware youyou don'tdon't have?have?

Emulators of Hardware: Cousins of VMs

● IfIf youyou werewere givengiven softwaresoftware thatthat aliensaliens usedused onon theirtheir hardware,hardware, you'dyou'd needneed aa emulatoremulator ofof alienalien hardwarehardware toto runrun it.it.

Emulators of Hardware: Cousins of VMs

● LikeLike aa VM,VM, thethe emulatoremulator ofof hardwarehardware presentspresents fakefake hardware,hardware, butbut thethe translationtranslation fromfrom operationsoperations onon fakefake hardwarehardware intointo operationsoperations onon realreal hardwarehardware isis moremore involved.involved. – HumanHuman computerscomputers havehave nono IlludiumIlludium Q-36Q-36 ExplosiveExplosive SpaceSpace Modulators,Modulators, forfor example.example.

Emulators of Hardware: Cousins of VMs

● UnlikeUnlike aa VM,VM, thethe emulatoremulator makesmakes aa fakefake IQ36ESMIQ36ESM inin software;software; itit maymay oror maymay notnot interactinteract withwith thethe hosthost hardwarehardware inin anyany meaningfulmeaningful way.way.

Emulators of Hardware: Cousins of VMs

● QuestionsQuestions aboutabout thethe distinctiondistinction betweenbetween aa VMVM andand anan emulatoremulator ofof hardware?hardware? ● EmulatorsEmulators ofof OSesOSes areare next.next.

OS Emulators: Cousins of VMs

● AnAn OSOS emulatoremulator willwill runrun applicationsapplications thatthat werewere writtenwritten forfor anotheranother OS.OS. – IfIf thethe OSOS emulatoremulator cancan bebe installedinstalled asas thethe primaryprimary OS,OS, it'sit's aa cloneclone ofof thethe OSOS it'sit's emulating.emulating.

OS Emulators: Cousins of VMs

● IfIf thethe OSOS emulatoremulator needsneeds toto bebe runrun asas anan applicationapplication ofof aa fullfull OS,OS, it'sit's closercloser toto aa VM.VM.

Emulators: Cousins of VMs

● SomeSome famousfamous emulators:emulators: – DOSEMUDOSEMU

– MAME*MAME*

– WINEWINE****

* MAME emulates hardware ** only lets you run Windows applications; it isn't otherwise a Windows substitute. Emulators

● QuestionsQuestions onon thethe differencedifference betweenbetween VMsVMs andand differentdifferent kindskinds ofof emulators?emulators? ● NextNext up:up: WhatWhat areare VMsVMs goodgood for?for?

What are VMs good for?

● ReducingReducing hardwarehardware bottlenecksbottlenecks – AA VMVM onon aa goodgood hosthost cancan bebe fasterfaster thanthan youryour sparespare PCPC – 11 PCPC cancan actact likelike NN PcsPcs

>=>=

What are VMs good for?

● VMsVMs areare farfar moremore flexibleflexible thanthan physicalphysical hardware.hardware. – ””disk”disk” imagingimaging isis inherentinherent – RecoveringRecovering fromfrom hardwarehardware failuresfailures isis easyeasy – EasyEasy toto copycopy aa VMVM andand experimentexperiment withwith itit

What are VMs good for?

● VMVM flexibility,flexibility, continued...continued... – EvenEven somesome portabilityportability betweenbetween differentdifferent VMsVMs – YourYour VMVM cancan moremore corescores thanthan thethe host*host*

* Of course, this gives bad performance, but it's good for testing. What are VMs good for?

● IfIf thethe hosthost OSOS supportssupports youryour hardware,hardware, thethe guestguest OSOS doesn'tdoesn't necessarilynecessarily havehave to.to. – VistaVista notnot working?working? RunRun itit inin aa VMVM insideinside UbuntuUbuntu

←←

What are VMs bad for?

● SomeSome VMsVMs don'tdon't knowknow howhow toto passpass throughthrough realreal hardware.hardware. ● SomeSome VMsVMs aren'taren't yetyet feature-complete;feature-complete; itit cancan taketake timetime toto supportsupport newernewer OSes.OSes.

What are VMs bad for?

● SoftwareSoftware runningrunning inin aa VMVM isis generallygenerally slowerslower thanthan runningrunning directlydirectly onon thethe hosthost system.system. ● TestingTesting inin aa VMVM isis nono substitutesubstitute forfor testingtesting onon realreal hardware,hardware, oror inin aa differentdifferent VM.VM.

What are VMs bad for?

● Hibernate/suspendHibernate/suspend maymay notnot work.work.

What are VMs are good/bad for?

● QuestionsQuestions aboutabout whatwhat VMsVMs areare good/badgood/bad for?for? ● ComingComing up:up: ComplexComplex UsesUses forfor VMsVMs

Complex Use #1

● MakeMake aa VMVM forfor eacheach server/daemonserver/daemon youyou needneed toto run.run. – SomeSome businessesbusinesses dodo this.this. ● ExampleExample willwill useuse ApacheApache

Complex Use #1

● WhyWhy dodo thisthis sortsort ofof thing?thing? – VeryVery easyeasy toto testtest changeschanges beforebefore deployingdeploying – VeryVery easyeasy toto deploydeploy changeschanges ● runrun bothboth ApacheApache serverserver VMsVMs ● changechange thethe portport forwardingforwarding toto pointpoint toto thethe latestlatest livelive oneone ● TheThe ”hidden””hidden” VMVM becomesbecomes youryour newnew testtest VM.VM.

Complex Use #1 HOWTO

● InstallInstall UbuntuUbuntu 9.049.04 serverserver inin aa VMVM namednamed ”Ubuntu”Ubuntu 9.049.04 server”server” – OptionsOptions asas inin SimpleSimple UseUse #2#2 – WhenWhen asked,asked, choosechoose toto installinstall ”LAMP”LAMP server”server” ● OnceOnce installed,installed, halthalt thethe server.server.

Complex Use #1 HOWTO

● ConfigureConfigure portport forwardingforwarding fromfrom youryour hosthost machinemachine toto thethe guestguest server:server:

VBoxManage setextradata "Ubuntu 9.04 server" \ "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/Protocol" TCP

VBoxManage setextradata "Ubuntu 9.04 server" \ "VboxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/GuestPort" 80

VBoxManage setextradata "Ubuntu 9.04 server" \ "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestapache/HostPort" 8080

Complex Use #1 HOWTO

● StartStart VMVM UbuntuUbuntu 9.049.04 serverserver

Complex Use #1 HOWTO

● Now,Now, portport 80808080 onon youryour hosthost machinemachine forwardsforwards toto portport 8080 onon youryour guestguest server.server.

Complex Use #1

● QuestionsQuestions aboutabout ComplexComplex UseUse #1?#1? ● ComingComing up:up: ComplexComplex UseUse #2#2

Complex Use #2

● TestingTesting aa captivecaptive portalportal solutionsolution – IfIf youyou usedused realreal hardware,hardware, you'dyou'd need:need: ● aa server/gatewayserver/gateway boxbox withwith twotwo NICsNICs ● NN clientclient machinesmachines ● aa switchswitch forfor thethe subnetsubnet ● physicalphysical accessaccess toto thethe serverserver andand clientsclients

Complex Use #2

● ThatThat wouldwould looklook likelike this:this:

Complex Use #2

● WithWith VirtualBoxVirtualBox OSE,OSE, youyou need:need: – youryour hosthost machinemachine

Complex Use #2

● Scenario:Scenario: TestTest pfSensepfSense asas aa captivecaptive portalportal forfor aa cybercafe.cybercafe.

Complex Use #2 HOWTO

● StepStep 1:1: ConfigureConfigure thethe pfSensepfSense serverserver VM.VM. – AsAs SimpleSimple UseUse #2,#2, except...except...

Complex Use #2 HOWTO

● OSOS isis BSD/FreeBSDBSD/FreeBSD

Complex Use #2 HOWTO

● ChangeChange NICNIC toto ”Bridged”Bridged Adapter”Adapter” inin SettingsSettings →→ NetworkNetwork ● UseUse youryour hosthost machine'smachine's primaryprimary NICNIC forfor ”Name””Name”

Complex Use #2 HOWTO

● ””BridgedBridged Adapter”Adapter” networkingnetworking usesuses thethe host'shost's NICNIC toto putput youryour VMVM onon youryour LANLAN – IfIf youryour LANLAN hashas DHCP,DHCP, VMVM getsgets IPIP addressaddress viavia youryour LAN'sLAN's DHCPDHCP – ToTo LANLAN machines,machines, samesame effecteffect asas ifif thethe VMVM werewere aa realreal machinemachine onon youryour LANLAN

Complex Use #2 HOWTO

● AddAdd aa secondsecond NICNIC onon ”Internal”Internal Network”Network” inin SettingsSettings →→ NetworkNetwork

Complex Use #2 INFO

● ””InternalInternal Network”Network” isis aa software-createdsoftware-created subnet.subnet. ● AllAll NICsNICs onon thethe same-namedsame-named InternalInternal NetworkNetwork cancan talktalk toto eacheach otherother butbut nothingnothing else.else.

Complex Use #2 HOWTO

● Next,Next, createcreate aa VMVM asas inin SimpleSimple VMVM UseUse #1#1 ● Then,Then, putput itsits lonelone NICNIC onon anan InternalInternal NetworkNetwork namednamed intnet.intnet.

Complex Use #2 HOWTO

● BootBoot pfSensepfSense inin VM;VM; installinstall andand configure.configure. – UseUse em0em0 forfor WANWAN (”bridged”)(”bridged”) – UseUse em1em1 forfor LANLAN (”intnet”)(”intnet”) ● BootBoot livelive UbuntuUbuntu VMVM andand testtest thethe captivecaptive portal.portal. – LiveLive UbuntuUbuntu VMVM willwill acquireacquire IPIP addressaddress fromfrom pfSense'spfSense's DHCPDHCP server,server, byby defaultdefault inin 192.168.1.x192.168.1.x subnet.subnet.

Complex Use #2 HOWTO

● InIn livelive UbuntuUbuntu VM:VM: http://192.168.1.1http://192.168.1.1 toto finishfinish pfSensepfSense configuration.configuration.

Complex Uses

● QuestionsQuestions onon ComplexComplex Uses?Uses? ● QuestionsQuestions aboutabout anything?anything? ● NextNext up:up: SummarySummary

Summary

● Don'tDon't fearfear VMsVMs ● TryTry VirtualBoxVirtualBox OSEOSE ● UseUse youryour bestbest hardwarehardware ● TrapTrap programsprograms inin TheThe MatrixMatrix