Building a Sandbox VM for DB2
There are plenty of things that I want to try in a sandbox VM before I let them anywhere near even a development environment. Even if I didn’t use it constantly for blogging, I would still need it for trying things to see how they work before advising clients. These instructions should never be used to build a development, test, qa, or any other environment. More robustness is required for any other kind of environment.
The first thing to know about building a VM is that you’re a user doing admin-level tasks with one or more pieces of software. Things are going to go wrong. You’re likely to have to Google errors and try again. Building a new VM can be frustrating – patience, troubleshooting, and perseverance are all called for.
First, Build a Linux VM
The instructions are going to vary here depending on your distribution. For sandboxes, Ubuntu is free and easy. You can download it here: https://www.ubuntu.com/download/desktop
This version comes with all the desktop stuff, but honestly, being able to run a web browser can be useful from time to time on a sandbox. The download comes as an .iso file. You can use your favorite (free or not) VM software to create a new VM. I used to use Oracle Virtual Box, but recently switched to VMWare Workstation Player, and am enjoying it a lot. You do not need a paid version of the VM software simply to create VMs for your own use. You may need it to do anything more advanced than that or to share VMs. You can download VMWare Workstation Player here: http://www.vmware.com/products/player/playerpro-evaluation.html
I’m keeping the instructions general so whatever software you have available can be used.
Once you have the VM software installed, you can create a new VM, and specify the ISO of Ubuntu or other Linux distribution to install on the VM. The choices are fairly simple for VMWare, and straight forward. You will also want to install the VMWare (or Virutal Box) tools on on the VM. This will make nifty things like easy resizing and copy/paste to/from the VM work well and mostly seamlessly. You will have to choose how much memory and disk to give the VM – your choices there will depend on what computer you’re installing it on and what else you’re running there. Remember to leave some memory for the host OS. I generally do 4 GB, but I think you could get by with 2. I have a laptop with 16 GB of memory and never really run more than 2 VMs at once (one Windows and one Linux) in addition to the host operating system.
There are several ways to go here. Note that any licensing statements are the author’s opinion at the time this article was written, and should be verified with IBM. They also may change over time.
The first is completely free – DB2 Express-C. It has many of the features of DB2, but is limited to 2 cores, 16 GB of memory, and 15 TB of data. The nice thing about this is that you don’t have to pay for it, and it’s a permanent install. You can download Express-C here:
DB2 Trial Version (from Fix Pack)
DB2 Fix Packs are freely downloadable and include a full image of DB2. You can download the fixpack and install from it, but these are only try and buy licenses, meaning they expire after 90 days. And by expire, I mean become unusable other than to apply a license file. Fixpacks are available here, with your free IBM ID: http://www-01.ibm.com/support/docview.wss?uid=swg27007053
Entitled DB2 from Passport Advantage
If you have DB2 Developer Edition or other entitled versions from IBM that include the ability for you to use them in a sandbox environment, you can download them from Passport Advantage. You’re likely to also have to download the Quick Start/Activation kit as well and apply the license file.
Business Partner Software Access Catalog
If you work for an IBM business partner, there’s something called the Software Access Catalog. Make sure you’re using the software in an approved manner if you download it from this source. The nice thing about this is that you have access to complete versions of every edition of DB2. IBM relies on you, as a business partner, to ensure you’re using the software in a legal way.
Transferring Files to the VM
You can download directly to your VM using a web browser there, or download to the host machine (my laptop, in my case), and create a shared folder. I find a shared folder quite useful over and over again, so I create one whenever I create a VM. I have one that I share with all my VMs to keep things simple. It’s fairly easy to do this in the various VM softwares. Here is what it looks like for my VMWare player VM:
You’ll have to have the vm software’s tools installed on both the host and the VM for this to work.
However you get it, the installation is really similar. I’m a command-line gal, so this is my preferred method:
- Create a user for the db2instance owner and a group to be the sysadm group:
$ sudo groupadd -r db2iadm1 $ sudo mkdir /db2home $ sudo mkdir /db2home/db2inst1 $ sudo mkdir /db2home/db2fenc1 $ sudo useradd -d /db2home/db2inst1 -g db2iadm1 -r db2inst1 $ sudo useradd -d /db2home/db2fenc1 -g db2iadm1 -r db2fenc1 $ sudo chown db2inst1:db2iadm1 /db2home/db2inst1 $ sudo chown db2fenc1:db2iadm1 /db2home/db2fenc1
- Unzip and untar the DB2 install file, wherever you have it. Name may vary. In my case (installing from fixpack code):
$ gunzip v11.1.1fp1_linuxx64_universal_fixpack.tar.gz $ tar -xvf v11.1.1fp1_linuxx64_universal_fixpack.tar
- Install prerequisite packages
$ sudo apt-get update $ sudo apt-get install libaio1 $ sudo apt-get install binutils $ sudo apt-get install libpam0g:i386 $ sudo apt-get install libstdc++6:i386
- There’s a problem with the install for DB2 11.1 fix/mod pack 1 on Ubuntu. To prevent encountering it at all, install rpm (this is not a listed or checked-for dependency):
$ sudo apt-get install rpm
See my blog entry on this issue if you want more information about it.
- Run db2prereqcheck to verify no other packages are needed. The version number will need to be changed based on what you’re installing. I’m doing 11.1, fix/mod pack 1 (sample output included):
sudo ./db2prereqcheck -v 184.108.40.206 ========================================================================== Checking prerequisites for DB2 installation. Version "220.127.116.11". Operating system "Linux" Validating "Linux distribution " ... Required minimum "UBUNTU" version: "14.04" Actual version: "16.04" Requirement matched. Validating "kernel level " ... Required minimum operating system kernel level: "2.6.16". Actual operating system kernel level: "4.4.0". Requirement matched. Validating "C++ Library version " ... Required minimum C++ library: "libstdc++.so.6" Standard C++ library is located in the following directory: "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21". Actual C++ library: "CXXABI_1.3.1" Requirement matched. Validating "32 bit version of "libstdc++.so.6" " ... Found the 32 bit "/usr/lib/i386-linux-gnu/libstdc++.so.6" in the following directory "/usr/lib/i386-linux-gnu". Requirement matched. Validating "libaio.so version " ... DBT3553I The db2prereqcheck utility successfully loaded the libaio.so.1 file. Requirement matched. Validating "libnuma.so version " ... DBT3610I The db2prereqcheck utility successfully loaded the libnuma.so.1 file. Requirement matched. Validating "/lib/i386-linux-gnu/libpam.so*" ... Requirement matched. DBT3533I The db2prereqcheck utility has confirmed that all installation prerequisites were met.
- Switch to root, change to the directory where db2_install is, and run it (note that IBM says db2setup is a better choice, so you may want to use it instead)
sudo su - ./db2_install
It will ask you to verify agreement with the license, for the install directory (take the default), to specify SERVER installation, and whether to install pureScale (no).
You want to run this as root instead of with sudo. There can be issues with installs when they’re run with sudo
- Review the install output carefully to see if it has succeeded.
- Once the install has completed successfully, create the instance (still as root):
cd /opt/ibm/db2/V11.1/instance ./db2icrt -u db2fenc1 db2inst1
- Su to the instance, and set up profile, if it’s not already set up:
su - db2inst1 vi .bash_profile
Add the following lines to the .bash_profile if they do not already exist:
if [[ -f /db2home/db2inst1/sqllib/db2profile ]] then . /db2home/db2inst1/sqllib/db2profile fi
- Perform basic validation and create the sample database:
$ db2start 01/05/2017 15:49:03 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful. $ db2level DB21085I This instance or install (instance name, where applicable: "db2inst1") uses "64" bits and DB2 code release "SQL11011" with level identifier "0202010F". Informational tokens are "DB2 v18.104.22.168", "s1612051900", "DYN1612051900AMD64", and Fix Pack "1". Product is installed at "/opt/ibm/db2/V11.1". $ db2val DBI1379I The db2val command is running. This can take several minutes. DBI1335I Installation file validation for the DB2 copy installed at /opt/ibm/db2/V11.1 was successful. DBI1339I The instance validation for the instance db2inst1 was successful. DBI1343I The db2val command completed successfully. For details, see the log file /tmp/db2val-170105_154911.log. $ db2sampl Creating database "SAMPLE"... Connecting to database "SAMPLE"... Creating tables and data in schema "DB2INST1"... Creating tables with XML columns and XML data in schema "DB2INST1"... 'db2sampl' processing complete. $
- Verify your licensing matches what you expect:
$ db2licm -l Product name: "DB2 Enterprise Server Edition" License type: "License not registered" Expiry date: "License not registered" Product identifier: "db2ese" Version information: "11.1"
If you have a separate license file, you can add it using the db2licm -a command.
The sample database created in these steps has sample objects in it that can be used for a variety of testing purposes. See DB2 Basics: The DB2 LUW Sample Database for more details.