Nombre total de pages vues

lundi 7 mars 2011

Customize CentOS



This is the method that I use to customize CentOS x86_64 distro. The objective of this operation is reducing image install used for server. We need those two ISO: CentOS x86_64 netinstall and CentOS x86_64 CD1. CentOS netinstall permits you to install a fresh mini install but there's yet in this way some packages that are useless for using on a server. On netinstall install, where only the vim package is selected , all the following packages are useless for me: wireless-tools xorg-x11-filesystem Deployment_Guide-fr-FR libXcursor rhpl libpng libjpeg libtiff cups-libs bitstream-vera-fonts fontconfig libXft libXext libXcursor libXrandr libXdmcp libXinerama ecryptfs-utils gtk2 libX11 libXi libXrender cairo trousers libXau libXfixes But some others useful packages for server were not installed: slocate autoconf automake rsync make imake m4 man yum-utils elinks telnet First, you have to do this fresh mini netinstall for create a local repository, because customising an ISO, for reducing it, essentially requires the removal of unnecessary packages. So when install is done. We create a mini local repository, with packages installed on this fresh install. Those that will be included into the custom ISO. How to:
# remove useless packages
yum remove wireless-tools xorg-x11-filesystem Deployment_Guide-fr-FR libXcursor rhpl libpng libjpeg libtiff cups-libs bitstream-vera-fonts fontconfig libXft
libXext libXcursor libXrandr libXdmcp libXinerama ecryptfs-utils gtk2 libX11 libXi libXrender cairo trousers libXau libXfixes -y

# install required packages
yum install slocate autoconf automake rsync make imake m4 man yum-utils elinks telnet yum-utils -y

# listing all packages and download them into temp directory
rpm -qa > /home/rpm.log && mkdir /tmp/rpm
for i in $(cat /home/rpm.log) ; do yumdownloader "$i" -y --destdir /tmp/rpm ; done

# To create repo (useless for customize CentOS ISO)
yum install createrepo -y
createrepo /tmp/rpm/
cd /etc/yum.repos.d/

vi local.repo

[localrepo]
name= CentOS Server $releasesever - My Local Repo
baseurl=file:///tmp/rpm/
enabled=1
gpgcheck=0
#gpgkey=file:////etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

:wq
Now packages are downloaded and we can start to build new ISO. To customize CentOS distro, we only need of the first CentOS CD among eight medias CD for normal install. Thus after downloading, mount the iso on this linux server and customise your distro. How to Second part :
# Create directories
mkdir /mnt/cdimages/
mkdir /mnt/cdimages/CentOS-5.5-x86_64
mkdir /mnt/cdimages/CentOS-5.5-x86_64-core

# Mount ISO
mount -t iso9660 -oloop,ro /home/CentOS-5.5-x86_64-bin-1of8.iso /mnt/cdimages/CentOS-5.5-x86_64

# Install needed packages
yum install mkisofs cdrecord

# Rsync ISO content to new CentOS minimal core 
rsync -av --exclude CentOS/ /mnt/cdimages/CentOS-5.5-x86_64/ /mnt/cdimages/CentOS-5.5-x86_64-core/
mkdir /mnt/cdimages/CentOS-5.5-x86_64-core/CentOS
cp -r /tmp/rpm/* /mnt/cdimages/CentOS-5.5-x86_64-core/CentOS/

# Edit comps.xml
cd /mnt/cdimages/CentOS-5.5-x86_64-core
wc -l repodata/comps.xml # 11418 repodata/comps.xml
grep "xml:lang" repodata/comps.xml | wc -l # 8811
grep -v "xml:lang" repodata/comps.xml > /tmp/no-lang.comps.xml
wc -l /tmp/no-lang.comps.xml # 2607 /tmp/no-lang.comps.xml
rm repodata/* -f
cp /tmp/no-lang.comps.xml repodata/comps.xml

# Test RPM dependencies
cd /mnt/cdimages/CentOS-5.5-x86_64-core/CentOS
mkdir /tmp/testrpmdb
rpm --initdb --dbpath /tmp/testrpmdb/
rpm --test --dbpath /tmp/testrpmdb/ -ivh *.rpm

echo $? # 0
du -sh /tmp/testrpmdb/ # 644K /tmp/testrpmdb/
rm -rf /tmp/testrpmdb

# Create repo
yum install createrepo -y
cd /mnt/cdimages/CentOS-5.5-x86_64-core
cat .discinfo
export discinfo=$(head -1 /mnt/cdimages/CentOS-5.5-x86_64-core/.discinfo)
echo $discinfo
createrepo -u "media://$discinfo" -g repodata/comps.xml /mnt/cdimages/CentOS-5.5-x86_64-core

# Create bootable ISO
export isofilename=/mnt/cdimages/CentOS-5.5-x86_64-core.iso

mkisofs -r -R -J -T -v \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-V "CentOS-5u5-core 64 bit" -p "CentOS_Custom" -A "CentOS-5u5-core 64 bit-2011/01/01" \
-b isolinux/isolinux.bin -c isolinux/boot.cat -x "lost+found" \
-o $isofilename /mnt/cdimages/CentOS-5.5-x86_64-core 
# 213685 extents written (417 MB)

# Implant MD5SUM in the ISO file
yum install mkcdrec
updatedb
locate implantisomd5
/var/opt/mkcdrec/bin/implantisomd5 $isofilename

## Use New CentOS ISO: /mnt/cdimages/CentOS-5.5-x86_64-core.iso
You can now try to install new virtual machine with this new ISO media boot to check that everything works perfectly.

1 commentaire: