Preparing CentOS in a VM for Oracle install

This guide details how to prepare Centos 5.3 for an Oracle install. I'm running CentOS inside a VM using KVM. Since I'm setting up a test Oracle install because I'm studying for an OCA, my database needs are pretty simple. An Oracle install requires a non-trivial amount of OS prep work, so I'm writing about the experience here.

Unfortunately, I wasn't able to get CentOS to read from a kickstart file off a floppy disk image. Instead I installed CentOS 5.3 with a generic set of packages (including GNOME), then added necessary packages using yum. The options I selected here are geared toward simplicity. If this were for a production instance, there are a lot of optimizations that could be done such as giving the VM direct access to a real hard drive.

To start with, I'll create two disk images to more accurately represent something I'd run in production. The OS is on a 6 Gig virtual disk, and Oracle will be installed on a 20 Gig disk.

$ qemu-img create -f qcow2 VCentOracle.qcow 6144M
$ qemu-img create -f qcow2 Oracle20G.qcow 20480M

Start the VM using the 6 Gig virtual disk and boot from the CentOS ISO. The networking options specify the guest's subnet and the IP address the host computer will use inside the guest's virtual network (these are the default options). Anaconda, the Red Hat/CentOS installer will decide how large a swap partition to create depending on the amount of RAM it detects. Ultimately, I plan on running this machine with 2 Gigs of RAM, so I'll start with 2 Gigs here.

$ kvm \
-hda VCentOracle.qcow \
-boot d -cdrom /path/to/iso/CentOS-5.3-x86_64-bin-DVD.iso \
-net nic -net user,net=10.0.2.0/8,host=10.0.2.2 \
-m 2048 -vga std -usb -usbdevice tablet &

I explicitly assigned the guest a fixed IP address of 10.0.2.1/8 with default gateway is 10.0.2.2 and DNS is 10.0.2.3 (both of these are provided by the host running KVM) My host's clock is set to UTC and it's interesting to note that KVM seems to pass the UTC time to the guest, unlike VirtualBox which passed the time in the local timezone to it's guests. Once CentOS has finished installing, I'll restart it with the parameters I'll want it to have when it actually runs Oracle: the 20 Gig hard drive.

$ kvm \
-hda VCentOracle.qcow \
-hdb Oracle20G.qcow \
-net nic -net user,hostfwd=tcp:127.0.0.1:2228-10.0.2.1:22,net=10.0.2.0/8,host=10.0.2.2 \
-m 2048 -vga std -usb -usbdevice tablet &

I installed CentOS 5.3 with a default set of packages (including GNOME) and disabled the firewall and SELinux in this sandbox. I made an oracle user on the guest belonging to default group dba. Starting from a generic CentOS 5.3 install, we need to add some packages needed for Oracle. They can be added with yum:

# yum install \
gcc \
libaio-devel \
libstdc++-devel \
sysstat \
elfutils-libelf-devel \
glibc-devel \
gcc-c++ \
compat-libstdc++-33.i386 \
compat-libstdc++-33.x86_64

We also need to update some runtime kernel parameters:

# /sbin/sysctl -w kernel.sem="250 32000 100 128"
# /sbin/sysctl -w kernel.shmall="2097152"
# /sbin/sysctl -w fs.file-max="6553600"
# /sbin/sysctl -w net.ipv4.ip_local_port_range="1024 65000"
# /sbin/sysctl -w net.core.rmem_default="4194304"
# /sbin/sysctl -w net.core.rmem_max="4194304"
# /sbin/sysctl -w net.core.wmem_default="262144"
# /sbin/sysctl -w net.core.wmem_max="262144"

They can be made permanent by adding them to /etc/sysctl.conf. It's never a bad idea to back up the original. There is only one line in the original that needs to be commented. The other settings can be appended to the bottom of the file.

# mv /etc/sysctl.conf /etc/sysctl.conf.orig
# cat /etc/sysctl.conf.orig | sed 's/^kernel.shmall/# kernel.shmall/' > /etc/sysctl.conf
# echo "
## Oracle modifications
#
kernel.sem = 250 32000 100 128
kernel.shmall = 2097152
fs.file-max = 6553600
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144
" >> /etc/sysctl.conf

Then I mounted the 20 gig drive image and created a filesystem. I'm going by Oracle conventions, so the data drive is mounted on /u01. mkfs asks for confirmation before laying a filesystem on an unpartitioned drive, but that shouldn't be a problem here. These commands should be run as root from inside the VM:

# /sbin/mkfs.ext3 /dev/hdb
# mkdir /u01
# echo "/dev/hdb /u01 ext3 defaults 1 1" >> /etc/fstab
# mount /u01

Now, make a target directory for the Oracle install and have it belong to the oracle user:

# mkdir -p /u01/app/oracle/product/11.1.0
# chown -R oracle:dba /u01/app

Copy the oracle database zip file into the new partition.

(From the host OS)
$ scp -P 2228 /path/to/zipfile/linux.x64_11gR1_database_1013.zip oracle@127.0.0.1:/u01/repository/

Once the file is unzipped, Oracle is ready to be installed.