Ubuntu Hacks/Virtualization and Emulation
With all the power that today's computers have, why be content to run only one operating system on them? Thanks to modern advances in virtualization technology, you can run multiple operating systems on a single computer at near-native speeds. There are many choices for virtualization on Linux. On the proprietary end, you've got applications such as VMware, and on the open source end, you've got Xen, coLinux, and QEMU (for more information not covered in this chapter, see http://fabrice.bellard.free.fr/qemu/).
If you don't need a full-blown virtualization environment, the open source Wine suite may be just what you need: it's a call-level reimplementation of the Windows Application Programming Interfaces (APIs) that allows many Windows programs to run unmodified on Linux. With proprietary enhancements such as Cedega, Wine can even run many games!
Run Windows Applications
If the Windows applications you need to run just happen to be supported by Wine, you won't need to dual-boot or run an emulator. Just run the installers and launch the programs as if they were any other Linux app.
Novell, the company behind the SUSE distribution, recently ran a survey asking people which Windows applications they would most like ported to Linux. Adobe's Photoshop (number 1), Dreamweaver (3rd), and Flash (5th) all ranked very high (you can see the complete poll results here: http://www.novell.com/coolsolutions/feature/16917.html). Will Adobe be porting these much-requested apps to Linux soon, in response to the survey results? Probably not. But that doesn't mean you can't run them on Linux.
You can run all three of these applications, along with many more, thanks to Wine, an open source Windows compatibility layer. Wine is not an emulator (hence the name, in true GNU recursive style), but it does provide an alternative, 100-percent-non-Microsoft implementation of the DLLs that Windows programs use. (Wine can also use actual Windows DLLs as well.) The software has been in development for more than 12 years and just reached beta status in the fall of 2005. But Wine has been in widespread use for quite some time, and it's included in most distributions, including Ubuntu (in the universe repository [Hack #60]).
The Wine software included with Ubuntu is frequently at least a step behind the current version, so to run the latest version you'll want to edit your /etc/apt/sources.list file and add Wine's own apt repository. You can do so manually, or with the Synaptic Package Manager.
To add the line yourself, open Terminal and enter this command:
$ sudo nano /etc/apt/sources.list
After you furnish your password, the nano editor will open sources.list. Enter this line at the end of the file:
deb http://wine.sourceforge.net/apt binary/
Save the file (press Ctrl-O), then open Terminal again and run:
$ sudo apt-get update
This will update the package cache. Now you can install Wine with the command:
$ sudo apt-get install wine
If you prefer to add the Wine repository and install Wine with Synaptic [Hack #55], click System→Administration→Synaptic Package Manager and select Settings→Repositories. Then click Add, select Custom, and enter deb http://wine.sourceforge.net/apt binary/ in the APT Line field, as shown in Figure 9-1.
Next, click Add Repository, and then click Reload to update the package cache. Now search for wine, highlight it, right-click the highlighted entry, and select Mark for Installation. Then click Apply, review the proposed changes, and click Apply again. Wine will proceed to download and install the latest version (0.9.10 as of this writing).
Wine is very much a work in progress, and each new version shows improvement, even if it sometimes temporarily breaks compatibility with Windows programs that formerly worked. The newer Wine is, the better it is, unlike its vintage namesake. Overall, each new version tends to be more stable and run more Windows software than its predecessor, so it's definitely worth running the latest version.
The first thing you will want to do with Wine is configure it. You do so by running the Wine configuration utility, winecfg. In Terminal, enter:
Running this command will create the Wine configuration directory in /home/username/.wine. It will also bring up the tabbed Wine configuration interface shown in Figure 9-2, which lets you adjust various parameters of your Wine installation, including the version of Windows that you want Wine to behave like. It's generally fine to accept the defaults, but you may find it helpful to add a new Windows drive (via the Drives tab) that explicitly maps to your CD-ROM drive. To do so, click the Add button to create a new Windows D drive, and then click Browse to select the path to your CD-ROM (such as /media/cdrom0/). Finally, click the Apply button to finish.
There's one more thing you should attend to before you begin to install Windows apps, and that is to install Microsoft TrueType fonts [Hack #53] (so applications running in Wine can render text correctly) and cabextract, a useful tool for extracting the contents of Microsoft .cab archives. You can install both packages via apt by issuing this command in Terminal:
$ sudo apt-get install msttcorefonts cabextract
You can also choose to install with Synaptic by searching for the msttcorefonts package, and then installing it. Synaptic will install the cabextract package along with msttcorefonts.
Install a Windows Application
OK, now that you have Wine, msttcorefonts, and cabextract installed, you can install your first Windows application. If you have it, you may as well choose Photoshop, since it is currently the most requested app for porting to Linux (actually, I think the GIMP is more than fine for most web graphics work, but I'll defer to popular opinion here).
Wine won't always run the current version of a Windows application; often, there will be some catching up to do. So, for example, the current version of Photoshop is not likely to work with the current version of Wine (although, at some point in their respective development cycles, it may). Usually, you will run Windows apps that are a generation or two behind. This is what I did with Photoshop. Since I tend to run that application more on OS X, my Windows version (Photoshop 6.0) is older. Photoshop 6 is no slouch in terms of functionality, though, and you can use these instructions to install a more recent version. Photoshop 7 is widely reported to work well, and it's possible you'll be able to get Photoshop CS working, too.
Pop the installation CD for your Windows app in your drive. Open Terminal and type the command wine, followed by the path to the installer. For example:
$ wine "/media/cdrom0/Adobe Photoshop 6/Setup.exe"
That's it. If you're using an application that works with Wine, the installer will launch and install the application into the mock Windows filesystem in your .wine directory, as shown in Figure 9-3.
Run Windows Applications
Now that you've installed a program, you can run it—but you have to find it first. For example, my Photoshop installation is located in the /home/username/.wine/drive_c/Program Files/Adobe/Photoshop 6.0/ directory. To launch Photoshop, I simply type the following command in Terminal:
$ wine "c:\\Program Files\\Adobe\\Photoshop 6.0\\Photoshp.exe"
Photoshop will launch almost instantly (see Figure 9-4). And this old version runs fast—probably faster than it did/does on Windows. It also runs very well; I have yet to encounter any glitches.
Whenever you have questions as to whether a particular Windows application will work with Wine, you should consult the Wine Application Database at http://appdb.winehq.org/. Frank's Corner (http://www.frankscorner.org/) is another good resource for checking whether your application is likely to work.
Working with Wine
When Wine works really well, there's no better way to run a Windows application in a Linux environment. Many people dual-boot, of course, but that is really cumbersome when all you want to do is use a particular application. Other people run Windows itself using emulation software, but that is a less well-integrated solution, more resource-intensive, and generally not as fast. Wine enables Windows apps to run at native speed (at least) and to interact seamlessly with Ubuntu. Photoshop (along with other Windows apps) can open and save files anywhere on your computer, with no special effort required (there's no need for Samba-based file sharing between Ubuntu and your Windows environment, for example). In addition to the mock C drive installed by Wine, there is a Z drive that maps to your Linux filesystem.
Running Wine on your Ubuntu system is very straightforward. You've already seen how to install and then launch Windows applications. Some other basic Wine commands to keep in mind include:
- wine control
- Some programs (such as QuickTime) install associated control-panel applets; wine control will let you access them.
- Running the winefile command will bring up a graphical interface, shown in Figure 9-5, that enables you to view your drive configuration and locate files. You can also run programs directly from this graphical environment; simply double-click on an .exe, just as in Windows.
- The uninstaller program, shown in Figure 9-6, is similar to the Windows Add/Remove Programs control-panel applet. Simply highlight the program you want to remove and click Uninstall. It's that straightforward.
You can access a complete set of Wine documentation at the Wine HQ site: http://www.winehq.org/site/docs/wineusr-guide/index.
Running Other Windows Components
In addition to various Windows applications, you may find it interesting to run various Windows components as well—notably Internet Explorer, the infamous standards-shy browser that is nevertheless used by over 80 percent of all web surfers. There are a number of ways you can install IE.
The easiest way, by far, is to use one of the utilities that have sprung up around Wine to accomplish this very thing. The three major such utilities are WineTools (http://www.von-thadden.de/Joachim/WineTools/), Sidenet (http://sidenet.ddo.jp/winetips/config.html), and the awkwardly named IEs 4 Linux (so named because it will let you install IE 6, IE 5.5, and IE 5 all at once, if you so choose). Of the three, I recommend IEs 4 Linux (http://www.tatanka.com.br/ies4linux/). It is the only one that doesn't radically modify your Wine filesystem and that seems to work smoothly with the latest version of Wine.
To install IEs 4 Linux, first download it from here: http://www.tatanka.com.br/ ies4linux/en/instructions/. Then open the tar.gz file and run the ies4linux program that's inside. You'll be given a choice of which version(s) of IE to install; I chose IE 6 only. IEs 4 Linux will then proceed to download the version(s) you selected; IE 6 alone is an 80 MB download. The Microsoft browser(s) will be installed in a separate, .ies4linux directory in your home directory; your .wine directory is left untouched.
A nice, if rather bizarre touch: an Internet Explorer icon (customized with Wine glass and shown in Figure 9-7) is placed on your Ubuntu desktop. You can simply double-click it to launch the security-challenged browser, which defaults, for safety's sake, to an about:blank home page.
Perhaps you don't want an IE icon on your desktop—I certainly didn't. So I removed it and used Ubuntu's Applications Menu Editor to add Internet Explorer and some other Windows apps to the Ubuntu Applications menu. The result is shown in Figure 9-8 (you'll find the Wine glass in /usr/share/icons).
Note that Wine's commercial cousins, CodeWeavers' CrossOver Office [Hack #31] (http://www.codeweavers.com/) and TransGaming's Cedega [Hack #88] (http://www.transgaming.com/), can add the menu items for you.
Play Windows Games
Those Windows games don't have to be trapped in that partition you rarely boot into. Instead, you can use Wine or Cedega to play them.
Wine (http://www.winehq.com), the open source Windows compatibility layer [Hack #87], is well known for its ability to run many popular Windows applications, and even certain Windows components such as Internet Explorer. Wine can also run some popular Windows games, though gaming is not its primary focus. Still, if a game runs successfully in Wine, then Wine is probably the best way to play it. It is usually a fairly straightforward matter to install and play games in Wine, not to mention the fact that Wine itself is free and open source software.
Still, there are other game-playing solutions for Linux that may often produce better results. That is certainly the case when it comes to classic, DOS-based games. For these, DOSBox (http://dosbox.sourceforge.net) is your best bet. DOSBox is a free and open source x86 and DOS emulator that runs on multiple platforms (including modern versions of Windows and Mac OS X, as well as Linux). It is especially good with older games.
Run Blasts from the Past
DOSBox is included in Ubuntu's universe repository [Hack #60], and it is generally up-to-date. So you can simply install it by running:
$ sudo apt-get install dosbox
or using Synaptic [Hack #55] or Adept [Hack #56]. In either case, the SDL multimedia library dependencies will also be installed. After you've installed DOSBox, you'll need to create a new directory in your home directory and name it something like dosgames. This is, of course, where you'll install those DOS classics you remember so fondly. Let's download and install a game to use with DOSBox; you'll find almost all the classic DOS games at the Abandonia site (http://www.abandonia.com).
I chose a true all-time classic, the original Tetris (http://www.abandonia.com/games/en/69/Tetris.htm), and made a directory for it (dosgames/Tetris). Then I unzipped the Tetris download into the dosgames/Tetris directory. To launch DOSBox, you just type dosbox in Terminal.
Doing so brings up the DOSBox shell (shown in Figure 9-9), where you can enter various DOS commands and launch your games. The DOSBox shell opens in the Z directory by default, so you will need to mount the C directory, which contains your games. You can do so within the DOSBox shell by typing:
Z:> mount c /home /username/dosgames
where username is your username and dosgames is whatever you named the directory that contains your DOSBox games. After you've mounted the C directory, you can switch to it simply by typing c: within the shell.
Now that you're in the C directory, type dir to have a look at its contents. (See the DOSBox Wiki at http://dosbox.sourceforge.net/wiki/index.php?page=DOSBoxWiki for a DOS command reference and other useful information.) If you've installed Tetris, you should see a line like this:
TETRIS <DIR> 15-03-2006 14:14
which simply tells you that TETRIS is a directory, and gives you the time and date of its installation. Inside the TETRIS directory (change to it by typing cd tetris, and then look inside with dir), you'll see one file: Tetris.com. (DOS executable files have one of three extensions—.exe, .com, or .bat.) You can launch the game by typing tetris.com. (You can also launch the game by typing TETRIS.COM—don't worry about case sensitivity.) Figure 9-10 shows the game in action.
There are a few basic commands you can access if you need:
- Ctrl-F7 decreases frameskip.
- Ctrl-F8 increases frameskip.
- Ctrl-F11 slows down the game.
- Ctrl-F12 speeds up the game.
When you've finished your game, type z: at the prompt and press Enter. This takes you back to the Z:> prompt, where you can type exit to quit the DOSBox shell.
You're not limited to antique classics like Tetris when you use DOSBox; many more graphically advanced games are available as well. Abandonia, in addition to its very wide selection of games, is also valuable for its compatibility ratings; you can see at a glance whether an older game is compatible with DOSBox (most are). And many collections of DOS games are available on CD-ROM, including classic role-playing games such as Wizardry and Might and Magic, as well as classic text adventures from Infocom. Some of these collections are easy to find in the $9.99 bin at your local computer store. Others are a bit harder to find, so you might have to check eBay.
Run Current Windows Games with Cedega
Cedega (http://www.transgaming.com) is a commercial version of Wine—commercial to a fault, some would say. Cedega, formerly known as WineX, is basically a fork of Wine that has gone proprietary. This has generated some resistance among free software fans, and you won't find Cedega in the Ubuntu repositories. But if you're a gamer, you'll want Cedega anyway; it's generally regarded as the best way to run recent Windows titles on Linux.
Cedega costs $5 per month, and you have to pay the first three months up front. However, there is a fully functional, two-week trial version available. I recommend you start with that; if you like it, you can convert to the paid version from the trial.
You can download the Cedega Time Demo from http://www.transgaming.com/products_linux.php. You'll find the download link near the bottom of the page, and you'll find system requirements and installation information at http://downloads.transgaming.com/files/timedemo_howto.html. Pay particular attention to the video-card requirements: Cedega won't be worth your subscription cost if your system isn't up to handling current games. NVIDIA GeForce or ATI Radeon class cards are pretty much the minimum requirement; pixel shaders are only available on NVIDIA FX class cards and above. ATI Radeon 8500 or better cards will also work, but only with proprietary ATI drivers. Intel and other cards may be able to drive some games, but probably not most.
To install the Cedega Time Demo, run the installation script with this command:
$ sh /PATH_TO_INSTALLER/ cedega_timedemo_installer
Note that the preceding command will install the Time Demo in your user directory. If you'd prefer a system-wide installation, then run the preceding command as root.
The installer will check for updates and then ask whether you want to install the Microsoft Core Fonts and the MozControl package. You must agree to the licenses for each before they are downloaded as part of the install.
The TransGaming people will email you a registration key, which you'll need to enter during the process of installing Cedega. Figure 9-11 shows the Cedega registration process.
Finally, before you play your first game with Cedega, a wizard will walk you through tests of various facets of your system. If your computer can't pass the OpenGL Direct Rendering and 3D Acceleration tests, in particular, Cedega is not going to run many games.
After installation, you can launch the Cedega Time Demo by entering:
in a Terminal. This brings up Cedega's graphical interface (see Figure 9-12).
In Cedega, almost everything can be done via the GUI. There are command-line options too, though. You can read about these options and other Cedega usage tips on the Cedega How-To Guide page at http://downloads.transgaming.com/files/Cedega-How-To-5.0.0-2.html. Note that the Cedega Time Demo is actually the same as the full subscription version, currently 5.1.
To install a game with Cedega, just click the Install button and then browse to and run the installer. You can download games from a wide variety of sources (e.g., Download.com), and you can even mix and match the original Windows .pak files from CDs with open source game binaries for games like Quake I, II, or III. You can also install demos to try a game before installing the full version (see Figure 9-13), but note that there can often be significant differences between the demo and the full game; both may not run. TransGaming has an extensive games database (http://transgaming.org/gamesdb/) you can consult.
As noted earlier, you'll want the best graphics setup possible to take maximum advantage of Cedega and today's Windows titles. But Cedega (and Wine as well) can run some games even on underpowered machines—a title such as Delta Force 2 being a case in point (see Figure 9-14).
Cedega, in spite of its licensing and cost issues, is regarded by many as the best way to run current Windows games on Linux. For hardcore gamers, that alone is enough to recommend it. Just be sure your system is suitably equipped, and also make sure you have the time and inclination to tweak your system to get the most out of Cedega, and today's games. Sometimes a game will run "out of the box," but sometimes it won't. For many gamers, getting such games to work is part of the fun.
Run Google Earth with Wine
Modern games aren't the only visually advanced Windows applications that can be challenging to run on Linux. Because it relies on DirectX and OpenGL, a sophisticated application like Google Earth poses similar issues, and there are similar rewards for those who can get it to run.
A HOWTO for Gentoo users for installing Google Earth with Wine was published at http://gentoo-wiki.com/HOWTO_Install_GoogleEarth_with_wine, and I was able to adapt these instructions for an Ubuntu PC. Your mileage may vary: chances are some additional tweaking will be required, depending on your computer's exact configuration. But you can use the following instructions as a starting point, and, if you're lucky, they'll be all that is needed. First, of course, you must install Wine [Hack #87].
Next, you need to install the Microsoft DCOM98 (Distributed Component Object Model for Windows 98). First, run winecfg and set the Windows version to Windows 98. Then, you can download DCOM98 from here: http:// download.microsoft.com/download/d/1/3/d13cd456-f0cf-4fb2-a17f-20afc79f8a51/ DCOM98.EXE (or just search for the link on Google; it's probably faster!). Now, install DCOM98 with a WINEDLLOVERRIDE, specifically:
$ WINEDLLOVERRIDES="ole32=n" wine DCOM98.EXE
After you have DCOM98 installed, download the psapi.dll from http://www.dll-files.com/dllindex/pop.php?psapi and place the DLL in your ~/.wine/drive_c/windows/system32 directory.
Downloading these DLLs from untrusted sources can be quite dangerous, since you have no way of knowing that they have not been compromised (for example, they could be harboring a Trojan horse). The safest option is to copy them over from a working Windows system that has recently been checked for spyware, viruses, and other malware.
Next, download Google Earth from http://earth.google.com. Before you do so, though, run winecfg again and set the Windows version to Windows XP. Also, before you install Google Earth, make sure you download the usp10.dll (Google for the download location); place this in the ~/.wine/drive_c/windows/system32 directory as well.
Now, install Google Earth like so:
$ WINEDLLOVERRIDES="ole32,oleaut32,rpcrt4=n" wine GoogleEarth.exe
After you've managed to install Google Earth, you reach the moment of truth: it's time to run it. Here's the command I used:
$ WINEDLLOVERRIDES="ole32,usp10,msvcrt=n" \\ wine "c:\\Program Files\\Google\\Google Earth\\GoogleEarth.exe"
This should work (see Figure 9-15). However, it might not work on your system, and therein lies the challenge. (If you do run into trouble getting it to work, be sure to check the HOWTO mentioned earlier in this section.) Getting Google Earth to run on Ubuntu or any Linux system is a worthy hack, and tools like Wine (along with DOSBox and Cedega, for vintage and state-of-the-art games) make it possible.
Run Ubuntu Inside Windows
If you want to avoid the confines of the emulator sandbox, give coLinux a whirl and run Ubuntu as a cooperative process alongside Windows.
coLinux (Cooperative Linux), available from http://www.colinux.org/, takes a unique approach to solving the same problems that emulators do. Instead of providing a completely enclosed sandbox like Virtual PC or VMware, it's a port of the Linux kernel that lets you run Linux alongside Windows. This means that you don't get a fully emulated and/or virtualized PC environment. But you do get enough to launch a Linux distribution in console mode with networking support, and from there you can use ssh to tunnel into the coLinux system and run applications on your Windows X11 server. You can get a great, free X11 setup with Cygwin (http://www.cygwin.com), a Windows port of many Linux tools and applications. With the combination of coLinux and Cygwin, you can get Ubuntu running alongside Windows, and without the overhead and complexity of other offerings, it runs quite fast.
To get Ubuntu up and running with coLinux, you'll first need to install coLinux itself and choose the minimal Debian disk image that comes along with it. With some apt-get trickery, you'll be able to turn that Debian installation into an Ubuntu system.
Download the latest installer from the coLinux web site, and run it under Windows. If you don't have WinPcap (http://winpcap.mirror.ethereal.com/install/default.htm) installed, you should download and install it (don't worry, the coLinux installer will remind you about this, too).
When you run the installer, it will try to install coLinux into C:\\Program Files\\coLinux. You should change this to C:\\coLinux, because the default configuration files expect to find it there. Plus, paths without spaces make everyone happier.
When you're prompted to choose a Linux distribution, select the Debian installer. This will download a small compressed file that you'll later expand to about 1 GB. Sometime during the install, you'll get a Windows Logo compatibility-testing error message about the TAP-Win32 adapter, which is necessary if you want to use networking, so you'll need to click Continue Anyway and let Windows install it.
When installation is finished, you'll be offered the opportunity to look at the README file. I know you would normally never do this, but with software that's this complicated, I think you should.
Set Up the Debian Image
Now that coLinux is installed, there are a few more steps to get it configured. By now, I hope you've installed Cygwin, since you'll need to use some of the utilities from it to get things set up nicely. If not, go install it now and, when you're ready, open a Windows command prompt, then cd to the C:\\coLinux directory. You'll need to expand the filesystem image you downloaded. It's probably compressed with bzip, so you should use the bunzip2 utility from Cygwin to decompress it:
Consider backing up this file before you unzip it, just in case you make a horrible error while you are hacking it and want to start out with a fresh image.
Next, you'll need to create a swapfile. Cygwin's dd is fine for this purpose. Windows has a utility called fsutil that can also create it, so either of these commands will create a 512 MB swapfile:
> fsutil file createnew swap_device 536870912 > c:\\cygwin\\bin\\dd if=/dev/zero of=swap_device bs=1M count=512
Now you need to work on the configuration file. Copy default.colinux.xml to colinux.xml and open colinux.xml in your favorite text editor.
Edit this file and make sure the paths to your filesystem image (default is root_fs) and swap device (default is swap_device) are correct. Bump up your memory size to whatever you feel comfortable setting aside (256 MB is good, assuming you have more than 512 MB of memory and don't plan to do something memory-intensive while your coLinux system is running).
Now it's time to get the network connection set up. Go to Control Panel→Network Connections and locate the TAP-Win32 adapter, highlighted in Figure 9-16. Change its name if you'd like (the default will be something like "Local Area Connection 5"), and add its name to the network entry in colinux.xml.
Now you need to share your Internet connection. Locate your Internet connection in the Network Connections window, right-click on it, and select Properties. Go to the Advanced tab, click "Allow other network users to connect through this computer's Internet connection," and select the TAP adapter in the "Home networking connection" drop-down menu, as shown in Figure 9-17.
In Windows 2000, you will need to first boot up coLinux; then select your Local Area Connection, select the Properties tab, and choose "Enable Internet Connection Sharing for this Connection." This is because Windows 2000 won't let you enable sharing unless the Tap interface is live at the time.
Next, return to the Command Prompt and start colinux as a standalone process. You can run it as a daemon, but it's easier to debug this way. The -t NT option uses the Windows command prompt as the console, for easier cutting and pasting, and the -c option specifies the configuration filename:
C:\\coLinux>colinux-daemon.exe -t NT -c colinux.xml Cooperative Linux Daemon, 0.6.3 Compiled on Sun Feb 5 20:25:03 2006 Linux version 2.6.11-co-0.6.3 (george@CoDebianDevel) (gcc version 3.4.4 20050314 (prerelease) (Debian 3.4.3-13)) #1 Sun 384MB LOWMEM available. initrd enabled: start: 0xd7e10000 size: 0x001ef78a) On node 0 totalpages: 98304
You'll see the usual messages scroll by until you get a login prompt. Log in as root, with the password root. At this point, networking won't be working, since there are some hardcoded (and incorrect) values in /etc/network/interfaces. Run the command pump -i eth0 and check the output of ifconfig to see if you got an IP address from Windows connection sharing. If so, you can edit (you may want to do an apt-get update and then apt-get install vim or apt-get install emacs) /etc/network/interfaces and replace:
iface eth0 inet static address 192.168.254.205 netmask 255.255.255.0 gateway 192.168.254.1
iface eth0 inet dhcp
If you want the same address each time, you should instead replace 192.168.254.205 with the address you got from pump. As long as you're not running multiple coLinux instances, you'll never need to worry about IP address collisions. If you are running multiple instances, you can always choose IP addresses in the 192.168.0.0/24 that don't conflict.
At this point, you can issue the command halt inside of the coLinux distribution to shut down, start up coLinux again, and verify that networking is configured correctly on boot. Now you're ready to install Ubuntu.
If your real network uses the same address range as that used by Windows (192.268.0.0/24), you'll have problems. If this happens, you'll need to change your physical network to use a different range of addresses.
It's pretty easy to turn Debian into Ubuntu, but for the smoothest transition, you should make sure you've got the latest and greatest Debian system, so do an apt-get update; apt-get upgrade. You also need to update a few things to make sure your system has the necessary versions to install Ubuntu. This should do the trick:
$ sudo apt-get install sed locales
For another (not quite as quick-and-dirty) approach to converting Debian to Ubuntu, see "Convert Debian to Ubuntu" [Hack #66].
Next, edit /etc/apt/sources.list, delete everything in there, and insert the following lines:
deb http://archive.ubuntu.com/ubuntu dapper main restricted deb-src http://archive.ubuntu.com/ubuntu dapper main restricted deb http://archive.ubuntu.com/ubuntu dapper-updates main restricted deb-src http://archive.ubuntu.com/ubuntu dapper-updates main restricted deb http://security.ubuntu.com/ubuntu dapper-security main restricted deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted
Now, it should theoretically be smooth sailing from here, but it probably won't be. To kick off the update, run apt-get update and then apt-get dist-upgrade.
If you see a message about configuring LILO, you can ignore it. coLinux doesn't use it.
During the upgrade, you will almost certainly get this error:
E: This installation run will require temporarily removing the essential package e2fsprogs due to a Conflicts/Pre-Depends loop. This is often bad, but if you re ally want to do it, activate the APT::Force-LoopBreak option. E: Internal Error, Could not early remove e2fsprogs
If so, add -o "APT::Force-Loopbreak=true" to the apt-get dist-upgrade command line, as in:
$ sudo apt-get -o "APT::Force-Loopbreak=true" dist-upgrade
If you continue to get errors, run this command to clear things up:
$ sudo apt-get -o "APT::Force-Loopbreak=true" -f install
Then, run the apt-get dist-upgrade command again, and it should run to completion.
When it's done, you must apt-get install ubuntu-keyring so that apt-getcan verify package signatures. Now you can start apt-getting what you need. Pick out some high-level applications, since this will pull in a lot of other dependencies. I'd suggest something like:
$ sudo apt-get install firefox openoffice.org2 gnome-games
Do what you can to prevent Ubuntu from installing an X server, since that can only complicate things.
If you'd rather not work in the coLinux console, you can SSH in to your coLinux system. First, run apt-get install ssh, then use ifconfig eth0 to determine your IP address, which will be on the private network that Windows assigned for Internet connection sharing, such as 192.168.0.143. Fire up PuTTY or openssh (available in Cygwin) to connect to that IP address. If you're using Cygwin, you may need to set your TERM to something other than cygwin, such as ansi:
bjepson@thlon ~ $ ssh email@example.com Password: Last login: Fri Mar 3 23:00:31 2006 from thlon.mshome.net Linux colinux 2.6.10-co-0.6.2 #5 Sat Feb 5 10:19:16 IST 2005 i686 GNU/Linux The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. colinux:~#
Running X11 Applications
To run any X11 applications, you'll need to ssh -X into your coLinux system from within the Cygwin X11 environment and launch applications from there. (You will probably need to enable X11Forwarding in Ubuntu's /etc/ssh/sshd_config and restart sshd with /etc/init.d/sshd restart to get this working. You'll need to apt-get xauth as well.)
Now you're ready to start playing. Run the adduser username command to add a mortal user, and then you can log out as root.
Next, start up a Cygwin shell on the Windows system, and run the Cygwin X server with the command startxwin.sh. When the xterm appears, use ssh -X IP_ADDRESS to log in to your coLinux system. Replace IP_ADDRESS with either the fixed private network address you assigned it or the latest one it got from DHCP (use ifconfig in the Ubuntu system to find this out). Once you're logged in, you can start running your favorite programs (see Figure 9-18)!
If you get the error "xterm Xt error: Can't open display: xterm: DISPLAY is not set," you should log out, and try ssh -X again, but with the -v option, which gives you verbose details on your connection attempt and should shed light on the situation. For example, if you see an error related to xauth, that means you need to apt-get xauth on the coLinux Ubuntu system.
Use Xen to Host Virtual Machines
Use Ubuntu as a deployment platform for multiple virtual machines.
A virtual machine (VM) is a simulated computer-inside-a-computer, allowing you to boot an entire extra operating system inside your primary environment. You may already be familiar with the concept of emulation: booting Microsoft Windows within your Linux machine using VMware [Hack #92], running an arcade-game emulator such as MAME on your computer so you can play old-style console games on your PC, or using Virtual PC on a Macintosh to allow it to run Windows programs.
These systems generally work by using both software that pretends to be hardware (emulation) and software that encapsulates and grants access to physical devices (virtualization). So, in practice, what we commonly think of as an emulator is actually a combination of emulation and virtualization. For example, if you're running an x86 emulator on an x86 system, the CPU certainly doesn't need to be emulated (so it's virtualized), but other devices, such as network adapters, may be emulated. For performance reasons, a virtualization environment such as VMware will emulate as little as possible and virtualize everything it can.
This scheme allows an application designed for the target hardware to run unmodified. The application itself probably won't be able to tell the difference: it just thinks it's running on whatever hardware is being emulated and virtualized by the host system.
While this approach can be applied to single applications, it can even be applied to entire operating systems: it's possible to boot an entire extra copy of Ubuntu, for example, right inside the copy you already have running. The extra copy is a complete, self-contained virtual computer with its own IP address, kernel, users, and applications. Mainframe systems have been doing this for decades, with many virtual machines running simultaneously under the management of a hypervisor. By taking this approach, the primary operating system running directly on the hardware can be relatively simple since it doesn't need to provide any end-user services or applications itself. All it needs to do is run the hypervisor to manage the child operating systems and provide a stable environment on which they can run.
The benefit of this approach is that the core system itself can be extremely stable, secure, and reliable, allowing mainframes to run for years or decades without any downtime at all. Once the parent OS has been installed and configured, it can be left running indefinitely and be almost immune to hackers and other external threats by being completely segregated from the network. Then any applications or services that need to be provided to end users can be installed within a virtual machine that can be backed up easily and "rebooted" at any time without affecting the underlying hardware or any other virtual machines that happen to be running alongside it. Separating services into different virtual machines is a great way to limit the impact of security problems, since a compromised web server running on one virtual machine does not give the attackers any access to mail services running in a different virtual machine, even if they're on the same physical server.
Other advantages of this setup include rapid backups, versioning, and rollbacks; live migration of running services to another host; rapid provisioning of new services; segregated system administration; and support for multiple runtime environments running simultaneously on one server.
This technology has now started to filter down to Linux in a number of forms, including UML (User Mode Linux), VMware, and Xen. This hack focuses on Xen, a project to implement a mainframe-style hypervisor within a Linux environment, giving Linux much of the power and flexibility of the older Unix systems that inspired it. Xen's approach to virtualization is to provide a virtual architecture to which the Linux kernel can be ported. In just the same way that Linux is supported on architectures such as ia32 (386), ia64, PowerPC, AMD64, and many others, Xen defines an architecture for which the kernel can be compiled. This virtual architecture is provided by a special kernel that runs on the host machine, and virtual machines that execute on it run an otherwise unmodified kernel that has been compiled for the Xen architecture.
The host machine is generally referred to as dom0, and guest virtual machines that run on it are referred to as domU machines.
Initial Host Installation
The whole idea of virtualization is to run the dom0 base system in a totally cut-down form with as little installed as possible. The less you have in the base system, the less there is that can go wrong. With an extremely stable base system, you can then run all your services in virtual machines.
Start by doing a clean install of Ubuntu in server mode [Hack #93] so you have as little cruft on your system as possible.
Base Packages Required by Xen
To run Xen and provide networking services to virtual machines, you will need to install a number of packages:
$ sudo apt-get install grub bridge-utils iproute python \\ python-twisted gcc libcurl3 libcurl3-dev zlib1g zlib1g-dev
Obtain Xen3 Binary Distribution
While you can apply the Xen patches and build a kernel [Hack #78], the simpler approach for now is to just grab the latest prebuilt binaries from the Xen project and install them using the provided installer. To reduce load on the Xen project infrastructure, the developers request that P2P systems such as BitTorrent be used to fetch the binaries where possible, but if you submit your email address, they will also provide you with a direct download link if you prefer. Visit http://www.xensource.com/xen/downloads for more information. For Ubuntu, the item you need to download is the Xen 3.0 Tarball. (Even if you're on a single-processor system, it's OK to download the one marked 32-bit SMP.)
Extract Binary Distribution
Once you've downloaded the binary distribution, just unpack it and run the provided install script:
$ tar zxf xen-3.0.1-install-[arch].tgz $ cd xen-3.0.1-install $ sudo ./install.sh
The install script places a number of special kernels and initrd images in /boot, so assuming all went well you should now have quite a few extra items in there.
Configure GRUB Bootloader
GRUB is designed to automatically detect new kernels and autoconfigure them, but unfortunately it doesn't manage the Xen kernels in quite the right way, so you will need to make some manual adjustments. Start by updating the autogenerated kernel list:
$ sudo update-grub
You should see GRUB report your new Xen kernels in addition to any that were previously installed. Now open the GRUB configuration file (/boot/grub/menu.lst) in your favorite editor and look down near the bottom for all the autogenerated kernel definitions. You should find one that looks something like this:
title Ubuntu, kernel 2.6-xen0 root (hd0,0) kernel /boot/vmlinuz-2.6-xen0 root=/dev/hda1 ro quiet splash boot
To allow the Xen kernel to boot properly, the configuration stanza needs to be restructured. It's also a good idea to put the new stanza above the list of automagically detected kernels, so look for a line that reads:
### BEGIN AUTOMAGIC KERNELS LIST
and just before it, put in an entry using the same values as the autogenerated stanza but restructured to use a module line like the one shown here, and with the kernel line modified as shown:
title Ubuntu, kernel 2.6-xen0 static root (hd0,0) kernel /boot/xen-3.0.1.gz console=vga module /boot/vmlinuz-2.6-xen0 root=/dev/hda1 ro console=tty0 boot
The static entry in the title is just a label so that when GRUB displays a list of available kernels, you can tell which ones were added automagically and which one is your statically defined kernel.
Now tell GRUB to update its kernel list again, just to make sure you haven't made any mistakes:
$ sudo update-grub
Xen needs to start up a number of services at bootup, so set appropriate runlevel symlinks:
$ sudo update-rc.d xend defaults 20 21 $ sudo update-rc.d xendomains defaults 21 20
Virtual machines you run on your host will most likely need some way to make network connections. Obviously, they don't have actual Ethernet cards installed in their virtual motherboards, so the usual solution is to have the host machine provide a virtual "bridge" from its own networking stack to the guest system. Each guest virtual machine can then be assigned its own IP address and even a virtual MAC address, with packets passing through the virtual bridge, into the host networking stack, and finally out the host's Ethernet card and onto the real network.
To keep everything as secure as possible, it's also a good idea to implement firewalling within the dom0 host to prevent external machines attacking the domU guests.
Install the packages required to provide network connectivity and network-management services to the guest operating systems:
$ sudo apt-get install iproute bridge-utils screen ssh
Disable TLS Libraries
The standard Thread Local Storage (TLS) library is incompatible with the Xen kernel, so it's necessary to either disable the library or replace it with a special Xen-friendly version before attempting to reboot with the Xen kernel. Otherwise, an emulation mode is used within Xen that reduces performance considerably.
The simplest solution for now is to move the library aside so it's not available when the host reboots:
$ sudo mv /lib/tls /lib/tls.disabled
If necessary, you can always move it back later if you need it for a non-Xen kernel.
For running heavily threaded code, you may prefer to install a nosegneg (no segmentation negotiation) version of the library.
You should now be ready to reboot your dom0 host with the Xen kernel, so sudo reboot and make sure GRUB loads the correct kernel when it restarts. You can also double-check the kernel version once the machine has finished booting:
$ uname -r 188.8.131.52-xen0
Your dom0 machine is now ready to host guest domU virtual machines, so either download a pre-prepared image or create your own [Hack #91].
Create an Ubuntu/Xen Virtual Machine
Install Ubuntu into a virtual-machine image and boot it using Xen.
The previous hack showed you how to set up a Xen server [Hack #90]. To make use of your newly Xen-enabled host, you need to create some domU virtual machines to run on it. In this hack, you'll set up a basic Dapper virtual machine (VM).
Prepare VM Filesystems
The VM needs both root and swap filesystems. In a production environment, these would most likely be stored on some form of shared-access filesystem, such as a SAN or similar, but, to keep things simple, for now you should create them as loopback disk images on the local disk. So start by making a couple of directories to store them in:
$ sudo mkdir -p /vm/vm_base $ sudo mkdir /vm/images
The root filesystem will be a 2 GB image, so first use dd to create a disk image and then use mkfs to set up a filesystem in it. 2 GB should be enough space for initial testing, but if you want to vary the size, just change the count argument, which, when multiplied by the bs (block size) argument, determines the total disk size.
While mkfs is running, it will complain that vm_base.img is not a special block device and ask if you want to proceed anyway. Say y:
$ sudo dd if=/dev/zero of=/vm/images/vm_base.img bs=1024k count=2000 $ sudo mkfs.ext3 /vm/images/vm_base.img
You can create a 200 MB swap image in a similar way:
$ sudo dd if=/dev/zero of=/vm/images/vm_base-swap.img bs=1024k count=200 $ sudo mkswap /vm/images/vm_base-swap.img
Mount the root filesystem image
Mount the root filesystem image as a loopback device, allowing it to appear as a separate volume, even though it's only an image stored on the local disk:
$ sudo mount -o loop /vm/images/vm_base.img /vm/vm_base
Install Ubuntu into the Root Filesystem
Now you have the equivalent of a blank disk just waiting to have Linux installed on it. The system you install will become the domU virtual machine that is booted by Xen. Installing into a different volume can be a tricky exercise, but luckily Debian provides an extremely useful tool called debootstrap that takes care of all the hard work for you. First, grab debootstrap:
$ sudo apt-get install debootstrap
Then, use it to build a new Breezy base system into the root filesystem. The installation process has been radically overhauled for Dapper, so for now it's easier to install Breezy first and dist-upgrade to Dapper afterwards:
$ sudo debootstrap --arch i386 breezy /vm/vm_base/ \\ http://archive.ubuntu.com/ubuntu
If you're wondering why you're installing Breezy, it's because base-config no longer exists in Dapper (the install process has been largely rewritten into a single-stage system, and we haven't yet figured out exactly how the initial configuration takes place). A simple workaround is to do a Breezy bootstrap and then update it to Dapper.
The preceding example specifies the architecture as i386 (32-bit Intel). You may need to specify an alternative, such as powerpc or amd64, depending on your system architecture.
Running debootstrap can take quite a long time because it needs to download all the packages, and if you need to go through this process several times, you may want to set up a local package cache [Hack #61] or replace the mirror address with a reference to file:///media/cdrom and use an Ubuntu install CD. If you have a local apt-cacher running already, you can include the cache address like so:
$ sudo debootstrap --arch i386 breezy /vm/vm_base/ \\ http://localhost/apt-cacher/archive.ubuntu.com/ubuntu
Configure the Virtual Machine
At this point, you have a basic Ubuntu install, but it's totally unconfigured. If your host machine is running Ubuntu, you can save yourself some effort by copying in your /etc/apt/sources.list file:
$ sudo cp -a /etc/apt/sources.list /vm/vm_base/etc/apt/
Then edit /vm/vm_base/etc/apt/sources.list and change any references from dapper to breezy, since you are starting with a base Breezy install.
Now edit /vm/vm_base/etc/network/interfaces and set up the loopback address and a virtual eth0 interface. You will need to adjust these values to suit your own network. The address allocated to eth0 needs to be one that's not in use yet:
auto lo iface lo inet loopback address 127.0.0.1 netmask 255.0.0.0 auto eth0 iface eth0 inet static address 192.168.0.101 netmask 255.255.255.0 gateway 192.168.0.1
Edit /vm/vm_base/etc/hostname and set it to vm01.
Edit /vm/vm_base/etc/hosts and put in some basic entries:
127.0.0.1 localhost.localdomain localhost vm01 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
The VM also needs to be given a filesystem configuration. Note that this is not necessarily the same as the configuration of the host, and the volume names have nothing to do with your actual local disk. The volumes that the VM will see when it starts up are virtual volumes that will be determined by the Xen configuration, so for now just edit /vm/vm_base/etc/fstab and set it up like this:
/dev/hda1 / ext3 defaults 1 2 /dev/hda5 none swap sw 0 0 /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0
Run Setup Within the VM Image
Use chroot to switch into the root of the VM filesystem:
$ sudo chroot /vm/vm_base
From now on, everything you do will be within the context of the VM, so you can manually invoke the tools that are normally run in the last stages of the regular Ubuntu installer. Make sure the universe repository [Hack #60] is enabled in sources.list (Breezy has a universe repository as well), and tell apt to update the package list and then set up locales:
# apt-get update # apt-get install localeconf # dpkg-reconfigure localeconf
You will then be asked a series of questions when the localeconf package is installed and then additional questions when you reconfigure it:
- Manage locale configuration files with debconf?
- Answer Yes.
- Replace existing locale configuration files?
- Answer Yes.
- Default system locale
- Select the applicable default, such as en_US ISO-8859-1.
- Environment settings that should override the default locale
- Don't select any options; just select OK to proceed.
At this point, many of the standard devices don't exist and locale generation won't be working, so mount the proc virtual filesystem and create the default devices:
# mount -t proc proc /proc # cd /dev # ./MAKEDEV generic
When MAKEDEV finishes, run base-config to bootstrap the system:
base-config will ask you all the usual questions that you normally see when running the Ubuntu Breezy installer, so answer all the questions as normal, with one exception: when asked to specify an access method for apt, select "edit sources list by hand," which will then put you into the vim editor with the sources.list file open. Since it's already set up correctly, just type ZZ to save and exit vim, and let apt run through the process of verifying the repositories and installing all the base packages.
Once the Breezy installer has finished, edit the /etc/apt/sources.list again, and this time change all references from breezy to dapper. Then update the package list again and dist-upgrade to Dapper:
# apt-get update # apt-get dist-upgrade
You now have a basic Dapper install inside the loopback filesystem, so finally you can exit the chroot:
Get Ready to Crank Up the VM
The domU virtual machine will be booted using the Xen kernel installed on the dom0 host, so copy the kernel modules into its filesystem, disable TLS, and unmount the image:
$ sudo cp -dpR /lib/modules/184.108.40.206-xenU /vm/vm_base/lib/modules/ $ sudo mv /vm/vm_base/lib/tls /vm/vm_base/lib/tls.disabled $ sudo umount /vm/vm_base
It's quite likely that umount will complain that the device is busy even though nothing is using it anymore, so ignore the warning.
You now have one complete, functional domU virtual machine, but it's quite likely that you will ultimately want to create a few of them, so rather than boot the image you just created, it's best to treat it as a template and make copies of it to play with.
Copy the disk image to create a new VM:
$ sudo cp -a /vm/images/vm_base.img /vm/images/vm01.img $ sudo cp -a /vm/images/vm_base-swap.img /vm/images/vm01-swap.img
Configure the VM in Xen
You need to create a configuration file for each domU virtual machine so that Xen will know how to boot it. Start by copying the sample configuration file into place:
$ sudo cp /etc/xen/xmexample1 /etc/xen/vm01.conf
The sample config file is very well commented, and most of the defaults are fine as a starting point, so open /etc/xen/vm01.conf in your favorite editor and start working through it. Highlights to pay attention to include:
- The kernel parameter specifies the path to the domU kernel in the host system. Note that the dom0 and domU kernels are almost identical, so you can use the dom0 kernel image to boot the domU guest if you prefer. The domU kernel is basically just the dom0 kernel, but with most of the modules stripped out because networking and many other services are supplied by the dom0 host and the virtual machine doesn't need to manage such things itself. This makes the domU kernel about 30 percent smaller than the dom0 kernel.
- The dom0 host preallocates RAM to each virtual machine using the memory parameter in the config file, so set it to some sensible value to start with, such as 128. You need to make sure you leave enough memory for the dom0 host after all the domU guests have claimed their allocated address space; so if, for example, you have 512 MB RAM in the host, you could run three guests with 128 MB allocated each and still have 128 MB available for the host.
- Each domU host needs a unique name that will be used to identify it. Set it to vm01 for now.
- Virtual network interfaces
- You can specify virtual network interface settings directly in the config file or leave a blank value to have the guest specify its own settings. For now, just leave this blank because you configured a virtual eth0 interface earlier: vif = [ '' ].
- The dom0 host exposes real filesystems to the domU guest as if they were real filesystems, so the disk parameter allows you to specify what will be seen by the guest. For now, you should use the loopback disk images that were created earlier, so if you set up the guest's /etc/fstab in the way suggested earlier, you should set the disk parameter to:
disk = [ 'file:/vm/images/vm01.img,hda1,w','file:/vm/images/vm01-swap. ⏎ img,hda5,w' ]
The disk images don't have to be mounted: the file argument tells Xen that it has to treat the target as a loopback disk image, and takes care of everything for you.
Boot Your Virtual Machine
Virtual machines are managed using xm, the Xen Manager, which allows you to boot, shut down, list, and migrate them to other physical hosts. Start up your newly created VM:
$ sudo xm create -c /etc/xen/vm01.conf
If all goes well, you will see Linux run through its boot sequence all the way up to a login prompt into your virtual machine. Log in as the user you created during the setup process and poke around. Try a few things like:
$ cat /proc/cpuinfo $ cat /proc/meminfo $ uname -r
It should look exactly as if you're in a totally separate machine, and the network interface will be functional, with packets bridged to the physical Ethernet through the kernel in the dom0 host so you can even apt-get install some packages or do whatever else you need to do to set up the virtual machine just the way you want it.
While your virtual machine is still running, open another terminal session onto the dom0 host and try running:
$ sudo xm list
to see a list of currently running guests. You can also view a dynamically updated list of hosts along with resource utilization:
$ sudo xm top
If you want to nicely bring down a VM without logging in to it, you can do so through xm:
$ sudo xm shutdown vm01
When you've finished playing around in your new VM, you can either shut it down from the dom0 host using xm or shut it down from inside just like any other machine using sudo shutdown.
Create Additional Guests
To create additional guests, you need to repeat a number of the previous steps. Copy the templates again:
$ sudo cp -a /vm/images/vm_base.img /vm/images/vm02.img $ sudo cp -a /vm/images/vm_base-swap.img /vm/images/vm02-swap.img
Mount the base image:
$ sudo mount -o loop /vm/images/vm02.img /vm/vm_base
Edit /vm/vm_base/etc/network/interfaces, /vm/vm_base/etc/network/hostname, and /vm/vm_base/etc/network/hosts to set appropriate values for the hostname and IP address.
Unmount the base image:
$ sudo umount /vm/vm_base
Copy the Xen configuration:
$ sudo cp /etc/xen/vm01.conf /etc/xen/vm02.conf
Then edit it to change the paths to the disk images and the machine name, and you're ready to start up a second VM.
Split Your Machine's Personality
Give your machine split personalities by installing VMware Server, and get some virtual machines running.
Virtualization is one of the current buzzwords in the computer industry. Virtualization is where a thin software layer is installed on a computer that allows its processor and other resources to be split among several virtual machines (VMs). This allows the computer operator to run several different operating systems underneath this virtualization layer. Each virtual machine has its own set of resources and operates independently from any other virtual machines that may be running at the same time.
VMware (http://www.vmware.com) is one of the oldest companies in the virtualization business. It has had a Linux-based product lineup available for some time, both in the personal computer space (its Workstation product) and the server space (GSX and ESX server). Recently, however, VMware has released two new free (as in beer) products: VMware Player (http://www.vmware.com/products/player/) and VMware Server (http://www.vmware.com/products/server/). The VMware Player product allows you to "play," or use, a premade virtual machine. The VMware Server product is much more interesting, as it allows the creation of new virtual machines, and its modular, network-enabled console lets you control the virtual machines whether they're installed on your computer or another computer on the network.
VMware Server is like a Swiss army knife: its uses are limited only by your imagination. Need a particularly sticky Windows application working, but still want to run Linux? If it doesn't work in Wine [Hack #87], you can install VMware Server and run that application in a virtual machine. Want to test the latest Linux distribution but have only one computer? Install the new distro in a virtual machine and don't worry about your main system.
Installing VMware Server
VMware Server is really designed for use on a Red Hat-based Linux distribution, but it does work fine on Ubuntu. However, it requires that some packages be in place before installation, since it has to compile the VMware-specific kernel modules. VMware also has a dependency on inetd, if you want to remotely connect to your virtual machines from another computer on the network.
To install VMware, start by installing the build-essential and netkit-inetd packages. If you use the aptitude package manager, the additional recommended packages will get installed without any other intervention (be sure to replace linux-headers-386 with the appropriate package for your architecture, such as linux-headers-686 or linux-headers-k7):
bill@lexington:~$ sudo aptitude install build-essential \\ linux-headers-386 netkit-inetd
Next, get VMware Server from the download page (http://www.vmware.com/download/server/). You'll need to register on the site, and VMware will send you a serial number to activate your VMware Server installation. Ensure that you get the .tar.gz package, and not the rpm variant. Optionally, you can download the web interface and Windows console program separately. Once you've downloaded the package, untar it by running this command:
bill@lexington:~$ tar zxvf VMware-server-e.x.p-22088.tar.gz
Then start VMware installer and answer the questions it asks. In most cases, you can accept the defaults. At the end of the installer, you will be prompted for your serial number. This was emailed to you by VMware after you registered, so check your mail for it:
bill@lexington:~/vmware-server-distrib$ sudo ./vmware-install.pl Password: Creating a new installer database using the tar3 format. Installing the content of the package. In which directory do you want to install the binary files? [/usr/bin] What is the directory that contains the init directories (rc0.d/ to rc6.d/)? [/etc] What is the directory that contains the init scripts? [/etc/init.d] In which directory do you want to install the daemon files? [/usr/sbin] In which directory do you want to install the library files? [/usr/lib/vmware] The path "/usr/lib/vmware" does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? [yes] In which directory do you want to install the manual files? [/usr/share/man] In which directory do you want to install the documentation files? [/usr/share/doc/vmware] The path "/usr/share/doc/vmware" does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? [yes] The installation of VMware Server e.x.p build-22088 for Linux completed successfully. You can decide to remove this software from your system at any time by invoking the following command: "/usr/bin/vmware-uninstall.pl". Before running VMware Server for the first time, you need to configure it by invoking the following command: "/usr/bin/vmware-config.pl". Do you want this program to invoke the command for you now? [yes] ... lots of output truncated ... The configuration of VMware Server e.x.p build-22088 for Linux for this running kernel completed successfully.
See the VMware documentation for a detailed explanation of each installation and configuration option.
Running VMware Server
Once this process is over, the VMware installer will have added a VMware Server entry to your Applications→System Tools menu (see Figure 9-19). Click on this entry to start the VMware console.
The VMware console is where you will create, manage, and interact with your virtual machines. Once the console starts, it will ask you if you want to connect to your locally installed VMware Server instance or connect over the network to another VMware server. Select "Local host," as shown in Figure 9-20, and then click Connect.
Once you've successfully connected to the VMware Server, you'll be presented with a screen in the console with various options (see Figure 9-21). You're going to create a new virtual machine, so click "Create a new virtual machine."
The New Virtual Machine wizard will start up. Select Next to move past the splash screen. The wizard will ask you if you'd like to use a typical or custom virtual machine configuration; select Typical and click on Next. Now you get to the meat of the wizard: what type of operating system you'd like to install (see Figure 9-22). Select the guest OS family that you want to install in your new virtual machine and choose the version. Click Next to move on.
At this point, you'll be prompted to name the new virtual machine and select a location to store its files. The defaults are usually fine here, unless you'd like to name the system something more descriptive. When you've named your machine, click on Next, and you'll be asked to select the type of networking you want for your virtual machine (see Figure 9-23). There are several different types of network options: bridged networking, where your virtual machine will appear as another host on your LAN; network address translation, where your VM will be "firewalled" behind your host machine; and host-only, where your VM can communicate only with the host computer. In this example, you'll select "Bridged networking." Click on Next to continue.
The final screen, shown in Figure 9-24, lets you select how large you want the virtual machine's hard disk to be. We usually uncheck the "Allocate all disk space now" and "Split disk into 2GB files" boxes. If the "Allocate all disk space now" checkbox is selected, VMware Server will consume the amount of space specified in "Disk size" upon virtual-machine creation. If that box is unchecked, the virtual machine's disk will grow dynamically, so as you install the OS and add applications, the disk will gradually get larger. The only real reason to check that box is for performance reasons, as it is faster than dynamic allocation; otherwise, leave it unchecked. Click on Finish to complete the New Virtual Machine Wizard.
At this point, your virtual machine is ready to be powered up for the first time and begin its OS installation. You can perform any tweaking to the virtual machine in the console here, prior to OS installation. All the items in the right pane are clickable and adjustable, such as the amount of RAM you want to dedicate to the VM and what installation media or mount point you wish to use. One cool thing about the VMware console is that you can install your virtual machine from a CD in your server, a CD in your client, or straight from an .iso image (select VM→Removable Devices→CD-ROM 1→Edit). All those installation options really make life easy and give you options when you're installing a virtual machine.
All that remains at this point is to click the Power On button in the toolbar and watch your virtual machine boot for the first time. It will go through a virtual BIOS and POST check (see Figure 9-25), and then it'll begin installing from whatever boot media you selected. You'll need to click in the console window to "capture" your mouse and keyboard for use in VMware (to get back to your main OS, press Ctrl and Alt on your keyboard at the same time).
Once you start using VMware, you'll find new uses and ways to leverage virtual machines that you never thought possible. We've even used a virtual machine to kick-start other physical Linux boxes!