Virtualbox For Dummies

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

These materials are © 2021 John Wiley & Sons, Inc.

Any dissemination, distribution, or unauthorized use is strictly prohibited.


VirtualBox
®

Oracle® Special Edition

by Simon Coter
and Simon Hayler

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
VirtualBox® For Dummies®, Oracle® Special Edition

Published by
John Wiley & Sons, Inc.
111 River St.
Hoboken, NJ 07030-5774
www.wiley.com
Copyright © 2021 by John Wiley & Sons, Inc., Hoboken, New Jersey
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of
the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department,
John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online
at http://www.wiley.com/go/permissions.
Trademarks: Wiley, For Dummies, the Dummies Man logo, The Dummies Way, Dummies.com, Making
Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons,
Inc. and/or its affiliates in the United States and other countries, and may not be used without written
permission. Oracle, Java, MySQL, and VirtualBox are registered trademarks of Oracle and/or its affiliates.
All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated
with any product or vendor mentioned in this book.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO


REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF
THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING
WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY
MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS.  THE ADVICE
AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS
WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN
RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES.  IF PROFESSIONAL
ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE
SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING
HEREFROM.  THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK
AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN
THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION
OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE.  FURTHER, READERS
SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR
DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

ISBN 978-1-119-82338-4 (pbk); ISBN 978-1-119-82339-1 (ebk)


For general information on our other products and services, or how to create a custom For Dummies
book for your business or organization, please contact our Business Development Department in
the U.S. at 877-409-4177, contact [email protected], or visit www.wiley.com/go/custompub. For
information about licensing the For Dummies brand for products or services, contact BrandedRights&
[email protected].

Publisher’s Acknowledgments

Some of the people who helped bring this book to market include the following:
Development Editor: Business Development Representative:
Rebecca Senninger William Hull
Acquisition Editor: Ashley Coffey Production Editor:
Tamilmani Varadharaj
Editorial Manager: Rev Mengle
Special Help: Faithe Wempen

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Table of Contents
INTRODUCTION ............................................................................................... 1
About This Book ................................................................................... 1
Foolish Assumptions............................................................................ 2
Icons Used in This Book....................................................................... 2
Beyond the Book .................................................................................. 2

CHAPTER 1: Unlocking VirtualBox................................................................ 3


Introducing VirtualBox......................................................................... 3
How virtualization helps................................................................. 4
Key Features and Benefits................................................................... 5
Getting Started with VirtualBox .......................................................... 8
Moving Beyond the Basics .................................................................. 9

CHAPTER 2: Automating with Encryption............................................ 11


Using VirtualBox’s Built-in Encryption.............................................. 11
Managing encryption from the GUI............................................ 12
Managing encryption from the command line ......................... 13
Deploying Applications with Vagrant ............................................... 15
Vagrant basics ............................................................................... 15
Vagrant boxes................................................................................ 16
Configuring Vagrant with the Vagrantfile .................................. 16
Vagrant plugins ............................................................................. 17

CHAPTER 3: Packaging and Migrating to the Cloud ..................... 19


Packaging Virtual Machines Using Open
Virtualization Format ......................................................................... 20
Exporting to an OVF appliance.................................................... 21
Importing an OVF appliance ........................................................ 22
Exporting to Oracle Cloud Infrastructure........................................ 22
VirtualBox requirements.............................................................. 23
Virtual machine requirements .................................................... 23
Running the export....................................................................... 24
Importing from Oracle Cloud Infrastructure .................................. 24

CHAPTER 4: Ten Reasons to Use VirtualBox ...................................... 25

Table of Contents iii

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Introduction
E
ver wish you could run more than one operating system on a
single hardware platform? Oracle VM VirtualBox enables
that, and a whole lot more.

With VirtualBox, IT administrators, developers, technical archi-


tects, technical writers, and basically anyone who has a computer
can host multiple operating systems. VirtualBox enables you to
quickly spin up full-blown virtual machines that can be used as
servers, desktops, test environments, or teaching tools without
having to use dedicated and expensive hardware.

In this book, you learn the basics of virtualization, and see how
VirtualBox enables it. Then you find out how using VirtualBox
features such as encryption, automation, and packaging for the
cloud address many of the challenges of modern application
development.

About This Book


VirtualBox For Dummies consists of four chapters. Here’s what to
expect:

Chapter  1: Unlocking VirtualBox. Here you get to know Virtual-


Box, discover its key features, and find out why businesses use it.

Chapter  2: Automating with Encryption. This chapter explains


how VirtualBox uses encryption to provide a secure environ-
ment. This can be done using an open source tool called Vagrant,
or using VirtualBox’s own Unattended Installer utility within a
script.

Chapter  3: Packaging and Migrating to the Cloud. Here you find


out how to use Open Virtualization Format (OVF) to export and
import virtual machines, and how to export and import with
Oracle Cloud Infrastructure.

Chapter  4: Ten Reasons to Use VirtualBox. Here’s a quick list of


ten key benefits that VirtualBox brings to the table.

Introduction 1

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Foolish Assumptions
In writing this book, we’ve made some assumptions about who
will be reading it. Mainly we assume you work in IT in a pro-
fessional capacity such as an application developer, architect,
or development operations manager. It’s also possible that you
just love technology and want to learn how to get more from
VirtualBox.

Icons Used in This Book


Throughout this book, we occasionally use icons to call attention
to important information. Here’s what you can expect.

This icon points out the key takeaways that you’ll want to file
away in your mind for later recall.

Anything marked with this icon is fairly technical, like a list of


standards or an explanation of the inner workings of something.

When you see this icon, look for friendly advice for sidestepping
pitfalls.

This icon points out bright ideas and best practices that can
help your organization make the most out of automation for
cross-platform virtualization.

Beyond the Book


Say you get to the end of this book and think “Wow! That was an
amazing read. Where can I learn more?” Just head to https://
www.oracle.com/virtualbox. You can also access the VirtualBox
user manual at https://docs.oracle.com/en/virtualization/
virtualbox/6.1/user/index.html.

2 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
» Getting to know VirtualBox

» Discovering its key features

» Learning how to get started with


VirtualBox

Chapter  1
Unlocking VirtualBox

N ew to VirtualBox? Start here! This chapter explains what it


is, what it can do, and why a lot of businesses choose it.

Introducing VirtualBox
With thousands of downloads each day, VirtualBox is the world’s
most popular free and open source, cross-platform virtualization
software. It’s based on vibrant community participation com-
bined with world-class development and support by Oracle.

VirtualBox is cross-platform virtualization software. What does


that mean?

First of all, cross-platform means it works across different


hardware and software platforms. You can install VirtualBox on
all your existing Intel or AMD-based x86 computers, whether
they’re running Windows, macOS, Linux, or Oracle Solaris oper-
ating systems (OSs).

Virtualization means you can create an installation of one OS


inside another OS’s operating environment. VirtualBox extends
the capabilities of your existing computer so that it can run mul-
tiple OSs, inside multiple virtual machines, at the same time. As
an example, you can run Windows and Linux on your Mac, run

CHAPTER 1 Unlocking VirtualBox 3

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Linux on your Windows PC, and so on, all alongside your existing
applications. You can install and run as many virtual machines
as you like. The only practical limits are disk space and memory.

VirtualBox is deceptively simple yet very powerful. It can run


everywhere from small embedded systems or desktop class
machines all the way up to data center deployments and cloud
environments.

How virtualization helps


VirtualBox simplifies cloud and on-premises deployments by
enabling developers to create multiplatform environments and to
develop applications for container and virtualization technologies
on a single machine. Operating system and application updates
can be done within VirtualBox virtual machines and subsequently
be deployed to server virtualization environments running
production systems.

VirtualBox is an ideal choice for next-generation application


development.

Here are some of the cool things that VirtualBox makes possible:

» Run multiple operating systems simultaneously.


VirtualBox enables you to run more than one OS at a time.
This enables you to run software written for one OS on
another, such as Windows software on Linux or a Mac,
without having to reboot to use it.
» Make software installation easy. Software vendors can
use virtual machines to ship entire software configurations.
VirtualBox allows them to package a complex architecture
that includes multiple operating systems and applications
into an appliance.
» Accelerate application testing. VirtualBox is a key tool for
developers creating and testing applications. Once installed,
a virtual machine can be arbitrarily frozen, woken up, copied,
backed up, and transported, as an appliance, between hosts.
» Consolidate resources. Instead of running more physical
computers that are only partially used, each with a dedicated
OS, VirtualBox enables you to consolidate multiple virtual
machines on a single desktop or laptop system.

4 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
LEARNING SOME LINGO
Here are some key terms that will be popping up as you go along.

• Host operating system (host OS): This is the operating system of


the physical computer on which VirtualBox is installed. VirtualBox
is available for Windows, macOS, Linux, and Oracle Solaris operat-
ing systems.
• Guest operating system (guest OS): This is the operating system
that runs inside a virtual machine. Theoretically, VirtualBox can
run any x86 operating system inside a virtual machine.
• Virtual machine (VM): This is a process, running on the host
operating system, that shows the virtual machine as a window on
your computer’s desktop.
• Guest additions: These are special software packages that are
shipped with VirtualBox but designed to be installed inside a vir-
tual machine running a specific OS.
• Graphical user interface (GUI): This is a user interface that con-
sists of a graphical environment with icons and windows, such as
Windows or macOS. Users interact with it using a pointing device
such as a mouse.
• Command-line interface (CLI): This type of interface is a text-
based prompt where users type commands using a keyboard.

Key Features and Benefits


VirtualBox enables users to set up multiplatform virtual
machine environments for software development, testing, and
general-purpose operating system (OS) virtualization, with
optional runtime encryption. Software engineers can develop for
cloud native environments from within VirtualBox VMs directly
on their Windows, macOS, Linux, and Oracle Solaris machines,
making it easier to create multitier applications with just a
standard laptop.

CHAPTER 1 Unlocking VirtualBox 5

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Here are some of the key features and benefits that VirtualBox
offers.

Portability: You can easily import and export virtual machines


using the Open Virtualization Format (OVF), an industry standard
created for this purpose. You can even import OVFs that were cre-
ated with different virtualization software. You can also export
and import virtual machines to and from the cloud. That simpli-
fies application development and deployment to the production
environment.

Guest additions: Guest additions are OS-specific packages of


drivers and other helper files that you can install after setting up
a certain OS in a virtual machine. After installing the guest addi-
tions, a virtual machine can support shared folders, automatic
video resolution adjustment, seamless windows, accelerated 3D
graphics, and more.

Scriptable CLI: VirtualBox includes a powerful CLI (VBoxManage


and vbox-img) to automate all the possible operations that the
graphical user interface (GUI) usually executes.

Hardware support: VirtualBox supports virtual machine multi-


processing with up to 32 virtual CPUs to each virtual machine.
It implements a virtual USB controller and enables you to connect
arbitrary USB devices to your virtual machines. It also virtualizes
a vast array of virtual devices and supports the Advanced Config-
uration and Power Interface (ACPI).

Multiscreen resolutions: VirtualBox virtual machines support


screen resolutions many times that of a physical screen, enabling
them to be spread over a large number of screens attached to the
host system.

Multigeneration branched snapshots: VirtualBox can save arbi-


trary snapshots of the state of the virtual machine. You can go
back in time and revert the virtual machine to any such snapshot
and start an alternative VM configuration from there, effectively
creating a whole snapshot tree. You can even create and delete
snapshots while the virtual machine is running.

6 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Remote machine display: You can access your virtual machines
remotely from anywhere that has Internet access via the Virtual-
Box Remote Desktop Extension (VRDE). This extension supports
the Remote Desktop Protocol (RDP) originally built into Micro-
soft Windows, with special additions for full client USB support.
VirtualBox VRDE also supports Winlogon authentication on
Windows, pluggable authentication modules (PAM) on Linux, and
enables remote access to USB ports over RDP.

Export to Oracle Cloud Infrastructure: You can export a virtual


machine to Oracle Cloud Infrastructure. One single upload can
create multiple virtual machines.

Import from Oracle Cloud Infrastructure: VirtualBox’s Import


Appliance feature enables you to import virtual machines from
Oracle Cloud Infrastructure.

Nested virtualization: You can install a hypervisor within a


virtual machine. That means that your VirtualBox instance can be
installed on a guest OS, which can in turn become a host for other
nested guests.

Graphics: VirtualBox enables virtual machines to display 3D


graphics. Guest additions within a virtual machine can boost 3D
performance.

Bi-directional drag-and-drop support: You can open files and


directories and copy them between the host and the virtual
machine.

Disk image encryption: Data stored in hard disk images can be


encrypted transparently for the virtual machine. VirtualBox uses
the AES algorithm and supports 128 or 256-bit data encryption
keys.

Storage I/O subsystem: VirtualBox supports a wide range of vir-


tual storage controllers including NVMe, SAS, SATA, SCSI, and
IDE controllers.

Virtual webcam: On hosts with cameras, VirtualBox exposes a vir-


tual webcam. That means that applications running on guest OSs
can use the host’s webcam hardware.

CHAPTER 1 Unlocking VirtualBox 7

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Virtual machine clone: You can make clones of virtual machines.
You can also retain the hardware UUID, MAC address policy, and
disk image names — or not, your choice.

Flexible networking options: VirtualBox offers a rich range of


networking models, from easy-to-use NAT networking to fully
functional bridged networking and specialized internal and host-
only networking.

Virtual media manager: VirtualBox supports the widest range of


virtual disk formats from its own native (.vdi) format to those
offered by Microsoft (.vhd), VMware (.vmdk), and Parallels (.vdd).
You can also use VirtualBox to convert between formats.

Video capture: VirtualBox provides a built-in recording mecha-


nism that enables you to capture video of the virtual machine’s
screen activity. The recorder is easy to start and stop, and it can
record one or more virtual screens to the standard webm format.

Getting Started with VirtualBox


VirtualBox is easy to install on your x86 laptop or desktop. If this is
your first time, a great place to start is the VirtualBox installation
documentation.

You have a choice of interfaces when managing your virtual


machines. If you like a GUI, the VirtualBox Manager provides a
slick and easy-to-use graphical environment. You can use the
VirtualBox Manager, or if you prefer command-line interfaces,
VirtualBox offers the VBox-Manage command, which is extremely
powerful and can be used in scripting to automate and orchestrate
virtual machine lifecycle flows. For further information on both,
refer to the online VirtualBox User Manual.

Once VirtualBox is up and running, you can create your first


virtual machine. A useful guide for creating your first virtual
machine using the VirtualBox Manager graphical interface is in
the User Manual.

8 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
HASHICORP VAGRANT
HashiCorp Vagrant is a tool for building and managing virtual
machines on VirtualBox in a single workflow. With an easy-to-use
workflow and focus on automation, Vagrant lowers development
environment setup time, increases production parity, and makes the
“works on my machine” excuse a relic of the past. Vagrant features
prominently in Chapter 2 of this book, so you may want to go ahead
and install it. You can find it at https://www.vagrantup.com/.

Like VirtualBox, HashiCorp Vagrant works on macOS, Linux, Windows,


and more.

After you create your first virtual machine, you can then run it and
explore other options, including how to access the console and
how to interact with your virtual machine. Your virtual machine
needs specific settings defined such as CPU, memory, displays,
network, and storage. For these settings, refer to the VirtualBox
User Manual.

A key area is the VirtualBox extension pack, which provides the


security and packaging features described in Chapters 2 and 3 of
this book. The extension pack also provides support for USB 2.0
and USB 3.0 devices, VirtualBox Remote Desktop Protocol (RDP),
disk encryption, host web camera pass through, Non-Volatile
Memory Express (NVMe) and Preboot Execution Environment
(PXE) boot for Intel cards, and the ability to export and import
from Oracle Cloud Infrastructure. For further details on the exten-
sion pack, refer to the VirtualBox User Manual.

Moving Beyond the Basics


The next two chapters are designed to move beyond the basics
of VirtualBox, into the complicated real-world stuff that admins
have to deal with. You find out how to use the encryption features
of VirtualBox, and how to automate your virtual machine installs.
You also find out how to use the packaging features of both the
Open Virtualization Format (OVF) and Oracle Cloud Infrastruc-
ture, so you can import and export virtual machines locally or to
Oracle Cloud Infrastructure.

CHAPTER 1 Unlocking VirtualBox 9

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
Chapter  2 discusses in detail, and with examples, some options
for using encryption and automation with Vagrant. We provide
some sample code that shows the steps to enable these features
and how to use them with your own virtual machines.

Chapter  3 of this book discusses in detail how the OVF format


works with VirtualBox and how you can publish to and from Ora-
cle Cloud. As with Chapter 2 of the book, code examples show how
you could do this with your own virtual machines.

VIRTUALBOX ENTERPRISE
Organizations can streamline operations by purchasing VirtualBox
Enterprise, which includes commercial licenses and technical support
and provides:

• 24x7 support from Oracle for the Base Package and Extension
Pack
• Multiple remote desktop connections (VRDP) to virtual machines

• Centralized, easy tracking of VirtualBox Extension Pack downloads


and installation compliance
• Ensures all VirtualBox instances are on the latest release and have
the latest security patches

10 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
» Leveraging built-in virtual machine
encryption

» Automating virtual machine creation


with Vagrant

Chapter  2
Automating with
Encryption

W
e all have data we want to keep private and secure both
for personal and business use. Exposing sensitive data
to others could lead to financial, personal, and contrac-
tual implications. Encryption puts data in a form that is unreada-
ble to anyone without authorization.

In this chapter, you find out how virtual machines are encrypted
in VirtualBox and you learn how to automate virtual machine
creation — and how to include encryption in that automation.

Using VirtualBox’s Built-in Encryption


When you have an OS within an OS, encryption can get a bit tricky.
Fortunately, VirtualBox has you covered with built-in encryption
designed specifically for virtual machines.

Using encryption at the virtual machine level enables you to use


VirtualBox rather than the virtual machine operating system,
which may not support encryption natively. VirtualBox uses the
Advanced Encryption Standard (AES) algorithm in XTS block
cipher mode and supports 128-bit or 256-bit data encryption

CHAPTER 2 Automating with Encryption 11

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
keys (DEK). Current thinking suggests that the larger the key the
more secure the encryption. The DEK is stored encrypted and is
decrypted when the virtual machine starts by entering a password.

You can configure encryption using either the GUI or the CLI (via
the VBoxManage command).

VirtualBox has both a slick, intuitive GUI and a powerful CLI. The


GUI interface is easier to use, but the CLI is more feature-rich.
Case in point: individual disk encryption. Your virtual machine
may contain multiple disk images, and if you enable encryption
via the GUI, all the disk images are encrypted with a single pass-
word. If you have some disk images that do not need encryption,
or you want individual passwords for the different disk images,
you can use the VBoxManage command to select disks individually.
The following sections explain how to manage encryption using
each interface.

Using encryption requires the VirtualBox Extension Pack; this is


for both the user interface and the VBoxManage command. You can
download the extension path from the VirtualBox website.

Managing encryption from the GUI


Follow these steps to enable and configure encryption using the
VirtualBox Manager, the GUI interface of VirtualBox:

1. Download and install the Oracle VM VirtualBox Extension


Pack from the VirtualBox website.
2. With the VM stopped, right-click it in the Oracle
VM VirtualBox Manager window and choose Settings.
3. In the General section, click the Disk Encryption tab, and
mark the Enable Disk Encryption check box.
4. Select the encryption level from the Disk Encryption
Cipher drop-down list.
If you’re not sure, pick AES-XT256-PLAIN64.
5. In the Enter New Password and Confirm New Password
boxes, enter the desired password.
6. Click OK.

12 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
If you later want to remove encryption, go back to this same
section in Settings and deselect the Enable Disk Encryption
check box.

Managing encryption from


the command line
Here is how to manage Virtual Machine (VM) encryption settings
from the CLI.  This management method offers some advanced
options and features that the GUI method lacks. For example, you
can enable or disable encryption individually for each disk image.

The command to use is VBoxManage, and here’s the syntax for it:

VBoxManage encryptmedium <uuid|filename>


[--newpassword <file|->]
[--oldpassword <file|->]
[--cipher <cipher id>]
[--newpasswordid
<password id>]

Here’s what the options mean:

» The disk image file: You can supply either the disk UUID or
absolute path to the disk image file. If you run the following
command, it lists the disks, with UUID, and which virtual
machine it belongs to:

VBoxManage list hdds

» Password prompt: The --newpassword option requires a


path to a file within the operating system or – that prompts
for a password when the virtual machine starts.
If you choose a prompted password, then you need to use
the --newpasswordid <password id> command to give
the disk a name. This is useful if you have multiple disks and
want to encrypt each disk with a separate password. If you
choose the same password for multiple disks, only one
password entry is required when the virtual machine starts.

CHAPTER 2 Automating with Encryption 13

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
» Specifying the cipher: The --cipher <cipher id> option
can be either AES-XTS128-PLAIN64 or AES-XTS256-PLAIN64.
Here is an example of single disk, prompt for a password,
256-bit cipher, and a disk id of disk1:

VBoxManage encryptmedium d401ef19-1aa9-4edc-


8d78-c4660c3206a0 --newpassword - --cipher
AES-XTS256-PLAIN64 --newpasswordid disk1

» Removing the password from memory on suspend: Starting


your virtual machine with encrypted disks using headless mode
starts the virtual machine. However, when any encrypted disk is
first accessed, the virtual machine pauses. For each encrypted
disk, you need to run a command using VBoxManage such as:
vboxmanage controlvm “vmname” addencpassword
“diskidentifier” -. The - switch prompts the user to enter a
password; you can also specify a path to a password file using
vboxmanage controlvm “vmname” addencpassword
“diskidentifier” path_to_password_file. For both
password choices you can use the --removeonsuspend
<yes|no> option. This is an additional security feature that
specifies whether to remove/keep the password from/in virtual
machine memory when the virtual machine is suspended. If the
virtual machine has been suspended and the password has
been removed, the user needs to resupply the password before
the virtual machine can be resumed. This feature is useful in
cases where the user doesn’t want the password to be stored in
virtual machine memory, or if the virtual machine is suspended
by a host suspend event.

» Entering the old password: The –-oldpassword option


is used when a password already exists, for example if you
want to change the cipher type. If unsure, you can check
the password on a disk, for example, by running the
VBoxManage checkmediumpwd d401ef19-1aa9-4edc-
8d78-c4660c3206a0 - command. This command requires
the disk UUID or absolute path to the disk image file, and
prompts for the password. You can also provide a path to a
password file within the operating system.
» Removing encryption: If you need to remove encryption
from the command line, you can use the VboxManage
command for individual disks. You need passwords for
each disk (or a single password for all disks) and the virtual
machine needs to be shut down.

14 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
When you export a virtual machine using the Open Virtualiza-
tion Format (OVF), encryption is removed before the export, and
you’re prompted to enter the password. See Chapter 3 to find out
how to export a virtual machine.

Deploying Applications with Vagrant


VirtualBox can help accelerate application deployments by auto-
mating the configuration and provisioning of virtual machines.
Automation reduces human error and simplifies VM portability.
This can be done in two ways: using an open source tool called
Vagrant, or using VirtualBox’s own Unattended Installer utility
(which you can learn about in the VirtualBox User Manual).

Vagrant basics
Infrastructure as code is the process of creating and managing com-
pute resources using machine-readable definition files. Vagrant,
by HashiCorp, is infrastructure as code that automates the process
of provisioning and configuring virtual machines using Virtual-
Box as its default virtual machine provider. A Vagrant Provider is
a hypervisor leveraged to run virtual machines.

Vagrant runs in multiple operating environments and is easily


transported to others.

If your virtual machine operating environment of choice is Oracle


Linux, for example, you can have an instance configured and up and
running in a handful of steps with no need to download ISO images.

1. Install VirtualBox, and then install Vagrant.


2. Create a local directory for your project.
This is where the vagrant information is stored, so give it a
meaningful name.
3. Run an init command using Vagrant.
Suppose you want to run a VM with Oracle Linux 8. From this
project directory you just created, run the following
command:

vagrant init oraclelinux/8 https://oracle.


github.io/vagrant-projects/boxes/
oraclelinux/8.json

CHAPTER 2 Automating with Encryption 15

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
A Vagrantfile is created with the Oracle Linux 8 details
reusable for later projects.
4. Run the vagrant up command.
This command tells VirtualBox to create the Oracle Linux 8
virtual machine with NAT networking and automatically
generated ssh keys.
5. Run the vagrant ssh command.
You’re now in the Oracle Linux 8 virtual machine as the
vagrant user. Running sudo su - gives you the ability to get
to the root user.

This simple and repeatable process uses Oracle Linux base images
called Oracle Linux Vagrant Boxes. They’re available in Oracle Linux
versions 6, 7, and 8, and are designed to serve as a starting point.

Oracle Linux Vagrant Boxes are available at http://yum.oracle.


com/boxes/.

Example projects for Oracle Linux and Oracle software such as


Oracle Database are available at https://github.com/oracle/
vagrant-projects.

Vagrant boxes
Vagrant uses boxes for its packaging format. These boxes can be
created from ISO images, provided there is a base configuration to
reference. The box approach enables any user on any operating sys-
tem supported by Vagrant to bring up an identical virtual machine.

Configuring Vagrant with


the Vagrantfile
The Vagrantfile is a configuration file that enables you to config-
ure Vagrant differently for each project. Modifying it enables you
to control a virtual machine’s configuration. For example, you can
add network interfaces, set the memory size, number of CPUs,
and amount of RAM, and choose the graphics controller.

You’ll want to study the Vagrantfile and its syntax more closely
before you start editing it. Here’s an example:

config.vm.define "my-vm" do |s|


s.vm.provider "virtualbox" do |vb|

16 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
vb.memory = 5120
vb.name = "my-vm"
vb.cpus = 2
vb.customize ["modifyvm", :id, "--nested-hw-
virt", "on"]
vb.customize ["modifyvm", :id, "--nictype1",
"virtio"]
vb.customize ["modifyvm", :id, "--nictype2",
"virtio"]
vb.customize ["modifyvm", :id,
"--nicpromisc2", "allow-all"]
vb.customize ["modifyvm", :id, "--vram", "9"]
vb.customize ["modifyvm", :id,
"--graphicscontroller", "vmsvga"]
end

Moving upwards from the VM container, you can set access


and networking information within the VM operating environ-
ment. For example, you can enable ssh from your host, select an
Oracle Linux 7 image, and set a host-only private network. Here’s
an example of that:

s.ssh.forward_agent = true
s.vm.box = "oraclelinux/7"
s.vm.box_url = "https://oracle.github.io/
vagrant-projects/boxes/oraclelinux/7.json"
s.vm.hostname = "olvm-mgr"
s.vm.network "private_network", ip:
"192.168.56.101", netmask: "255.255.255.0"

Vagrant plugins
Vagrant has some very useful plugins. For example, the reload
plugin enables you to add a reboot of a virtual machine into the
configuration flow. This is useful if you script, for example, an
update or package install that needs a reboot. Following a reboot,
the steps in the Vagrantfile continue to run enabling a single
configuration flow.

Leveraging VirtualBox’s shared folder feature, Vagrant uses the


VirtualBox Guest Additions to access other folders and files. This
enables you to copy files into place or run complex scripts using

CHAPTER 2 Automating with Encryption 17

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
required configuration and answer files. For example, you can run
scripts using the shell statement, move files using the file state-
ment, and schedule a reboot using the reload plugin. Here’s an
example:

s.vm.provision :shell, path: "scripts/update-vm.sh"


s.vm.provision "shell", inline: "echo
'Reloading your VM to activate the latest
kernel'"
s.vm.provision :reload
s.vm.provision "file", source: "scripts/
answers.conf", destination: "/tmp/answers.conf"
s.vm.provision "shell", path: "scripts/engine-
configure.sh"
s.vm.provision "shell", path: "scripts/web-
app-build.sh"
s.vm.provision "shell", inline: "echo
'INSTALLER: Installation of my-vm complete!'"

Vagrant has other useful plugins:

» Proxyconf drives configuration of a proxy within the virtual


machine operating environment once set in the terminal or
shell.
» Vbguest installs and updates the VirtualBox guest additions
package in the virtual machine operating environment.
» Trigger makes things happen either on the host or within the
virtual machine operating environment.

Currently there is no explicit method to encrypt a disk as a step in


Vagrant. However, there are some workarounds. Using the trig-
ger plugin, you can trigger a script to run on the host to grab
disk information. You can, following the vagrant up command,
shut the virtual machine down, and then capture the disk infor-
mation via a script or manually. You can then encrypt the disk.
By enhancing the Vagrantfile using the trigger plugin, you could
append the disk id and password from a file. Every subsequent
vagrant up would then ask the user to enter the password for
the encrypted disk. You also have the option to use VirtualBox’s
Unattended Installer within a script, which is documented with
examples in the VirtualBox User Manual.

18 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
» Leveraging Open Virtualization Format
(OVF) to export and import

» Exporting to and importing from Oracle


Cloud Infrastructure

Chapter  3
Packaging and Migrating
to the Cloud

I
n this chapter, you find out how to package virtual machines,
how to share these packages with other users, and how to
export to and import VMs from Oracle Cloud Infrastructure
(OCI). OCI is a set of complementary cloud services that enable
you to build and run a wide range of applications and services
in  a highly available hosted environment. OCI offers high-
performance compute capabilities (as physical hardware
instances) and storage capacity in a flexible overlay virtual
network that is securely accessible from your on-premises
network.

Exporting a virtual machine is useful for creating an appliance


that can be shared with other users. It can contain, for exam-
ple, unique security settings or pre-installed applications. The
ability to package and export applications developed on your
local machine to OCI is also useful for cloud migration projects
and simplifies moving applications from test to production
environments.

CHAPTER 3 Packaging and Migrating to the Cloud 19

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
TRY ORACLE CLOUD FREE
You can build, test, and deploy applications for free using the
no-charge version of Oracle Cloud. You also get $300 of credits for
30 days to use on even more services, such as Container Engine for
Kubernetes, Analytics Cloud, and Data Integration.

Packaging Virtual Machines Using


Open Virtualization Format
Open Virtualization Format (OVF) is an industry standard for
packaging software for virtual on-premises environments or
private clouds. The format specifications describe how a package
or appliance is put together, including disk images, manifests,
and certificates. In applicable environments, OVF provides a com-
mon method of exporting and importing virtual machines.

An Open Virtual Appliance (OVA) is an OVF Package in a single file


archive with the .ova extension. The following is a list of the files
that can be contained within an OVA (in the form of a *.ova file):

» The descriptor file (*.ovf) describes the virtual hardware


elements of the virtual machine. They can include the
operating system type, description of the virtual disks and
format, the service itself, and how to stop and start the
virtual machine.
» The manifest file (*.mf) lists all files in the package with an
SHA-1 signature, allowing each to be checked for corruption.
» The certificate file (*.cert) contains a public key that enables
an author to be identified.

OVF doesn’t care about the type of virtual disk files; the disk type
is left to the technology that exported the virtual machine. For
example, VirtualBox uses the VDI disk format (*.vdi) by default,
but it can also handle VMDK (*.vmdk) and VHD (*.vhd) formats.

Using VirtualBox, you can create a virtual machine, customize


the configuration, and export to an OVF format. This package
or appliance can then be imported into an enterprise platform
enabling a test to production workflow. Conversely, production

20 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
virtual machines can be imported into VirtualBox, edited, and
then exported back into test and production. This decouples the
need for expensive development environments and permanent
virtual private network development sessions for a home worker.

Exporting to an OVF appliance


Suppose you’ve created a virtual machine using VirtualBox on
your local laptop or desktop, configured the operating system,
and installed and configured an application. This virtual machine
can be exported and then imported and used by other VirtualBox
users.

Install VirtualBox guest additions before exporting the VM to


enable advanced features. For further details on VirtualBox guest
additions refer to the documentation.

You can export your virtual machine from either the GUI or the
command line.

After you select the virtual machine to export via the GUI, you
have the option of Guided or Expert mode. Guided takes you
through the default flow to create your appliance, whereas Expert
enables you to attach additional information to your appliance,
referred to as Virtual System Settings: Product, Vendor, Descrip-
tion, and License. The License section is simply a statement users
agree to. It’s useful for providing a declaration of acceptance such
as “Yes, I agree to the usage of this appliance.”

The final stage is Appliance Settings, where you’re presented with


some defaults:

» The default format is 1.0 OVF, but you can choose versions
0.9 or 2.0.
» File is the name and location of where the appliance will be
exported to; this can be changed.
» MAC address policy is set by default to include only NAT
network adapter MAC addresses. This is changeable to strip
out all MAC addresses or leave all in. You can use the default
setting unless you have a local script or network functions
that rely upon MAC addresses.
» The option of writing a manifest file is set by default. This
option writes all the VirtualBox specific information as part

CHAPTER 3 Packaging and Migrating to the Cloud 21

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
of the appliance, enabling error checking on subsequent
imports.
» Including ISO image files isn’t set by default but can be
enabled if needed. Be aware that attached ISO images can
increase the overall size of the appliance, making upload and
download times longer.

After making export choices, VirtualBox creates the appliance,


providing information on the time needed and progress.

OVF is unable to cope with snapshots, so if your virtual machine


has snapshots, the exported appliance will reference the current
state.

Importing an OVF appliance


You can import and customize an OVF appliance using the GUI or
the VBoxManage import command.

As with the export flow, you have the option of Expert or Guided
mode. Guided mode asks for the location of the appliance, and
then displays the appliance settings such as CPU and adapter
details that can then be edited. Expert mode shows all the details
in one page.

For both modes, VirtualBox asks for the location to place the
virtual machine created from the appliance and the MAC address
policy. It also suggests changing the disk format to the preferred
VirtualBox VDI.

Finally, it displays details if the appliance is signed with a certifi-


cate. If the appliance has a License field set, you’re asked to agree
or disagree before the import is started. When the import begins,
it provides information on the time needed and progress. When
the import process completes, your virtual machine appears in
a stopped state. At that point, you can make further edits to it
before starting.

Exporting to Oracle Cloud Infrastructure


VirtualBox version 6.1 and above is integrated with OCI. This inte-
gration enables you to export a Linux or Windows virtual machine
created locally on your laptop or desktop from VirtualBox into

22 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
OCI. To do this, you need an account with suitable access to OCI
as well as VirtualBox version 6.1 or higher. For further details on
integrating VirtualBox with OCI, refer to the documentation.

VirtualBox requirements
VirtualBox needs identity information to interact with OCI and
upload your virtual machine.

First you need to gather some information from your OCI pres-
ence. You can find the needed Oracle Cloud Identifier (OCID)
details from your account via the OCI console: User, Tenancy,
Region, and Compartment. The key_file and fingerprint need to
be generated on your host system; refer to the OCI documentation
for details.

An individual OCID is attached to each OCI logical entity. Navi-


gate to each entity such as the tenancy and you see an option to
either show or copy the OCID. Use the copy function to avoid typ-
ing mistakes.

From the VirtualBox user interface, open the File menu and
choose Cloud Profile Manager. Click Add to create a new profile.
After the profile is created, select it, click Properties, and fill in all
the pertinent details.

Virtual machine requirements


To successfully export and import a Windows or Linux virtual
machine, follow the recommendations in the OCI documentation.
Here are the general requirements:

» Check that the virtual machine operating system is


supported.
» Use DHCP, not static networking.
» Use emulated rather than physical devices.
» Don’t include any reference to hardware addresses (MAC)
within the network configuration.
» Use only one disk. (Only one is supported.)
» Use a disk image size of no more than 400GB.
» Don’t use encrypted disk images.

CHAPTER 3 Packaging and Migrating to the Cloud 23

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
» Configure a console connection or Remote Desktop Protocol
(RDP) access to the virtual machine.
» Install the virtual I/O drivers available for the virtual machine
operating system.
» Use either VMDK or QCOW2 as the disk format.

Use the VBoxManage clonehd command to convert a disk image


from one format to another. If the virtual machine to export has
a *.vdi format, for example, you can first clone the original disk
image, and then attach it to the virtual machine with a command
like this:

VBoxManage clonehd source.vdi target.vmdk –format


VMDK

Running the export


To process the export operation, stop the virtual machine cleanly,
and then either select the Export function from the GUI or use the
VBoxManage export command at the command line.

Both options require you to select your cloud profile, as well as


other options such as name, bucket, and launch details. You’re
also given an option to not create the virtual machine but leave it
configured as a custom image ready to be created later. The time
to export depends on your Internet bandwidth.

Importing from Oracle Cloud


Infrastructure
You can import using the VirtualBox GUI or the VBoxManage
import command. Both options require your cloud profile; the
user interface shows all OCI instances related to your cloud profile.

After choosing which instance to import, you can change some


of the settings, such as Type, Version, CPU, and Memory. The
import process then runs. The time depends on your Internet
bandwidth. VirtualBox shows the progress and the estimated time
to complete.

24 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
IN THIS CHAPTER
» Compelling reasons to use VirtualBox

Chapter  4
Ten Reasons to Use
VirtualBox

W
hy do millions of people use VirtualBox? As the world’s
most popular open source, cross-platform virtualiza-
tion software, there are plenty of reasons. Here are ten
of the most compelling ones.

» It’s a great development platform for the cloud.


VirtualBox enables users to create and deploy virtual
machines nearly anywhere, upload to the cloud, download
from the cloud, and review and make changes offline.
Software developers can rely on VirtualBox for developing
and debugging their applications in multiple operating
systems and environments on a single physical device.
Developers can also clone a production environment on
their personal desktop/laptop without impacting the
business.
» It supports a wide range of platforms. VirtualBox can be
installed on your existing Intel or AMD-based x86 computers,
whether they’re running Windows, macOS, Linux, or Oracle
Solaris operating systems. Oracle VM VirtualBox can run any
x86 OS as a guest OS, but the most common ones are officially
supported and optimized.

CHAPTER 4 Ten Reasons to Use VirtualBox 25

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
» It simplifies quality assurance and testing. By using
a single physical device to test software on multiple OS
platforms and versions, VirtualBox enables software quality
assurance teams to simplify their environment and reduce
resources.
» It offers powerful hardware virtualization. VirtualBox
offers a wide range of virtual storage controllers, including
NVMe, SAS, SATA, SCSI, and IDE controllers. VirtualBox
utilizes an asynchronous I/O virtual disk subsystem to
achieve high performance while maintaining high data
integrity. It also offers a rich range of networking models,
including easy-to-use NAT networking, fully functional
bridged networking, and specialist internal and host-only
networking.
» Its virtual machines are secure and encrypted. VirtualBox
offers built-in encryption securing your data using the AES
algorithm 128-bit or 256-bit using XTS block cipher mode
data encryption keys (DEK).
» You can use it to provide secure remote access via
virtual machines. VirtualBox enables IT managers to
distribute desktop-based images to remote workers when a
VPN connection is considered insufficient. This capability
helps organizations increase security by implementing
restrictions defined by pre-built appliances.
» It’s easy to adopt. An easy-to-use GUI and a powerful CLI
make it easy for developers to work with multiple operating
systems on the same system. The command-line interface
also enables you to automate operations with Linux shell or
Windows PowerShell using the VBoxManage command.
» You can import and export virtual machines using OVF/
OVA standards. VirtualBox enables you to export and
import virtual machines by leveraging the standard Open
Virtualization Format. It also enables you to create and
distribute virtual machine appliances, so you can distribute
an application inside a virtual machine that will run on any
version of any supported OS.

26 VirtualBox For Dummies, Oracle Special Edition

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
» You can automate secure virtual machine builds using
Vagrant or the VirtualBox Unattended Installation
feature. Using Vagrant boxes with VirtualBox or using
VirtualBox’s Unattended Installer within a script, you can
quickly provision development VMs with preconfigured
applications software and automate the release to
production.
» You can build a multitier demonstration system on a
single portable machine. VirtualBox enables you to create
a multitier solution with separated and isolated networking,
emulating complex production environments.

CHAPTER 4 Ten Reasons to Use VirtualBox 27

These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
These materials are © 2021 John Wiley & Sons, Inc. Any dissemination, distribution, or unauthorized use is strictly prohibited.
WILEY END USER LICENSE AGREEMENT
Go to www.wiley.com/go/eula to access Wiley’s ebook EULA.

You might also like