SubsetRepositoriesFedora7

Subset Repositories (Fedora 7)

Creating the Base Repository

The base distribution repository is created in the same way as it's always been done on the earlier distribution releases. The files can be located anywhere but for the purposes of this article, the directory /srv/nb/distros/fc7 is used as a base.

To support both 32-bit and 64-bit machines on the network, the ISO images for both the 32-bit and 64-bit releases are needed. If you only need one architecture, skip the parts pertaining to the other architecture (similarly if you're using ppc, substitute ppc for i386 or x86_64 as appropriate).

The ISO images should be placed the repository area on the server that you are using, e.g.:

# mkdir -p /srv/nb/distros/fc7/os/i386/iso/
# cp F-7-i386-DVD.iso /srv/nb/distros/fc7/os/i386/iso/

# mkdir -p /srv/nb/distros/fc7/os/x86_64/iso/
# cp F-7-x86_64-DVD.iso /srv/nb/distros/fc7/os/x86_64/iso/

Create mount points so that the ISO images can be loopback-mounted:

# mkdir /srv/nb/distros/fc7/os/i386/dvd/
# chcon -t mnt_t /srv/nb/distros/fc7/os/i386/dvd

# mkdir /srv/nb/distros/fc7/os/x86_64/dvd/
# chcon -t mnt_t /srv/nb/distros/fc7/os/x86_64/dvd

Edit /etc/fstab and add entries for the DVD images to get them mounted at boot time:

/srv/nb/distros/fc7/os/i386/iso/F-7-i386-DVD.iso /srv/nb/distros/fc7/os/i386/dvd iso9660 _netdev,ro,loop,fscontext=system_u:object_r:public_content_t 0 0
/srv/nb/distros/fc7/os/x86_64/iso/F-7-x86_64-DVD.iso /srv/nb/distros/fc7/os/x86_64/dvd iso9660 _netdev,ro,loop,fscontext=system_u:object_r:public_content_t 0 0

<!> Note that these are just single long lines for each ISO image

It should now be possible to mount the ISO image(s) by issuing the command:

# service netfs start

It may seem strange to treat local loopback mounts as "network filesystems" but this is the point during the boot process where loopback mounts get done. Using service netfs start rather than plain mount -a checks that there are no SELinux issues (the former runs confined by SELinux, the latter does not). The long-winded mount options in the fstab entries prevent SELinux objecting if you serve out the repository using ftp, httpd, rsync etc.

You can then use createrepo to build the repository metadata:

# cd /srv/nb/distros/fc7/os/i386
# createrepo .

# cd /srv/nb/distros/fc7/os/x86_64
# createrepo .

/!\ Be careful with your directory hierarchy; it is important that the only RPM files that live in the /srv/nb/distros/fc7/os/i386 etc. directory or anywhere underneath that directory are the RPMs from your DVD ISO (i.e. the ones in the dvd/Fedora directory); any other RPMs that may be present will also be found by createrepo and included in the repository, which is probably not what you want.

{i} createrepo is in the createrepo package on the media

Using the Base Repository

Now to actually use the newly-created repository. The object is pull packages that are available from the local repository from that repository, and get anything else from the Internet.

The first step is to create lists of the packages on the media (and hence in the local repository):

# cd /etc/yum

# ls /srv/nb/distros/fc7/os/i386/dvd/Fedora |
        awk '{ pkgname = $1; sub("-[^-]*-[^-]*$", "", pkgname); print "\t" pkgname }' |
        uniq > fedora-7-i386-dvd-pkgs.conf

# ls /srv/nb/distros/fc7/os/x86_64/dvd/Fedora |
        awk '{ pkgname = $1; sub("-[^-]*-[^-]*$", "", pkgname); print "\t" pkgname }' |
        uniq > fedora-7-x86_64-dvd-pkgs.conf

This process creates a sorted list of the packages on each DVD ISO (the lists are slightly different for each architecture), one per line, indented with a tab character at the start of each line. The tab character (or at least some form of leading space) is important for later use.

Next, you need to edit the /etc/yum.repos.d/fedora.repo file, which tells yum where to get the base packages from. The first section of the file is for the [fedora] repository and initially looks like this:

[fedora]
name=Fedora $releasever - $basearch
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY

Change the line:

enabled=1

to:

enabled=0

Then add the following two repository definitions at the top of the file:

[fedora-dvd]
name=Fedora $releasever - $basearch (local media)
baseurl=file:///srv/nb/distros/fc7/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY

[fedora-everything]
name=Fedora $releasever - $basearch (network)
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY
exclude=
include=file:///etc/yum/fedora-7-i386-dvd-pkgs.conf

/!\ Change the i386 on the last line to x86_64 or whatever the architecture for the machine is - $basearch substitution doesn't work here.

This works by explicitly excluding from the [fedora-everything] repository (the packages to be downloaded from the Internet) the list of all of the packages available on the media; the list of packages created earlier and pulled in using the include= directive is treated as a continuation of the previous exclude= line.

You should now be able to test your setup by installing some package. Packages on the media will be shown as coming from fedora-dvd and other packages will be shown as coming from fedora-everything.

Creating the Updates Repository

The object here is to create an updates repository that contains only updates for the packages available on the original media. This will reduce the bandwidth and disk space needed to maintain the mirror.

The tool to be used is reposync, which is part of the yum-utils package.

Create a mirror configuration file, /etc/yum.repos.d/fedora-updates-mirror.repo (this uses the same trick with include= but this time to specify the list of wanted packages rather than the list of packages to exclude):

[fedora-7-updates-subset-i386]
name=Fedora 7 - i386 - Updates Subset
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/updates/7/i386/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f7&arch=i386
includepkgs=
include=file:///etc/yum/fedora-7-i386-dvd-pkgs.conf
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora

[fedora-7-updates-subset-x86_64]
name=Fedora 7 - x86_64 - Updates Subset
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/updates/7/x86_64/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f7&arch=x86_64
includepkgs=
include=file:///etc/yum/fedora-7-x86_64-dvd-pkgs.conf
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora

<!> It's a good idea to replace the mirrorlist entries with baseurl entries pointing to a fast, nearby mirror; not all mirrors are as up to date as each other, so with the mirrorlist you might find that one day's reposync run removes the updates downloaded in the previous day's run.

Then create a script updates-sync, and put it somewhere in your PATH, such as /usr/local/bin:

echo "Updating mirror of fedora-7-updates-subset-i386"
reposync -n -g -d -r fedora-7-updates-subset-i386 -p /srv/nb/distros/fc7 |
        grep -Ev "Skipping existing|%"
createrepo -q -d -C /srv/nb/distros/fc7/fedora-7-updates-subset-i386
echo ""

echo "Updating mirror of fedora-7-updates-subset-x86_64"
reposync -n -g -d -a x86_64 -r fedora-7-updates-subset-x86_64 -p /srv/nb/distros/fc7 |
        grep -Ev "Skipping existing|%"
createrepo -q -d -C /srv/nb/distros/fc7/fedora-7-updates-subset-x86_64
echo ""

Skip the part for any architecture you're not interested in. The grep command here reduces the volume of output from reposync whilst leaving the interesting output alone (unlike the -q option of reposync). Don't forget to make the script executable:

# chmod 755 /usr/local/bin/updates-sync

To populate the repository (download the update packages), just run /usr/local/bin/updates-sync. This will create repositories in directories /srv/nb/distros/fc7/fedora-7-updates-subset-i386 and /srv/nb/distros/fc7/fedora-7-updates-subset-x86_64 for i386 and x86_64 respectively.

Using the Updates Repository

Edit the /etc/yum.repos.d/fedora-updates.repo file, which tells yum where to get the update packages from. The first section of the file is for the [updates] repository and initially looks like this:

[updates]
name=Fedora $releasever - $basearch - Updates
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/updates/$releasever/$basearch/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora

Change the line:

enabled=1

to:

enabled=0

Then add the following two repository definitions at the top of the file:

[updates-local]
name=Fedora $releasever - $basearch - Local Updates
baseurl=file:///srv/nb/distros/fc7/fedora-7-updates-subset-$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora

[updates-network]
name=Fedora $releasever - $basearch - Network Updates
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/updates/$releasever/$basearch/
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
exclude=
include=file:///etc/yum/fedora-7-i386-dvd-pkgs.conf

/!\ Change the i386 on the last line to x86_64 or whatever the architecture for the machine is - $basearch substitution doesn't work here.

This works by explicitly excluding from the [updates-network] repository (the packages to be downloaded from the Internet) the list of all of the packages available in the local updates repository, which is the same as the list of packages available on the media.

You should now be able to test your setup by running yum update. Packages in the local repository will be shown as coming from updates-local and other packages will be shown as coming from updates-network.

No/Slow Internet Connection?

Edit the configuration files:

  • /etc/yum.repos.d/fedora.repo

  • /etc/yum.repos.d/fedora-updates.repo

Change the line:

enabled=1

to:

enabled=0

for the network repositories and leave just the local repositories enabled by default. You should then be able to use the package management tools whilst offline, though you may find that things you'd like to install appear not to be available.

To enable the Internet repositories for a single yum run whilst you're online, use:

# yum --enablerepo=fedora-everything --enablerepo=updates-network update

or

# yum --enablerepo=fedora-everything --enablerepo=updates-network install somepackage

etc.


CategoryTip

Recent
Toolbox