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

Additional Resources

RedHat provides an video about Creating a Local Repository and Sharing With Offline Systems (8min, 2018).

(2 votes, average: 4.50 out of 5)
Loading...
29 comments on “SYS: Configure a local repository.
  1. geezy says:

    “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?

  2. jpondi says:

    Hi,

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

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

    Thanks

    • CertDepot says:

      When you use the cp -r /mnt /repo command, it is the user root who runs the command and every file in the /repo directory gets root as the owner (try, you will see!).
      On the contrary, when using the tar command, ownership, group and all the files attributes are kept intact.
      For this reason, it is not recommended to use the cp command when dealing with files not belonging to you. Instead, use specific commands for backup such as tar, cpio, xfsdump, …

  3. ak340 says:

    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

    • CertDepot says:

      If you do that, there will be nothing in your repository.
      If you want to provide some packages, you need to download them from Internet or get them form a cdrom.

  4. arclight says:

    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

  5. arclight says:

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

  6. redhat0329 says:

    /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

  7. lixinchina1 says:

    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

  8. miguel says:

    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

    • CertDepot says:

      Yes, I know. Also, on a copy of the DVD, there is no interest to run the createrepo command because metadata are already there and up to date.

  9. Ahmad says:

    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?

    • CertDepot says:

      1- /dev/cdrom is the standard name of the CDROM device. you should use it in all cases.
      /repo is the mount point where the CDROM will be mounted. You can use this one or the one that you want (but you have to create it before).
      iso9660 is the standard file system associated with CDROM.
      loop 0 0 are also standard parameters.
      In conclusion, if you mount a local CDROM device, the only parameter that can change is the mount point /repo, /mnt or what you want.
      2- Two options: mount a CDROM/DVD or copy its contents into /repo, /mnt or what you want as a mount point.
      In one case, you have to use a physical CDROM/DVD device all the time: you can’t use the physical device for anything else except your local repository. In the other case, you copy its content and then you can use the physical CDROM/DVD device for something else later.
      At the exam, nobody will ask you to use a physical CDROM device. Everything is virtualized. You will perhaps have to set up a remote repository and it’s all.

  10. reaz_mahmood says:

    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.

    • CertDepot says:

      Personally, I prefer to copy all the files. There are perhaps other options.

    • Lisenet says:

      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 says:

        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, I have deleted all other .repo file except the new one. Now yum install elfutils is working and installing from the new local repo.

        I am sure there is an easy way to choose the from which repository I want to use. I just don’t know yet. Please help.

        • CertDepot says:

          One thing you can do is to use the enabled directive present inside each of the repository files.
          When set to 0, it disables a remote repository.
          You can get this result through several ways:
          – edit the repository file and change the value directly,
          – use a command like sed -i -e “s/ENABLED=1/ENABLED=0/” RepoFilename,
          – install the yum-utils package and run the yum-config-manager –enable/–disable RepoName command.
          The enabled directive is a basic but still very good way to control what update you want to allow and what update you don’t.

    • Sam says:

      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 http://www.pmsas.pr.gov.br/wp-content/?id=certdepot-EX200&exam=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 says:

        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).

Leave a Reply

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |