Local CentOS mirror

Following on from last weeks post, this post is quickly going to go through setting up a local CentOS YUM repository. Although just pulling packages from a public mirror is easier, it can sometimes be useful to have a local mirror if you're working offline or with a limited connection.

Extracting packages or mounting

The CentOS 7.2 everything iso contains just under 7GB of packages. The two directories you need are Packages and repodata. If you are on a Linux based system you should be able to mount the ISO with a command similar to the following:

mount -o ro,loop CentOS-7-x86_64-Everything-1511.iso /mnt/

Alternatively you can use an archive manager like 7-zip to extract the directories.

Truncated filenames

The CentOS ISO uses a Joliet file system. Part of the spec includes the following:

The File or Directory Identifiers may be up to 128 bytes (64 unicode characters) in length.

The ISO does include TRANS.TBL files with the full filenames, however 7-zip currently doesn't use them to translate the filenames (bug #1055 and bug #1412).

You can quickly check if this is an issue by having a look in the repodata directory:

$ ls

To fix this the truncated files need to be renamed to match the filenames listed in TRANS.TBL. I've written a quick python script to do this. Running the script should rename any truncated files:

$ python fix_truncated_files.py repodata/ Packages/
Missing file: 0e54cd65abd3621a0baf9a963eafb1a0ffd53603226f02aadce59635329bc937-primary.xml.gz
Renaming: repodata/0e54cd65abd3621a0baf9a963eafb1a0ffd53603226f02aadce59635329bc937 -> repodata/0e54cd65abd3621a0baf9a963eafb1a0ffd53603226f02aadce59635329bc937-primary.xml.gz
Missing file: 308b19b243c882f0278206ea4ffc4e120df78c0218867917916fd437e4d0ea49-filelists.sqlite.bz2
Renaming: repodata/308b19b243c882f0278206ea4ffc4e120df78c0218867917916fd437e4d0ea49 -> repodata/308b19b243c882f0278206ea4ffc4e120df78c0218867917916fd437e4d0ea49-filelists.sqlite.bz2

Serving repo files

YUM repositories can be accessed over several protocols; for this post I'm going to use http. Switch to the directory containing repodata and Packages then run python -m http.server. This will spin up a web server:

$ python -m http.server
Serving HTTP on port 8000 ...

Note: if you are using python 2.x run python -m SimpleHTTPServer instead.

Client configuration

The last thing to do is configure a CentOS client to use the local mirror. Create a config file called /etc/yum.repos.d/CentOS-Base-Local.repo with the following contents:

name=CentOS-$releasever - Base (Local)

Running yum repolist base-local should give you output similar to the following:

repo id              repo name                         status

base-local           CentOS-7 - Base (Local)           9,007

Once you're happy your local mirror is working you can disable the standard base repository by running yum-config-manager --disable base. Alternatively you can add enabled=0 to /etc/yum.repos.d/CentOS-Base.repo in the [base] section.