Centos Base Image
With these steps you can create a centos base image which you can use for a xen instance or as an image for systemimager. All steps have to be executed as root.
Set the root of the centos installation.
rootdir="/var/lib/systemimager/images/centos"
Create necessary directories.
mkdir -p $rootdir/{etc,dev,proc,sys,var/lock/rpm}
Create a basic fstab file.
The basic entries are necessary for the installation of some packages, you can add your system specific entries now or after the installation.
vi $rootdir/etc/fstab
The content of /etc/fstab:
/dev/sda1 / ext3 defaults 1 1
/dev/sda2 swap swap defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
Create necessary devices.
for i in console null zero ; do /sbin/MAKEDEV -d $rootdir/dev -x $i ; done
Create a yum config file which will be used for the installation.
vi /root/yum.centos.conf
The content of /root/yum.centos.conf:
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
exclude=*-debuginfo
gpgcheck=0
obsoletes=1
reposdir=/dev/null
[base]
name=CentOS 4 - $basearch - Base
baseurl=http://ftp.belnet.be/packages/centos/4/os/i386
enabled=1
[updates-released]
name=CentOS 4 - $basearch - Released Updates
baseurl=http://ftp.belnet.be/packages/centos/4/updates/i386
enabled=1
Install all packages of a very minimal base image.
yum -y -c /root/yum.centos.conf --installroot=$rootdir groupinstall Core
Install some extra necessary packages to the base image.
yum -y -c /root/yum.centos.conf --installroot=$rootdir install yum
Optional: disable some really unnecessary services.
for package in netfs kudzu; do chroot $rootdir chkconfig $package off; done
Optional: Store the passwords in /etc/shadow instead of /etc/passwd.
chroot $rootdir pwconv
For Xen virtual machines: Copy the necessary modules, the modules must match the kernel you will use voor the xenU’s.
cp -rv /lib/modules/*xen* $rootdir/lib/modules/
For Xen virtual machines: Disables the TLS to improve the performance of you virtual machine.
mv $rootdir/lib/tls $rootdir/lib/tls.disabled
For physical machines: Prepare for grub.
vi $rootdir/boot/grub/grub.conf
ln -s grub.conf $rootdir/boot/grub/menu.lst
ln -s ../boot/grub/grub.conf $rootdir/etc/grub.conf
For physical machines: The content of /boot/grub/grub.conf
You should update the version of the kernel and some other rules to match you configuration.
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.9-34.0.2.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-34.0.2.EL ro root=/dev/sda1 quiet
initrd /initrd-2.6.9-34.0.2.EL.img
For physical machines: Copy your custom grub splash image.
cp /path/to/splash.xpm.gz $rootdir/boot/grub/splash.xpm.gz
Network: Create the main network file.
vi $rootdir/etc/sysconfig/network
Network: The content of /etc/sysconfig/network
You should update the entries between < >.
NETWORKING=yes
NOZEROCONF=yes
HOSTNAME=<full.hostname.be>
GATEWAY=<gateway>
Network: Create the resolv.conf file.
vi $rootdir/etc/resolv.conf
Network: The content of /etc/resolv.conf
You should update the entries between < >.
search <hostname.be>
nameserver <ip-of-dns-server>
Network: Create the hosts file.
vi $rootdir/etc/hosts
Network: The content of /etc/hosts
You should update the entries between < >.
127.0.0.1 localhost.localdomain localhost
127.0.0.1 <full.hostname.be> <full>
Network: Create the ifcfg file.
vi $rootdir/etc/sysconfig/network-scripts/ifcfg-eth0
Network: The content of /etc/sysconfig/network-scripts/ifcfg-eth0
You should update the entries between < >.
DEVICE=eth0
BOOTPROTO=static
IPADDR=<ip>
NETMASK=<netmask>
ONBOOT=yes
TYPE=Ethernet
Unmount /proc:
umount $rootdir/proc
Your base-image is ready… enjoy!
Notes:
- I added the creation of the $rootdir/var/lock/rpm directory otherwise yum will fail with an error that it cannot create a transaction lock.
- I changed the groupinstall from base to Core, which gives a much smaller (but incomplete) baseimage.