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
RedHat provides an video about Creating a Local Repository and Sharing With Offline Systems (8min, 2018).
“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?
It is definitively /etc/fstab and not /dev/fstab as written. Well done!
Could you explain me what this tar cvf – . | (cd /repo; tar xvf -) would do?
Will not cp -r /mnt/ /repo do?
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, …
Can we use “#cp -rp /mnt/Packages/* /repo” to preserve the file attributes?
The tar command already preserves the file attributes.
Furthermore, by using the cp command you could miss some files starting with a .
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
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.
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.
During the exam, you will have all the details to setup a repository, if you need to. Don’t worry.
I passed the RHCSA exam today! And I have you and your great site to thank for your great assistance
I’m happy for you.
/dev/cdrom /repo iso9660 loop 0 0
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
I haven’t tried this configuration, but if it seems to work why you wouldn’t use it!
Yeah why not. But I think I still need to follow loop instead of defaults for best practice. Thank you!
Alternatively after running the createrepo command, you can run this command which will automatically generate the .repo file inside /etc/yum.repos.d
replace the content of file:///..with http://… or ftp://….
This way you don’t have to type or memorize anything
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
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.
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?
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.
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.
Personally, I prefer to copy all the files. There are perhaps other options.
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.
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.
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.
This, or you can try using yum priorities (see the yum-plugin-priorities package).
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.
I used a modified Rsync Script from the above.
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!!!
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).