The Industry Standard in IT Infrastructure Monitoring Purpose This document is intended to explain how to convert the stock VMware virtual machine image of Nagios XI to a VirtualBox one and load that image within VirtualBox. Target Audience This document is intended for use by Nagios XI customers who wish to run Nagios XI within VirtualBox rather than VMware and for whatever reason need to do the conversion themselves, or Nagios Enterprises, Nagios Authorized Resellers, or other Nagios Partners who wish to prepare a VirtualBox image for customers. Prerequisites / Assumptions These instructions assume that you have the following already: VirtualBox installed, either the commercial or OSE version A Linux / UNIX host environment (including BSD or Mac OS X) Approximately 80GB of available disk space The VMware image of Nagios XI, unzipped (available from the Nagios Library) The VirtualBox binaries are in your shell PATH and libraries in LD_LIBRARY_PATH. In distributions using a package manager such as Ubuntu, Debian, Fedora, or CentOS this should be done automatically, but in manual / custom installations you may need to do this yourself. Some type conventions Plain text Indicates usual instructions and descriptions Italics Indicates file and directory names, as well as references to utilities within descriptions Bold Indicates labels, such as on buttons Constant Width Indicates commands, options, switches, and command output Constant Width Bold Indicates text which should be literally typed by the user, usually when specifically prompted for Constant Width Italic Indicates text that should be replaced with user-supplied values Shell prompts ending in $ - Indicates that commands are being executed with normal user permissions Shell prompts ending in # - Indicates that commands are being executed as root, in whatever fashion is appropriate for your distribution and environment (eg. Some log in as root directly, some log in as user and use su -, and others use sudo command or sudo -s.) Converting the.vmdk to a raw file So far you have the Nagios XI image in a VMware format,.vmdk. In order to get it to VirtualBox's format, you must go through an intermediary step of a raw file. To do this, first, you will need to install qemu on the host system, which is actually a virtualization tool itself, but you'll only be using it for its conversion capabilities. On Debian and Ubuntu systems, this is done with: # apt-get install qemu All of the work can be done within the directory Nagios XI unzipped to, provided you have access rights to it and there is sufficient disk space on that partition (including user quotas). Go there now: $ cd nagiosxi/ You should see a number of files, ending in.vmdk,.vmsd,.vmx,.vmxf, and.nvram. You are only concerned with nagiosxi.vmdk. If you don't mind using an extra 3.0 GB of disk space, it's a good idea to make a backup of this before you proceed: $ cp nagiosxi.vmdk nagiosxi.bkup.vmdk Page 1
Now you're ready to convert the vmdk to a raw binary image. This will take a long time (dependent primarily on your hard drive speed), and will result in a 60GB file. This is because the vmdk is compressed to only need the amount of space that is actual used, but the raw image will be the total size of the virtual partition, including blank space, which is currently set at 60GB. $ qemu-img convert nagiosxi.vmdk nagiosxi.bin [ Note: The above command won't work properly if your Nagios VM directory is mounted from a remote location via GVFS, returning a rather unhelpful error about not being able to convert for format raw. It is fine for local files as well as NFS mounts. ] Converting the raw file to.vdi You are now ready to convert the raw file to VirtualBox's format,.vdi. $ VBoxManage convertfromraw nagiosxi.bin nagiosxi.vdi This will again take some time, and as of this writing produces a 14GB resultant file. Note that if you accidentally swap the order of the input and output file VBoxManage will complain File= nagiosxi.vdi open error: File not found. If you have worked with VBoxManage in the past, you may have seen the command option convertdd; convertfromraw is simply the newer replacement for that command, and convertdd is now mapped to it. Importing the image into VirtualBox To now use this.vdi disk image, you need to inform VirtualBox that you wish to assign it to a new virtual machine. So, load up VirtualBox and if it's your first time using it you'll see a Welcome screen like this: Click New to enter the new virtual machine image wizard, which will look like this: Page 2
Click Next. You will now be prompted to make up a name for your new VM, and to provide some information about what type of guest operating system it is. For the latter, select Linux and Red Hat, as shown below: Then, select Next again. The following screen will ask how much RAM you want to provision for the VM. This will depend on your organization's resource needs ultimately, but for now at least you can accept the default (384MB) and click Next again. The screen after that will ask what disk to use for the VM. Select Use existing disk, and click the folder icon to specify which one. This will bring to a screen showing VirtualBox's existing media definitions, which if you don't have any other machines defined, will look like this: You want to use the Add button to tell it about your existing.vdi image. That will bring up a standard file browser, in which you can navigate to your nagiosxi/ directory and select the nagiosxi.vdi file, resulting in a media listing like this: Page 3
Choosing Select now will bring back to the previous screen, with the disk name filled in: Select Next again and you will arrive at a confirmation summary. If everything looks good, click Finish to exit the wizard and return to the main VirtualBox screen, now with your Nagios XI virtual machine added: You'll now need to click the Settings button and change one option for your VM before starting it. Under the System tab on the left, and the Motherboard tab in the main area, under Extended Features, you want to check the box for Enable IO APIC. Not doing so appears to cause the VM to hang during boot, although the reason for this is unknown to the author at the time of writing. Page 4
Now click OK to return to the main screen. You are now ready to boot the VM, by clicking the Start button in the VirtualBox manager. This will give you a VirtualBox splash screen, followed by the CentOS Grub countdown, then the system loading messages, and finally a login prompt: Page 5
Shrinking the.vdi to used space only As you saw earlier, the.vdi is currently 14GB in size, although only a fraction of that is actually used. This is because of the way the internal filesystem works, leaving space still technically populated even when unused, which confuses the compression efforts of virtualization solutions. So, the next step is to clear out that unused space to actually be blank, using a utility called zerofree. This part is done within the actual virtual machine, not on the host system. The [root@localhost ~] and sh-3.2 prompt prefixes will remind you of this. First you'll need to log in, using the default credentials of user: root, password: nagiosxi. At the ensuing prompt, execute the following to download the zerofree package for CentOS 5, taking care not to include any space or line break in the URL even though it is wrapped here: [root@localhost ~]# wget http://download.fedora.redhat.com/pub/epel/5/i386/zerofree-1.0.1-5.el5.i386.rpm [ Note that this command could change in the future if the Nagios XI VM is upgraded to a new version of CentOS. ] Next, install the package: [root@localhost ~]# rpm -i -nosignature zerofree-1.01-5.e15.i386.rpm Actually using this tool will require the root partition to be mounted in read-only mode. To accomplish that, you need to first stop all running services. (Otherwise, the step after this will return an error, mount: / is busy.) To do this, it is easiest to first switch to runlevel 1, as this will stop all of the normal built-in system services: [root@localhost ~]# telinit 1 This will bring you to a different prompt, at which you still need to stop the Nagios-specific services. sh-3.2# service nagios stop sh-3.2# service npcd stop sh-3.2# service ndo2db stop You are now ready to remount the root partition in read-only mode. sh-3.2# mount -n -o remount,ro -t ext3 /dev/mapper/volgroup00-logvol00 / Now, you will run the zerofree utility directly on the device which is used for that partition, zeroing out all bits in space marked as being unused on the filesystem. (The reason for the unusual device name is that the VM is using logical volumes internally.) Again, this will take a little while. sh-3.2# zerofree /dev/mapper/volgroup00-logvol00 Once this is done, you can shut down the virtual machine, as the next step will be back on the host system. sh-3.2# shutdown -h now Now you will need to tell VirtualBox to shrink the image to adapt to the new zeroed out space. When invoking this command, you will need the full path to the.vdi file, which can be obtained by appending the file name to the output of pwd (print working (current) directory). The path in the example matches the author's system, but will be different for yours. $ VBoxManage modifyhd --compact /mnt/anthony/documents/work/nagios/nagiosxi/nagiosxi.vdi Further deployment In order to run the converted and shrunk image on additional hosts, simply repeat the steps within the Importing the image into VirtualBox section. Page 6