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

1 Star2 Stars3 Stars4 Stars5 Stars (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

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

RHCSA7: Task of the day

Allowed time: 5 minutes.
Add 100MB of swap space to the machine using a new logical volume.

RHCE7: Task of the day

Allowed time: 15 minutes.
Configure a httpd server with a password protected directory under the /var/www/html/private directory.

Follow me on Twitter

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