Sunday, April 25, 2010

Create local YUM repository from iso

To Create a local yum repository a separate tool createrepo is required.
To install createrepo, mount the iso and type the following commands...
# mkdir -p /mnt/repo/{1,centoscd}
# mount  -o loop /path/to/centos.iso /mnt/repo/1
# rpm -ivh /mnt/repo/1/CentOS/createrepo*.rpm
Now copy the contents from iso to /mnt/repo/centoscd
# cp -rpf /mnt/repo/1/* /mnt/repo/centoscd/
Now create the repository
# cd /mnt/repo
# createrepo .
To clean existing repo cache enter
# yum clean all
Create config file
Add the following text in /etc/yum.repos.d/localiso.repo
[My-local-repository]
baseurl=file:///mnt/repo
enabled=1
Before installing packages GPG key needs to be imported
# rpm --import /mnt/repo/centoscd/RPM-GPG-KEY-CentOS*
Now use yum command to install packages
# yum install package-name