Get the Best of All Worlds with Virtual Machines

VirtualBox
Image via Wikipedia

Virtual machines are those fascinating bits of software that enable us to run several operating systems on one computer without using multiple hard disks, multiple partitions and duel or multi boot systems.

Virtual machines are handier for computer enthusiasts than ice is for an Eskimo. They allow us to

try multiple operating systems without wiping hard drives to install them;

try an application that doesn’t work on our favourite operating system;

share our computer between several people simultaneously by letting several operating systems use the same hardware; and

much, much more geeky and nerdy stuff that we like to do with our computers.

As I said, virtual machines are handy. They can even be used to emulate hardware that’s alien to the real machine they are running on.

It wasn’t until a couple of days ago that I rediscovered their usefulness. I’d used them before and thought “Wow, these are cool.” but I forgot about them. This time I’ve already installed 6 operating systems across 3 different virtual machine packages (I can tell you I like Slax and LinuxMint (a Kubuntu derivative with all the media trimmings). And, yes, they can be networked together.

When we use a virtual machine, the operating system that loads when a computer is switched on is called the host and any operating system that loads within the host is called a guest. Generally, a guest is blissfully unaware that it functions within a host’s environment and the host is unaware that any other operating system shares its hardware.

Virtual machines operate in one of two main ways:

1. they provide a conduit for guests to access a host’s hardware, or

2. they provide software emulated hardware for a guest to use.

I said “main ways” because my understanding is that many virtual machines provide guest operating systems with access to a combination of real hardware and software emulated hardware.

There are many different software that create virtual machines. Three of my favourite ones are

FAUMachine which lets users insert hardware and software faults into guest systems for testing purposes. It can emulate a machine’s physical environment also (e.g power switches) ,

QEmu which emulates a variety of computer architecture types so is excellent for trying software aimed at operating systems running on machines other than the host’s type,

VirtualBox which uses a host system’s hardware to allow a guest OS to function by allowing the it to directly access the host’s hardware.

VirtualBox is my favourite. It’s fast, very little performance drag due to a machine’s virtual nature, and once Guest Additions is installed it provides seamless integration between the guest OS and host OS.

If you need a more detailed explanation of virtual machines then you should visit this Wikipedia page.

From this point on I will show you how to create virtual machines using VirtualBox. This guide includes step-by-step instructions and videos that will teach you how to

Create a Virtual Machine with VirtualBox,

Change the Virtual Machine’s Settings,

Run the Virtual Machine and Install an Operating System,

Install Guest Additions,

Access Real Hard Disks, and

Automount Shared Media When a Guest OS Boots.

These instructions apply to both Windows and Linux hosts and are specifically for guest Linux operating systems.

You can download VirtualBox from here and Kubuntu Linux from here. There’ no real need to read the step-by-step instructions as the videos demonstrate everything needed to get a virtual machine up and running; only read the step-by-step instructions if you need additional information and tips.

Create a Virtual Machine with VirtualBox

VirtualBox has a very intuitive graphical interface which makes it really easy to use.

[wpvideo]http://journalxtra.com/videos/Creating-a-virtual-machine-with-VirtualBox.mp4[/wpvideo]

Create a Virtual Machine with VirtualBox

1. Open VirtualBox,

2. Click New at the top left hand side,

3. Click Next,

4. Type the name you would like to give your virtual system,

5. Select the Operating System and its Version so VirtualBox can suggest recommended environment settings for the guest OS. If you’re not sure of them select Other.

6. Press Next,

7. Choose the Base Memory Size. VirtualBox will recommend a size according to the operating system and version selected in step 5. The more memory the host system has the higher you can set this,

8. Click Next,

9. Choose to either create a new virtual hard disk or use a previously created one. If you intend to install an operating system as opposed to use a Live Disk then you will need a virtual disk of at least 8 GB (the more space you can spare the better). We will continue as though we are creating a new virtual disk.

10. Click Next,

11. Choose the type of disk to create. I usually use dynamic disks so that space unused by the guest will not impact on the space available to the host. For example, a 100 GB real hard disk space with a 100 GB virtual hard disk set up on it could work in one of two ways:

a. if the virtual disk is dynamic then the real disk will have almost 100 GB of free space available to the host minus whatever the guest requires of its virtual disk (if the the guest has used 5 GB then the host will have 95 GB); but,

b. if the guest hard disk is a fixed size then there will be no free space available for the host to use i.e the space will be completely taken by the virtual disk.

12. Click Next,

13. Choose the name and location of the virtual disk. In the video I call the disk TestMachine and choose to create the virtual disk in the default location. I could easily have chosen another folder or hard drive for it,

14. Choose the virtual disk’s size. Ensure it is large enough for the guest’s needs. The disk can be small if you only intend to use it to run a Live Disc but if you intend to install the guest OS then it will need to be large enough to store the OS and any files or software you wish to add to it. Remember that Linux uses a swap partition so make the virtual disk big enough to hold it,

15. Click Next,

16. Click Finish to confirm the changes.

Change the Virtual Machine’s Settings

The default settings for virtual machines created by VirtualBox are a little bit meek. So to make them a little more meaty we must make a few  changes.

[wpvideo]http://journalxtra.com/videos/Setting-up-your-virtual-machine.mp4[/wpvideo]

Set up Your Virtual Machine

1. Highlight (by selecting) your virtual machine from the list in the left-hand panel,

2. Click Settings at the top of the window,

3. Choose the General tab

a. Ensure the clipboard is bidirectional so that the host and guest share the same copy and paste files,

b. If you want to add a description for the machine then do it here.

4. Choose the System tab

a. Increase the machine’s Base Memory,

b, unless you have need to use a Floppy Drive, remove it from the boot sequence,

c, set the CD/DVD ROM drive as the first boot device. Change this to Hard Disk once a guest OS has been installed,

d. if available, enable PAE/NX to speed up the virtual machine,

e. enable Hardware Virtualization, if available.

5. Choose the Display tab

a. increase the Video Memory (choose something compatible with the host),

b. enable 3D Acceleration,

6. Choose the Hard Disks tab if you wish to change or add another virtual hard disk.

7. Choose the CD/DVD-ROM tab,

a. select Mount CD/DVD Drive and choose either an ISO image of the OS you wish to use or choose a DVD or CD drive that contains a real operating system disc,

8. Choose the Audio tab,

a. Enable Audio check that the correct Host Audio Driver and Audio Controller is selected.

9. Select the Network tab,

a. Enable Network Adapter. You shouldn’t need to do anything else here as the default settings are generally good enough,

10. Select the Serial Ports tab,

a. Enable the serial ports if you have anything attached to them which you need the guest to access e.g a non USB Printer,

11. Select the USB tab,

a. Enable the USB Controller and USB 2.0 Controller if your host has USB 2 capable ports (most modern PCs do),

b. Click the icon with the green plus sign on it and select one of the USB devices attached to the host machine to enable it within the guest machine,

12 Select the Shared Folders tab,

a. if you wish to enable folder sharing then you must click the blue folder icon with the green plus sign on it so you may specify the folder/s or even drive/s to be shared by the host and guest machines. By default, the guest will have full access to the shared folder/s or drive/s; change this by selecting Read Only if you wish to prevent the guest from writing to them. Linux host users and Windows host users see a slightly different dialogue box when adding shares: the Linux box requires the user to know the address of the folder or drive to be shared; Windows users can browse to the location of the folder/s or drive/s to be shared. This is explained in greater detail in Accessing Real Hard Disk/s.

Run the Virtual Machine and Install an Operating System

When we changed the virtual machine’s settings we chose a disk image that contains the guest operating system’s installation files (Step number 7 of Change the Virtual Machine’s Settings). It is this disk image that will load when the virtual machine runs. Let’s start up our virtual machine. The video example uses a Kubuntu 9.10 Live Disk.

[wpvideo]http://journalxtra.com/videos/booting-your-virtual-machine.mp4[/wpvideo]

Boot Your Virtual Machine

1. Select your virtual machine,

2. Click Start at the top left of the Window,

3. Click the screen that shows the virtual machine loading up. Doing so will cause the virtual machine to grab the mouse and keyboard so you won’t be able to move the mouse outside of the virtual machine’s window. You can release the mouse and keyboard from the virtual machine’s control by pressing the control button (Ctrl) on the right-hand-side of your keyboard,

4. Follow the screen prompts to get the disk to load. At this point you can elect to install Kubuntu onto your virtual disk instead of running it as a Live Disk. If you do install the operating system then you will need a virtual disk of at least 8 GB (remember that dynamic disks only take up as much real space as has been written to it by the guest),

5. If you’ve installed the operating system you will need to shut it down and release (eject) the installation disk (or iso) before restarting it otherwise it will prompt you to install it again.

Install Guest Additions

Guest Additions is a program created by Sun Micro Systems to enable operating systems installed using VirtualBox to work seamlessly within the host operating system. It removes the need for the guest OS to capture the mouse and keyboard before the user may use them to navigate it (the guest OS); it allows the guest to work in a non-windowed mode such that the host desktop is visible and the guest’s taskbar sits above the host’s taskbar and the guest’s programs display against the host’s desktop; and it facilitates the easy set-up of file and drive sharing.

Guest Additions is easy to set-up and will have automatically downloaded at the same time as Virtual Box. It’s added to the guest OS as an iso image using the menu at the top of the guest’s surrounding window. Here’s how to get it working

[wpvideo]http://journalxtra.com/videos/Installing-guest-additions.mp4[/wpvideo]

Install Guest Additions (LinuxMint x86)

1. Boot up the Guest OS,

2. Once the desktop has loaded, select Install Guest Additions from the Devices menu at the top of the window. This will mount an iso image (disc image) called VBoxGuestAdditions. What happens now depends on your guest OS:

a. Linux users, the guest distro might notify you that the iso image has been mounted then provide the option to browse the drive. You should take that option if it’s offered. If it doesn’t do so then you should open a file browser such as Dolphin or Nautilus. You will then see the new media has been mounted as VBOXADDITIONS, browse it. Jump ahead to step 3, below.

b. Windows users, Windows guests should autorun the Guest Additions program. Follow the prompts. After you’ve restarted the guest OS you will be able to take advantage of better and seamless integration of the guest OS with the host OS.

3. This instruction applies to Linux guest OSs only. The file browser will show a list of programs. The ones required by Linux machines are

VBoxLinuxAdditions-AMD64.run

VBoxLinuxAdditions-x86.run

VBoxSolarisAdditions-AMD64.pkg

These programs are for the guest OS so the top program is for virtual machines running a guest OS designed for 64-bit architectures, the second one is for x86 architectures and the bottom one is for Solaris 64-bit.

Open a terminal within the VBOXADDITIONS folder and type sh VBoxLinuxAdditions-AMD64.run or VBoxLinuxAdditions-x86.run or VBoxSolarisAdditions-AMD64.pkg according to the architecture that your guest OS is designed to operate on. Follow the prompts to finish installing the package.

4. There is no 4. Guest Additions should now be installed and after restarting the virtual machine the guest and host will be better integrated i.e the mouse and keyboard will work seamlessly (without the guest grabbing them), the guest can work in full-screen mode with a fully sized desktop, and the guest can forsake its desktop and use the host’s desktop as the backdrop for its windows…

Access Real Hard Disks

The default set-up for a virtual machine is designed to ensure that the host’s security is not compromised by the guest. Consequently, the guest has no access to the host’s storage media until explicitly permitted by the operator (you, me, whoever uses the host machine). Setting up a shared folder or drive is different according to whether the guest OS is Linux or Windows. The differences are minor and non of this is difficult. There are two ways to set-up storage media shares; this guide demonstrates only one of them.

[wpvideo]http://journalxtra.com/videos/creating-shared-folders-with-vbox.mp4[/wpvideo]

Create and Automount Shared Folders

1. Boot the virtual machine,

2. Select Devices>Shared Folders from the top menu bar (Windowed mode),

3. Click the blue folder icon with the green plus sign on it (should be the top most one),

4. This is where Windows hosts and Linux hosts diverge,

a. Windows hosts, browse to the drive or folder you want to share between the guest and host. Windows will automatically name the file or drive that is chosen. If the guest OS is Linux then you should make a note of this name.

b. Linux hosts, type in the address of the drive or folder you want shared between the guest and host. Give the file or drive a name. If the guest OS is Linux then you should make a note of this name.

c. Choose whether this share is permanent or temporary. If permanent, put a tick in the checkbox next to Permanent otherwise leave it blank.

d. Choose whether the guest OS should be allowed to write to the shared folder or drive. If it should then you must not put a tick in the checkbox next to Read Only.

5. Click OK. If the guest OS is Windows then the next few steps can be ignored; Linux guest user should read on..

6. This is where some people might think it’s tricky but it isn’t. To get a Linux guest to use the shared drive or folder we must tell it that it’s available for it so we have to create a mount point (easy) and mount the folder or drive (even easier):

a. First, create a folder so the drive can be mounted. In the example video I use a drive located on my host machine at /media/disk and I give it the exciting and imaginative name of disk. Creating a mount point for disk is the same as  creating a folder for it somewhere in the guest OS’s file system. In the video, this folder is called disk; as this is Linux it seems reasonable to create that folder under media which is where storage media are generally mounted anyway. So open a terminal and type the command:

sudo mkdir /media/disk

which means make a directory (mkdir) under media called disk (/media/disk)

b. Next we mount the drive or folder into the directory created for it. In the video, our folder is a drive called disk and our mount directory is at /media/disk. To mount disk into /media/disk we issue a command via Terminal:

sudo mount -t vboxsf disk /media/disk

which means add the folder or drive (mount) called disk to the location /media/disk

c. Putting that together, create a mount point for the storage media and mount it with the two Terminal commands:

sudo mkdir /media/(desired folder name)
sudo mount -t vboxsf (name of shared media as created in step 4) /media/(folder name)

Gratitude goes to Giannis Tsakiris for showing me how to set up shared folders with a Linux guest.

Automount Shared Media When the Guest OS Boots

This applies to Linux guest OSs only; as far as I’m aware Windows guests will automatically automount shared folders and drives. If I discover anything different then I will update this article accordingly.

Once a Linux guest OS is switched off it releases the shared drives and folders or, in other words, it unmounts them. Not a problem provided you don’t want to dip into them again when next you use the virtual machine. Although we can’t stop a guest OS from unmounting shared drives we can force it to remount the drive whenever it is booted.

Getting drives to automount is much simpler than it sounds and requires only one piece of information per shared media and the addition of one line of code per shared media to a file that loads when the virtual machine loads. This is all done from within a loaded (running) guest operating system and is demonstrated in the video Create and Automount Shared Media.

1. Load the guest OS,

2. Open a terminal within the Guest OS and type

kdesudo kate /etc/rc.local

or, for a Gnome guest OS,

gkdsu gedit /etc/rc.local

3. The file rc.local will now be loaded in a text editor. It will look similar to this:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0

a. Remove the “#” symbol from the beginning of the top line,

b. Just above “exit 0″, type in the instructions required to mount the shared media (used in step 6b of Access Real Hard Disks, above), use a separate line per instruction.

c. rc.local should now look similar to this:

!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
mount -t vboxsf disk /media/disk
exit 0

4. That’s it. Restart the guest OS to confirm that the shared media are being automounted when it loads.

Warning: If you need to remove the shared drive’s or media’s folder then ensure you unmount the media or drive first otherwise you WILL delete the content of the shared folder or drive. You can safely unmount and delete the mount point with

sudo umount /media/(name of drive or folder)
sudo rm -r /media/(name)

“umount” is not a spelling mistake.

Please be careful with those commands because using them wrongly (especially the second one) could wipe your drive or folder.

You can also remove the shared device by using the guest’s VirtualBox’s top bar menu by entering Devices>Shared Folders. If you’ve set the drive to automount by addingit to /etc/rc.local then remember to remove it before restarting the guest.

Leave a Reply

All original content on these pages is fingerprinted and certified by Digiprove
How to Install SDLMAME and SDLMESS onto Ubuntu
Alien Hand Syndrome – Book Review
Loading

Invite Friends to ‘JournalXtra’

Supercharge your web design skills with JournalXtra

Buy me lunch!

I'm a cheap date. Where else can you buy lunch for a couple of dollars?

I accept Bitcoin too!

Categories

Dynamik Website Builder
WPMU DEV - The WordPress Experts
StudioPress Theme of the Month