How to create the local repo for RHEL/Centos

Save below script as YUM_REPO_CREATE.sh.

export OS_VER=$(cat /etc/os-release |grep -i version_id |head -1 |awk -F = '{print $2}' |tr -d \") 

case $OS_VER in
#For RHEL 8.0
    8.0)
    mv -fv /etc/yum.repos.d/*.repo /tmp
    DVD_DIR=$(mount |grep -i sr0 |awk '{print $3}')
    cat > /etc/yum.repos.d/rhel-local.repo << EOFRHEL
[Local-BaseOS]
name=Red Hat Enterprise Linux 8.0.0
baseurl=file://${DVD_DIR}/BaseOS
enabled=1
gpgcheck=0

[Local-AppStream]
name=Red Hat Enterprise Linux 8.0.0
baseurl=file://${DVD_DIR}/AppStream
enabled=1
gpgcheck=0
EOFRHEL
    yum update
    ;;

#For RHEL 7.x
    7.6|7.5|7.4|7.3|7.2|7.1|7.0)
    mv -f /etc/yum.repos.d/*.repo /tmp
    DVD_DIR=$(mount |grep -i sr0 |awk '{print $3}')
    cat > /etc/yum.repos.d/rhel-local.repo << EOFRHEL
[Local-BaseOS]
name=Red Hat Enterprise Linux 7.x
baseurl=file://${DVD_DIR}/
enabled=1
gpgcheck=0
EOFRHEL
    yum update
    ;;

    *)
	    echo "This RHEL is not supported. Please contact Maruku."
    ;;
    esac 

Then put your OS DVD into DVD-ROM.

FB 留言

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *