Monday, April 13, 2009

The Beginner's Guide to Creating Virtual Machines with VirtualBox [How-to]

Source: http://feeds.gawker.com/~r/lifehacker/full/~3/9XeN-MYAdvw/the-beginners-guide-to-creating-virtual-machines-with-virtualbox

Virtual machines can seem juuuuust a bit too geeky for most otherwise computer-friendly people. That's sad, because it's an easy, free way to try or use a separate OS without messing with your hard drive.

What's virtualization? Why get that nerdy?

Virtualization is a whole computer concept unto itself, at least on the server/enterprise/big-fancy-corporate level. For home users, talk about "virtual machines" generally refers to x86 virtualization. Basically, it's software that allows an entire operating system (the "guest") to run on another OS (the "Host"), whether in a container window, or full-screen, or in what's sometimes called a "seamless" mode, where just one application is run from the "guest"

Why would you want to run a virtual machine on your computer? Plenty of reasons:

  • You like using one OS, but need just an app or two from another running in their natural environments—Office or Photoshop in Windows (nine times out of 10), a light-on-resources game, or maybe even some uber-cool Linux app.
  • You want to try out some new software, but would rather not chance it mucking up the pretty decent system you've got right now.
  • Web sites that don't play nice with the operating system you're running (we're looking at you, almost every streaming site except Hulu and YouTube).
  • You're intrigued at the idea of trying out a Linux desktop, but the word "partitioning" doesn't sound like how you want to spend a Saturday afternoon.

For those and many other good reasons, we're going to walk through installing VirtualBox, a free, open-source virtualization tool offered for Windows, Mac, and Linux desktops, and ! then get virtual copies of Windows XP and Ubuntu running inside them. Installing Windows Vista (Ultimate or Business only, unfortunately) or the Windows 7 beta is about the same process, and almost any Linux distribution is friendly as a virtual machine, but this will give you an understanding of the basic process. Before you even ask, by the way, you can't run OS X as a guest system on Windows or Linux, but the VirtualBox can run most anything else—including those pre-rolled virtual images you find laying around the internet.

I have to note here that VirtualBox is far from the only competitor in this field—in fact, many in the tech community report that VMWare's Workstation offers more features and handles multiple virtual machines better. But VirtualBox is relatively easy to set up, free to install, and works on all three major operating systems.

Setting up

First off, head over to VirtualBox's Download page and grab the right copy for your system. The only real choice falls on Linux users having to choose between 32- and 64-bit versions for their particular distribution—you don't want to run a 64-bit guest on a 32-bit host machine, if you can avoid it. Linux users should note that while there may be a version of VirtualBox available in their repository, it's usually the Open Source Edition, which may not be as up-to-date as the VirtualBox download page, and doesn't offer support for USB devices, along with a few other odds and ends.

Click through the install screens; in most cases, you won't have to stop and change anything. You'll probably get a warning that VirtualBox will have to disconnect and re-connect your network connection for a few seconds while i! t's sett ing up, so finish up any crucial net transfers.

During setup on Windows, you'll be asked to install "device software" or "drivers"—hit "Install" for each, or check the box that indicates you'll "Always trust ..." Sun's drivers.

Once VirtualBox is installed, launch it and you'll arrive at a tauntingly empty screen:


Setting up

Let's get something running in there. One big advantage of virtual machines over partitioning, dual-booting, and all that other hard-drive-tweaking stuff is the ability to install a system right from an ISO file. So if you're testing out a Linux system, just download the ISO from Ubuntu, Fedora, or wherever. And if you've got an older XP installation disc, you can slipstream the latest service pack into it to create a minimal-hassle installation ISO image, and never bother burning it. While you're at it, check out Adam's guide to trimming down Windows to the bare essentials for a real speedy virtual installation ISO. If you've got your installation CD or DVD, however, that'll play, too.

Hit "New" and you'll be asked to give your system a name you'll recognize—in my case, an XP system I'll unleash all my morning Lifehacker test downloads on—and let VirtualBox know generally what variety and flavor it is. Linux users tryin! g out a funky remix can head for Linux->Other Linux.

This next screen asking for a memory allocation seems imposing—I won't give it enough! I'll kill my host system with too much!—but you can entirely change it later on. VirtualBox will recommend a minimum amount, based on the OS you said you were installing, but your common sense will pay off here. I'm usually not running anything intensive on my system with 2GB of memory, so if lost half a GB, or 512MB, I'd probably not notice much. Your mileage will certainly vary, but try peeling off as much as you can at first, then scale it back if you notice your system becoming unstable, or bump it up if you get frustrated with a lag-tastic system-in-a-system.

The next screen asks you to either create a new hard disk image or use an existing one. Assuming this is a first install, keep Boot Hard Disk checked and hit Next to create the image. Hit Next again at the start of the "New Virtual Disk Wizard" (they keep changing the name from "Virtual" to "image," but it's all the same), then you'll be asked to choose a dynamically expanding image or a fixed-size storage. This depends on how much space you're willing to give your virtual OS. Do you have just 8GB you want to give over, and don't want it reaching past that? Choose the fixed-size option, set a size amount in gigabytes, and relax. Or you can choose "dynamically expanding," which, just like it sounds, allots only a little bit of space at first, but will re-report itself to the virtual system as bigger if the OS needs a bit more space.

If you happen to have multiple SATA hard drives in your system, or a fast external SATA, the How-To Geek recommends placing your virtual machine image (the "guest") on a separate physical dri ve from the machine running it (the "host") for better multi-tasking and performance speed, plus a little less wear on a single hard drive. If not, don't worry about it too much, and don't go creating separate partitions for your machines, because you aren't fooling anybody, least of all your system's I/O bus.

Booting up

Assuming everything went well, you'll see your new virtual system in the left-hand pane of the VirtualBox window. Huzzah! But before you hit "start," let's hit "Settings" and get it ready to roll the right way. The first category from the left-hand menu, General, lets you change how much base memory (or RAM) and video memory is given over to the virtual machine. Unless you're planning to enable 3D effects, the default chosen for video memory should be fine, and the 3D acceleration box can remain un-checked. Let's move down to "CD/DVD-ROM."

Make sure "Mount CD/DVD Drive" is checked. If you're going to install your virtual system from a boot CD or DVD, put it in your computer's drive, then select "Host CD/DVD Drive." If you're using a downloaded or custom-made ISO file, select "ISO Image file," hit the folder icon to the right of the drop-down box, and then hit the "Add" button and browse for the ISO you're using. Once you've added an ISO file to this menu, you can mount it in any virtual machine you're running at any time—kind of a nice feature for files you need to get at often. Hit "Select" to close this dialog.

Back at the main Settings window, head down to the Audio and/or USB menus and enable them if you're going to be needing sound or access to thumb/external drives while you're in your OS-in-a-box. Before we get to the "Shared Folders," which is pretty darned convenient, let's boot our system. Hit OK and close out your Settings window, then hit Start back at the main box to get rolling.

Whatever ISO or disc you've supplied VirtualBo! x with w ill load just like it's on a machine for the first time, and you'll go through the same installation process as if you were loading Windows/Linux/whatever on a hard drive for the first time. You'll get occasional pop-ups from VirtualBox, "notifying" you that a mouse pointer is now in such-and-such a mode, the video display has changed, yada, yada—just hit OK and check the boxes so it doesn't bother you further. Click through all the usual name/username/password/registration jazz you're used to ... All done? Great. After however many reboots, you'll arrive at your fresh, clean desktop, which you could start using right away. You might notice, however, that the resolution is limited, the mouse might be jerky, and your sound or USB might not work out of the box. That's where the Guest Additions come in.

Fine-tuning

Head to the "Devices" menu at the top of the virtual OS window (if you've accidentally gotten into full-screen mode, hit right-Control+F to switch out) and choose "Install Guest Additions." In a virtual Windows, you'll get a prompt like you were installing software you just downloaded; if not, you can open My Computer, open up the CD drive named "VirtualBox Guest Additions," and run the auto-run software in there. In a virtual Linux, you may just get a CD or DVD mounted and displayed on the desktop. Each Linux system will be slightly different, but the Tombuntu blog's instructions for installing VirtualBox Guest Additions in Ubuntu hold mostly true: head to where the ISO is mounted as a CD/DVD drive, then run VBoxLinuxAdditions-x86.run (or the -amd64 version for 64-bit systems). Click through everything, restart your system, and things should be a lot more convenient: Your virtual desktop resizes itself to however big you make ! its wind ow, the mouse doesn't get "captured" and require un-locking when you click around, and everything should be a bit smoother.

You've got a well-oiled virtual machine at this point, but let's make it real easy to pass files between your host and guest systems (terminology should be making sense at this point, no?). The VirtualBox makers have described the process for Windows and Linux users in a FAQ post, and I've described the virtual-Windows-inside-Linux process in more detail in our guide to running Windows apps seamlessly inside Linux. Giannis Tsakiris has also explained setting up sharing from an XP guest, and the process is much the same for any virtual Windows (although some of the network tools have changed names). Need a bit more? Here's a quick video guide for a Windows guest system:


Now you're up and running with a machine you don't have to feel bad about messing with, or which lets your run the few apps you need in one OS while enjoying the benefits of the one you really want to work in. Wanna explore what kinds of systems you can install, and save yourself some install time while you're at it? Head over to VirtualBox Images, where you can download and run pre-compiled VDI files (i.e. VirtualBox hard drive images, like the dynamic/fixed kind you created above) for some swap-and-run fun. (Thanks to CherylIshabunny for the link!).

Are you an experienced virtual machine user with suggestions on making the process smoother for begin! ners? Ju st starting out and need something clarified? Drop your questions and suggestions in the comments, and we'll update the post as the good stuff trickles in.