SYS: Configure a local repository.

Share this link

Create a directory where packages will be stored:

# mkdir /repo

Two options: mount the distribution DVD or copy it into /repo.
To mount the DVD, edit the /etc/fstab file and add the following line:

/dev/cdrom /repo iso9660 loop 0 0

Then, mount the DVD:

# mount -a

To copy the DVD, type:

# mount -o loop /dev/cdrom /mnt
# cd /mnt
# tar cvf - . | (cd /repo; tar xvf -)
# cd /; umount /mnt

Optionally, update the repository structure (if new packages have been added):

# yum install -y createrepo
# createrepo /repo

Create the /etc/yum.repos.d/local.repo file and add the following lines:

[repo]
name=Repo - Base
Baseurl=file:///repo
enabled=1

Note: If you don’t remember the syntax, read the yum.conf man page.

Clean up the yum cache:

# yum clean all
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Leave a Reply

29 Comments on "SYS: Configure a local repository."

Notify of
Sort by:   newest | oldest
geezy
Member
geezy

“To mount the DVD, edit the /dev/fstab file and add the following line:”

I don’t have a /dev/fstab. Is that supposed to be there already or do you mean /etc/fstab?

jpondi
Member
jpondi

Hi,

Could you explain me what this tar cvf – . | (cd /repo; tar xvf -) would do?

Will not cp -r /mnt/ /repo do?

Thanks

ak340
Member
ak340

Hi CertDepot, could you please provide enlightenment why we need to mount the cdrom?

I can create a repository by just issuing createrepo /dir_name

arclight
Member
arclight

Sorry for some more questions (from previous topic), but it would be great to have this clarified, if possible: In the exam scenario, where there would be no .repo available, would it reasonable to assume that the link would be provided eg. dvd or http link in the question? Or would they exist?

This question would be important given that other questions would rely on the availability of the yum packages.

thanks again

arclight
Member
arclight

I passed the RHCSA exam today! And I have you and your great site to thank for your great assistance

redhat0329
Member
redhat0329

/dev/cdrom /repo iso9660 loop 0 0

Hi CertDepot,

What will happen if instead of ‘loop’ you have inputted ‘defaults’?
I’m using ‘defaults’ value on /etc/fstab and it seems that all is working fine while installing the packages.

Btw, I’m using iso image rhel7 on my vmware test environment. Please see below sample. Thanks

/dev/cdrom /repo iso9660 defaults 0 0

lixinchina1
Member
lixinchina1

Alternatively after running the createrepo command, you can run this command which will automatically generate the .repo file inside /etc/yum.repos.d

yum-config-manager –add-repo=file:///data/iso

replace the content of file:///..with http://… or ftp://….

This way you don’t have to type or memorize anything

miguel
Member
miguel

Hi Certdepot, I think we cannot use createrepo if it’s mounted to /dev/cdrom because /dev/cdrom is not writable. The only option is to copy from the DVD to the /repo folder

Ahmad
Member
Ahmad

Hi

1-What do you mean by iso9660 in the below line :

/dev/cdrom /repo iso9660 loop 0 0

Should I use the same line if I asked to configure local repository?

Plus, should I use the above same config in the exam (identically)

or is there some variable that has to be changed?

2- You mentioned two options: mount the distribution DVD or copy it into /repo.

What do you mean? Should I use only one option or use both?

reaz_mahmood
Member
reaz_mahmood

To create a local repo from the centos iso file do I need to copy all files in the isoimage or only files from the packages directory to the repo directory.

Lisenet
Member

I prefer to leave the ISO file mounted, make it a permanent mount and use the mountpoint for the yum .repo file. This way you don’t have to copy anything and save a few gigs of disk space.

reaz_mahmood
Member
reaz_mahmood
Using the iso mounting directory for repo directory seems like a very good idea, specially in virtual lab environment. So, I have created the .repo file for the local repository. Then my “yum repolist” shows the new repo including three centos defaults, which were present during installation. Now, how do I test my new repository to check whether packages are actually installing from it? I tried “yum install elfutils” (by switching off internet access to force it to use local repo), but the yum command fails because it could not access the url for base repo. As an extreme measure,… Read more »
Sam
Member
Sam

The set up I eventually used was an mixture of an external usb harddrive and an Internal hardrive, with a FTP server as opposed the http server. Updates were blocked from the external www or ftp sites for the virtual machine.
(ref https://www.certdepot.net/rhel7-set-local-repository-lab/)

I used a modified Rsync Script from the above.

My Reasoning.
Each Version of CentOS needs update, security update, and this should be done any way.

Multiple versions of CentOS. As there’s no idea which version is available on the exam, and it is wise to a question/topic under each version. I learned this the hard way!!!

Lisenet
Member

Ah, I thought you were setting up an exam lab with a locked up RHEL/CentOS version (this requires no updates really). I had 3 VMs configured, RHEL 7.0, 7.1 and 7.2 with ISO as a repo.

If you want to do it properly (with updates, security patches tracking etc), then check out Spacewalk (RH Satellite 5) or Katello (RH Satellite 6).

wpDiscuz

RHCSA7: Task of the day

Allowed time: 3 minutes.
Check that you've got no SELinux policy violations.

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a default secure MariaDB database called maria and back up the database with mysqldump.

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...

Recent Comments