Creating Virtual RedHat/CentOS/Scientific Linux/Fedora Appliances For KVM With BoxGrinder (Fedora 17)
Version 1.0
Author: Falko Timme
Follow me on Twitter
BoxGrinder is a tool that allows you to build virtual machines (with RedHat, CentOS, Scientific Linux or Fedora as the OS) for multiple virtualization techniques. Currently it supports KVM, VMware, Amazon EC2, VirtualBox, and VirtualPC. This tutorial shows how to use BoxGrinder to create a CentOS 6 KVM guest on Fedora 17 and also how to deploy it to a remote KVM host.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
Currently BoxGrinder is available as a package for Fedora 17, but not for RedHat/CentOS/Scientific Linux 6. Therefore I'm using a Fedora 17 system to create a CentOS KVM guest which you can run locally (if you use Fedora 17 as your KVM platform) or transfer to a remote KVM host (you could do this manually by transferring the image file and the XML definition file of the guest to the remote host, but BoxGrinder also has a built-in feature that allows you to do this automatically).
2 Installing BoxGrinder
Log into your Fedora system as the root user and run:
yum install rubygem-boxgrinder-build
3 Using BoxGrinder
You can find out about BoxGrinder's plugins and supported guest operating systems by running:
boxgrinder-build --version
[root@localhost ~]# boxgrinder-build --version
BoxGrinder Build 0.10.4
Available os plugins:
- rhel plugin for Red Hat Enterprise Linux
- centos plugin for CentOS
- fedora plugin for Fedora
- sl plugin for Scientific Linux
Available platform plugins:
- vmware plugin for VMware
- ec2 plugin for Amazon Elastic Compute Cloud (Amazon EC2)
- virtualbox plugin for VirtualBox
- virtualpc plugin for VirtualPC
Available delivery plugins:
- s3 plugin for Amazon Simple Storage Service (Amazon S3)
- cloudfront plugin for Amazon Simple Storage Service (Amazon S3)
- ami plugin for Amazon Simple Storage Service (Amazon S3)
- sftp plugin for SSH File Transfer Protocol
- ebs plugin for Elastic Block Storage
- local plugin for Local file system
- elastichosts plugin for ElasticHosts
- openstack plugin for OpenStack
- libvirt plugin for libvirt Virtualisation API
[root@localhost ~]#
KVM is supported by default, that's why it's not listed as a plugin.
To learn how to use BoxGrinder, you can type:
boxgrinder-build -h
[root@localhost ~]# boxgrinder-build -h
Usage: boxgrinder-build [appliance definition file] [options]
A tool for building VM images from simple definition files.
Homepage:
http://boxgrinder.org/
Documentation:
http://boxgrinder.org/tutorials/
Examples:
$ boxgrinder-build jeos.appl # Build KVM image for jeos.appl
$ boxgrinder-build jeos.appl -f # Build KVM image for jeos.appl with removing previous build for this image
$ boxgrinder-build jeos.appl --os-config format:qcow2 # Build KVM image for jeos.appl with a qcow2 disk
$ boxgrinder-build jeos.appl -p vmware --platform-config type:personal,thin_disk:true # Build VMware image for VMware Server, Player, Fusion using thin (growing) disk
$ boxgrinder-build jeos.appl -p ec2 -d ami # Build and register AMI for jeos.appl
$ boxgrinder-build jeos.appl -p vmware -d local # Build VMware image for jeos.appl and deliver it to local directory
Options:
-p, --platform [TYPE] The name of platform you want to convert to.
-d, --delivery [METHOD] The delivery method for selected appliance.
-f, --force Force image creation - removes all previous builds for selected appliance. Default: false.
Plugin configuration options:
-l, --plugins [PLUGINS] Comma separated list of additional plugins. Default: empty.
--os-config [CONFIG] Operating system plugin configuration in format: key1:value1,key2:value2.
--platform-config [CONFIG] Platform plugin configuration in format: key1:value1,key2:value2.
--delivery-config [CONFIG] Delivery plugin configuration in format: key1:value1,key2:value2.
Logging options:
--debug Prints debug information while building. Default: false.
--trace Prints trace information while building. Default: false.
-b, --backtrace Prints full backtrace if errors occur whilst building. Default: true if console log is set to debug or trace, otherwise false.
Common options:
--change-to-user Change from root to local user after the OS plugin completes.
--help Show this message.
--version Print the version.
[root@localhost ~]#
Basically it works like this: you create an appliance definition file (e.g. centos.appl) in a directory (e.g. /usr/local/appliances):
mkdir /usr/local/appliances
cd /usr/local/appliances/
vi centos.appl
This appliance definition file describes our KVM appliance (like name, operating system (currently RedHat, CentOS, Scientific Linux, and Fedora are supported), root password, number of CPUs, RAM, partitions (numbers mean size in GB), and packages that BoxGrinder will install automatically when it creates the virtual machine):
name: centos-6-lamp summary: CentOS 6 LAMP version: 1 release: 0 os: name: centos version: 6 password: secret hardware: cpus: 2 memory: 1024 partitions: "/": size: 4 "/var": size: 10 "swap": size: 0.5 packages: - @core - @web-server - @mysql - acpid default_repos: true # default is true |
Packages that begin with an @ are not single packages, but package groups. You can find out about available package groups by running
yum grouplist -v
on a system that runs the same operating system that you want to use in your appliance.
The names of the packages groups are in parentheses.
Packages not beginning with an @ sign are not package groups, but exactly that single package.
BoxGrinder will always install the latest available version of an operating system, i.e., if you specify CentOS 6, it means it will instal 6.3 (6.3 being the latest CentOS version at the time of this writing).
You can now call BoxGrinder like this (make sure you are in the same directory that centos.appl is located in):
boxgrinder-build centos.appl
By default, BoxGrinder creates raw images. After the build, you can find the image and the XML definition in the directory build/appliances/<arch>/<osplugin>/<osversion>/<name>/1.0/<osplugin>-plugin/ - in my case, this translates to build/appliances/i686/centos/6/centos-6-lamp/1.0/centos-plugin/:
ls -l build/appliances/i686/centos/6/centos-6-lamp/1.0/centos-plugin/
[root@localhost appliances]# ls -l build/appliances/i686/centos/6/centos-6-lamp/1.0/centos-plugin/
total 863308
-rwxr-xr-x. 1 root root 15569256448 Oct 5 11:44 centos-6-lamp-sda.raw
-rw-r--r--. 1 root root 475 Oct 5 11:42 centos-6-lamp.xml
[root@localhost appliances]#
To create a appliance in qcow2 format, you'd use
boxgrinder-build centos.appl --os-config format:qcow2
instead:
ls -l build/appliances/i686/centos/6/centos-6-lamp/1.0/centos-plugin/
[root@localhost appliances]# ls -l build/appliances/i686/centos/6/centos-6-lamp/1.0/centos-plugin/
total 1628824
-rw-r--r--. 1 root root 784007168 Oct 5 11:52 centos-6-lamp-sda.qcow2
-rw-r--r--. 1 root root 481 Oct 5 11:51 centos-6-lamp.xml
[root@localhost appliances]#
You could now take the image and copy it to /var/lib/libvirt/images on your KVM host and the XML file and copy it to /etc/libvirt/qemu/ on the KVM host, open virsh and define a new virtual machine from the XML file, but instead of doing this manually, you can make BoxGrinder do this for you (with the -d switch):
For example, if you want to add the appliance to your local KVM installation, run:
boxgrinder-build centos.appl --os-config format:qcow2 -d libvirt
This would copy the image directly to the /var/lib/libvirt/images directory...
ls -l /var/lib/libvirt/images
[root@localhost appliances]# ls -l /var/lib/libvirt/images
total 765636
-rw-r--r--. 1 root root 784007168 Oct 5 11:55 centos-6-lamp-sda.qcow2
[root@localhost appliances]#
... and the XML file to the /etc/libvirt/qemu/ directory:
ls -l /etc/libvirt/qemu/
[root@localhost appliances]# ls -l /etc/libvirt/qemu/
total 8
-rw-------. 1 root root 2135 Oct 5 11:55 centos-6-lamp-1-0-centos-6-i686-raw.xml
drwx------. 3 root root 4096 Jun 28 15:52 networks
[root@localhost appliances]#