Creating a local repository

YUMLINUXCENTOSREDHAT

2/17/2026

Sometimes we don't want to expose a server to the internet. Here is an example with CentOS 7 on how to create a local repository. In this case we are using Virtual Machine Manager (virt-manager). The steps will be similar with other virtualization software.

Step 1: "Insert" the ISO in Virtual Machine Manager

Think of this as physically putting the DVD into the drive.

  1. Open the Virtual Machine Manager window.

  2. Select your CentOS VM and click Open to see the console.

  3. Click the "light bulb" icon (Show virtual hardware details) in the toolbar.

  4. Look for SATA CDROM 1 (or similar) in the left sidebar.

  5. On the right, look for Source path. Click Browse.

  6. Locate your CentOS .iso file on your host computer and select it.

  7. Click Apply.

  8. Go back to the console view (the screen icon) and make sure the VM is running.

Step 2: Mount the DVD inside CentOS

Now that the "disc" is in the drive, Linux needs to "mount" it so it can read the files.

Run these commands as root (or with sudo):

Create a place for the DVD to live

# mkdir -p /mnt/disc

Mount the drive (usually /dev/sr0 is the first CD-ROM)

# mount /dev/sr0 /mnt/disc

Verify it worked: Run ls /mnt/disc. You should see folders like BaseOS and AppStream.

Step 3: Create the Repository File

yum looks for files ending in .repo inside a specific folder. We need to create a new one telling it to look at your /mnt/disc folder.

  1. Move to the repo directory: cd /etc/yum.repos.d/

  2. Important: Create a "backup" folder and move the existing files there so yum doesn't try to go to the internet: mkdir backup && mv *.repo backup/

  3. Create your local repo file: vi local.repo

  4. Paste the following:

[local-media]

name=CentOS 7 Local Repository

baseurl=file:///mnt/disc

enabled=1

gpgcheck=0

Note: If your CentOS 7 ISO is the "Everything" or "DVD" version, the packages are usually in a folder simply called Packages, but the repodata (the index) is in the root of the disc. That is why we point the baseurl directly to /mnt/disc.

Step 4: Refreshing the Cache

Now, run the magic sequence to make CentOS 7 recognize your "Offline Store":

Bash

# yum clean all

# yum repolist

Under "status," you should see a number (like 3,000+). That is the count of software packages available on your DVD!

Note 1: you should get familiar with the lines of the local.repo file for the LPIC-1.

Note 2: for this configuration to be permanent (stay after reboot), you need to add the mount point to the fstab file.

Step 5: The Anatomy of an /etc/fstab Line

To mount your CD/DVD automatically, you need to add a single line to the bottom of the /etc/fstab file. The file uses 6 columns separated by spaces or tabs.

Here is the line you need for your CentOS 7 VM:

/dev/sr0 /mnt/disc iso9660 defaults,ro,loop 0 0

Step 6: Breaking Down the 6 Columns

The exam frequently asks what each part of this line does. Here is the breakdown:

  1. Device (/dev/sr0): The "thing" you want to mount (your virtual CD drive).

  2. Mount Point (/mnt/disc): Where you want it to appear in your folder tree.

  3. Filesystem Type (iso9660): This is the standard format for all CD/DVD ISOs.

  4. Options (defaults,ro,loop): * defaults: Uses standard settings (rw, suid, dev, exec, auto, nouser, async).

    Option Part of defaults? What it does

    rw Yes Allows reading and writing (overwritten by ro).

    suid Yes Allows "Set User ID" bits to work (important for some apps).

    exec Yes Allows binaries on that disk to be executed.

    auto Yes Mounts automatically when you run mount -a or reboot.

    user No If set, a normal user can mount the disk. defaults uses nouser (root only).

    async Yes It helps performance

    • ro: Read-Only. Since it's a DVD, you can't write to it anyway! This option rewrites the previous "rw" option within the "defaults" label.

    • loop: Tells the system to treat the ISO file/image as a block device.

  5. Dump (0): Used by the old dump backup utility. Set to 0 (disabled).

  6. FSCK (0): Tells the system whether to check the disk for errors at boot. Since it's a read-only DVD, we set it to 0 (don't check).

Note: Be very careful—a typo in fstab can sometimes prevent a system from booting properly!

The Safety Test: Before you reboot, run this command: mount -a

  • If you see no errors, you did it perfectly!

Step 7: LPIC-1 Pro Tip: blkid (Optional)

On the exam, they might ask about using a UUID instead of /dev/sr0. While /dev/sr0 works fine for a simple VM, pros use the UUID because /dev/names can sometimes change if you add more hardware.

  • You can find the UUID by running: blkid /dev/sr0

  • Your fstab line would then start with UUID=xxxx-xxx... instead of the device path.

Verification

Now that you've added the line and run mount -a. Even after a reboot, yum repolist should work instantly.