Fedora offline repo setup

From Dgplug

Contents

Status

Work in progress

People working

  1. mbuf (mentor)
  2. rtnpro
  3. aveek

How To

  1. Get a copy of the Fedora and rpmfusion repository in the local machine to be setup as offline mirror.
  2. Setup a dhcp server in the local machine.
  3. Setup an ftp server in the local machine. Mount the repository at /var/ftp/pub
  4. Create a fedora-local.repo file with the baseurl configure to the IP address of the server along with the requisite directories.
  5. Temporarily disable all the online repositories and enable the local repository.
  6. Then the client can either use PackageKit or yum to install/update the concerned system.
  7. Once over, the client will be able to revert back to the original settings.
  8. The offline repository will be updated regularly.

Testing Offline Mirror

Testing Environment

System : Dell XPS M1530
Host Operating System : Fedora 11
Virtualization Tool : Virtual Box
Guest Operating System : Fedora 10
Repository : Fedora 10 i386( fedora + updates + rpmfusion)
Location of offline repository : /dev/sdb1:/repo
Server used : vsftpd
ip of host machine : 192.168.122.1

Fedora 10 has been started on Virtual Box and we will refer this virtual system as client and the host machine as server.

Steps to be implemented on the server

1. Mount the External Hard Drive which contains the repo.

su -c 'mount /dev/sdb1 /mnt/'

2. Start the ftp server on the host machine.

su -c '/etc/init.d/vsftpd start'

3. Mount the repository to /var/ftp/pub/

su -c 'mount --bind /mnt/repo/ /var/ftp/pub/'

4. Create fedora-local.repo as given below

#rpmfusion free updates
[r-f-u-local]
name=RPM Fusion Free Updates Local for Fedora $releasever
baseurl=ftp://192.168.122.1/pub/rpmfusion/free/fedora/updates/$releasever/i386/
enabled=1
gpgcheck=0                                                                     

#rpmfusion free releases
[r-f-r-local]
name=RPM Fusion Free Releases Local for Fedora $releasever
baseurl=ftp://192.168.122.1/pub/rpmfusion/free/fedora/releases/$releasever/Everything/i386/os/
enabled=1
gpgcheck=0

#rpmfusion non-free releases
[r-n-r-local]
name=RPM Fusion Nonfree Releases Local for Fedora $releasever
baseurl=ftp://192.168.122.1/pub/rpmfusion/nonfree/fedora/releases/$releasever/Everything/i386/os/
enabled=1
gpgcheck=0

#rpmfusion non-free updates
[r-n-u-local]
name=RPM Fusion Nonfree Updates Local for Fedora $releasever
baseurl=ftp://192.168.122.1/pub/rpmfusion/nonfree/fedora/updates/$releasever/i386/
enabled=1
gpgcheck=0

#fedora releases
[f-r-local]
name=Fedora Releases Local for Fedora $releasever
baseurl=ftp://192.168.122.1/pub/fedora/linux/releases/$releasever/Everything/i386/os/Packages/
enabled=1
gpgcheck=0

#fedora updates
[f-u-local]
name=Fedora Updates Local for Fedora $releasever
baseurl=ftp://192.168.122.1/pub/fedora/linux/updates/$releasever/i386/
enabled=1
gpgcheck=0

and place it in a directory named "yum.repos.d.offline" in /mnt/repo/

mkdir /mnt/repo/yum.repos.d.offline

5. Note that the directory permissions of /var/ftp/pub and the concerned repo folders should at least give read and execute rights to group and other users. If it is not, you can do

su -c 'chmod 755 -R /var/ftp/pub/'

6. You should also allow ftp protocol from your Firewall settings. The offline mirror should now be ready to be used. You can check whether the mirror has been uploaded properly or not. You can do this by entering the following URL in a web browser like firefox and try to browse through the contents.

URL - ftp://127.0.0.1/ or ftp://192.168.122.1/

If the repo directories don't have proper access permissions as mentioned in step 5), clicking on pub might give an error 550 failed to change directory

Settings to be done on the client

1. Download the yum.repos.d.offline in the client from the ftp server. Let's assume it is downloaded in /home/usr/Download/

wget -r ftp://192.168.122.1/pub/yum.repos.d.offline

2. We need to preserve the original yum.repos.d configuration so that the client can do online installation/update later if required. So we will be mounting the yum.repos.d.offline folder at /etc/yum.repos.d/ and unmount it when offline installation/update is over.

su -c 'mount --bind /home/usr/Download/yum.repos.d.offline/ /etc/yum.repos.d/'

3. That's all. Now the client is ready to use yum from the offline repository or even use Packagekit.

4. When things are done on the client, one can restore the original yum.repos.d in the following way

su -c 'umount /etc/yum.repos.d/' 

To stop the offline yum server

1. Stop the ftp server :

su -c '/etc/init.d/vsftpd stop' 

2. Unmount the repo :

su -c 'umount /var/ftp/pub/' 

3. Unmount the external HDD from /mnt :

su -c 'umount /mnt/'

Roadmap

Task Status Result
Setup offline repo in an External HDD Done Success
Testing the above setup Done Success
Create udev rules to automate rsync of the offline repo in the server with the updated repo in the external HDD when it is connected to the server Working Not known
Create a GUI for the offline mirror To be implemented Not known

Automating rsync with udev

Steps

1. Wrote a custom udev rule at /etc/udev/rules.d/10-local.rules with the following content

#Rule for Maxtor Portable HDD
KERNEL=="sd?", SUBSYSTEMS=="scsi", DRIVERS=="sd", ATTRS{model}=="Basics Portable ", RUN+="/home/rtnpro/offline_fedora_repo/udev_call.sh"

2. Wrote a shell script udev_call.sh to be called by udev

#!/bin/bash
#Filename : udev_call.sh
#Description:udev_call.sh is called by udev when a USB HDD with model = "Basics  Portable" is connected to the system. This is done by a customized udev rule at /etc/udev/rules.d/10-local.rules
user=rtnpro
path_of_local_repo=/home/$user/offline_fedora_repo/
sleep 5
su - $user -c "nohup sh $path_of_local_repo/rsync_call.sh > $path_of_local_repo/logs 2>&1 &"

3. Contents of rsync_call.sh :

#!/bin/bash

#Declaration of variables
user=rtnpro
label=MyStorage
path_of_repo_src=/media/$label/repo
path_of_local_repo=/home/$user/offline_fedora_repo/

export DISPLAY=:0.0
ls -ld $path_of_local_repo > /dev/null || mkdir -p $path_of_local_repo/repo/

rsync -auv --delete $path_of_repo_src/ $path_of_local_repo/repo/ >>  $path_of_local_repo/rsync.log

/usr/bin/notify-send -t 0 "Rsync successful" "Offline repository was successfully synchronized"

To be done: Write a shell script to setup and configure offline_fedora_repo.

Some Issues: The processes in the rsync_call.sh gets repeated twice when udev_call.sh is called using udev 10-local.rules. But if udev_call.sh is directly executed, there is no repetition of any step in the scripts.

Issue Resolved
The above issue was being caused by an error in the 10-local.rules. 
It was KERNEL=="sd*", which hold for /dev/sdb and /dev/sdb1 as well
( they both have other identical variables). This resulted in the scripts
being called twice. So I changed it to KERNEL=="sd?" and the issue got
resolved.

Note : The above scripts were written just for trial and they seem to be working correctly. The scripts are still crude, and will be improved shortly.

Personal tools