如何判断是centos还是欧拉系统?

云计算

要判断当前系统是 CentOS 还是 欧拉系统(openEuler 或 EulerOS),可以通过以下几种方法进行识别:


✅ 方法一:查看系统发行版本信息文件

1. 查看 /etc/os-release 文件

cat /etc/os-release
  • 如果输出中包含:

    NAME="CentOS Linux"
    PRETTY_NAME="CentOS Linux 7 (Core)"
    ID="centos"

    → 是 CentOS

  • 如果输出中包含:

    NAME="openEuler"
    PRETTY_NAME="openEuler 20.03"
    ID="openEuler"

    或者:

    NAME="EulerOS"
    ID="euleros"

    → 是 欧拉系统(openEuler 或 EulerOS)

📌 openEuler 和 EulerOS 都是华为推出的系统,EulerOS 是商业版,openEuler 是开源社区版。


2. 查看 /etc/redhat-release(适用于基于 RHEL 的系统)

cat /etc/redhat-release
  • 输出如:

    CentOS Linux release 7.9.2009 (Core)

    → 是 CentOS

  • 欧拉系统通常 不会 有这个文件,或内容为:

    openEuler release 20.03

    或没有该文件。

注意:openEuler 虽然部分兼容 RHEL 生态,但不一定会提供 redhat-release 文件。


3. 查看其他标识文件

ls /etc/*release*

常见文件:

  • /etc/os-release
  • /etc/system-release
  • /etc/centos-release(仅 CentOS)
  • /etc/euleros-release(仅 EulerOS)

如果存在 /etc/euleros-release,基本可以确定是欧拉系统。


✅ 方法二:使用命令行工具

使用 hostnamectl 命令(推荐)

hostnamectl

输出示例:

   Static hostname: myhost
         Icon name: computer-vm
           Chassis: vm
        Machine ID: xxxxxxxx
           Boot ID: yyyyyyyy
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
            Kernel: Linux 3.10.0-1160.el7.x86_64
      Architecture: x86-64

→ “Operating System” 字段明确显示系统名称。


使用 lsb_release 命令(如果已安装)

lsb_release -a

输出:

  • 若显示 Distributor ID: CentOS → CentOS
  • 若显示 Distributor ID: openEuler → openEuler

注意:某些最小化安装可能未安装 lsb_release,可通过 yum install redhat-lsb-core 安装。


✅ 方法三:检查包管理器行为或特定软件包

虽然两者都使用 yumdnf,但底层仓库和包签名不同。

例如,查询系统发行包:

rpm -q centos-release
  • 如果返回类似 centos-release-7-9.el7.centos → 是 CentOS
  • 如果提示 package centos-release is not installed → 可能不是 CentOS

同理:

rpm -q openeuler-release  # 或 euleros-release

✅ 总结:快速判断脚本

你可以运行以下命令一键判断:

if grep -qi "centos" /etc/os-release; then
    echo "系统是 CentOS"
elif grep -qi "openEuler|EulerOS" /etc/os-release; then
    echo "系统是 欧拉系统 (openEuler 或 EulerOS)"
else
    echo "未知系统"
fi

🔍 补充说明

特征 CentOS openEuler / EulerOS
/etc/os-release 中的 ID= centos openEulereuleros
是否基于 RHEL 否(独立发展,兼容)
默认内核 RHEL 衍生内核 华为定制内核(如鲲鹏优化)
开发者 社区(Red Hat 支持) 华为

如有进一步需求(比如区分 openEuler 和 EulerOS),也可以查看具体版本号或联系厂商支持。