You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS 7系统升级后如何防止已删除的YUM仓库被自动重建?

Great question—this is a super common pain point when managing CentOS 7 repos, especially when you need to keep custom repo configurations intact through updates. Let’s break down the most reliable methods to stop those deleted repos from coming back:

Method 1: Mark repo files as immutable (most direct)

If deleted repo files keep reappearing, or you want to protect existing repo configs from being overwritten, use the chattr command to set an immutable attribute on the file:

  • First, set up the repo file exactly how you want it (e.g., /etc/yum.repos.d/your-custom.repo)
  • Run this command to lock it: sudo chattr +i /etc/yum.repos.d/<your-repo-file>.repo

This prevents any user (including root) from modifying, deleting, or renaming the file. If you ever need to edit it later, just remove the attribute with: sudo chattr -i /etc/yum.repos.d/<your-repo-file>.repo

Note: If a system package (like centos-release) tries to replace the repo file during an update, this will block the replacement and trigger a yum warning—but your custom config will stay intact.

Method 2: Disable repos instead of deleting files (more maintainable)

Instead of deleting repo files entirely, disable them so yum ignores them, and they won’t get recreated as easily:

  • Use yum’s built-in manager to disable a repo: sudo yum-config-manager --disable <repo-id>
    (Run yum repolist all to get the exact ID of the repo you want to disable)
  • Alternatively, edit the repo file directly and change enabled=1 to enabled=0

If you’re worried about this config being overwritten during updates, pair this with the chattr +i trick from Method 1 to lock the file.

Method 3: Lock system packages that rebuild repos

Most default CentOS repo files are provided by packages like centos-release or centos-release-x86_64. When these packages are updated, they’ll overwrite default repo files to their original state. Locking these packages stops that from happening:

  1. Install the versionlock plugin first: sudo yum install yum-plugin-versionlock
  2. Check the current version of the package: rpm -q centos-release
  3. Lock it to prevent updates: sudo yum versionlock add centos-release

To unlock the package later (if you need to update it), run: sudo yum versionlock delete centos-release

Method 4: Use a custom repo directory (advanced)

You can reconfigure yum to only read repo files from a custom directory, ignoring the default /etc/yum.repos.d/:

  • Edit /etc/yum.conf and add a line like: reposdir=/etc/yum.repos.d/custom-repos
  • Move all your desired repo files to this new directory, and delete the ones in the default folder

Just be aware that system updates might reset yum.conf, so you should lock this file with chattr +i or pair this with Method 3 to protect the config.

Personally, I recommend combining Method 2 (disable repos) with Method 3 (lock centos-release packages) for the most robust solution—it’s clean, easy to maintain, and avoids potential headaches with immutable files blocking legitimate system updates later on.

内容的提问来源于stack exchange,提问作者Kevin C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:09:29