os-release

来源:互联网 发布:大数据可以自学么 编辑:程序博客网 时间:2024/06/05 03:23

原文地址: https://www.freedesktop.org/software/systemd/man/os-release.html

名称

os-release – 操作系统标识

简介

/etc/os-release
/usr/lib/os-release

描述

/etc/os-release和/usr/lib/os-release包含了操作系统的标识信息。
os-release文件的内容和shell的环境变量的表述方式类似,也可以通过shell脚本的source配置到系统环境,不过,也仅仅是具有这样的变量分配的功能,shell的其他一些功能是无法支持(例如变量展开等),应用程序可以不通过复杂的shell执行引擎来读取文件内容。如果变量的值中带有空格、分号或者其他特殊字符(除了A-Z,a-z,0-9这些字符外),则必须用单引号或者双引号引起来。而shell中的定义的一些特殊字符(例如 美元符, 空格, 引号,反斜线,重音符等)则需要以shell的方式进行转义。所有的字符串都必须是UTF-8格式,不应当使用不可打印的字符。 不支持对多个单引用字符串的连接。 以“#”开始的行为注释行。

/etc/os-release优先于/usr/lib/os-release引用。应用程序应先首先检查前者,如果其数据存在就直接使用,仅当这个文件不存在的时候,再去检查/usr/lib/os-release。所有的应用程序不应当同时从这两个文件中读取数据。 推荐/usr/lib/os-release保存系统发布商的信息,而/etc/os-release应当作为指向/usr/lib/os-release的一个软链接,使应用程序只从/etc下面读取信息。 建议符号链接采用相对路径而不是绝对路径以避免在chroot环境或者类似dracut的initrd环境中失效。

os-release包含了由操作系统发行者所定义的数据,这些数据不应当被系统管理员改变。

这个文件仅仅包含了名字和标识,不应当再进行本地化翻译。

/etc/os-release和/usr/lib/os-release可以是指向其他文件的符号链接,但其中和很重要的一点是,因此在系统启动的早期就需要使用,所以这些必须放在根文件系统下。

For a longer rationale for os-release please refer to the Announcement of /etc/os-release.

选项

下面是os-release中可以使用的一些标识项:

NAME=

用来标识操作系统的字符串,不包含系统版本信息,要适用于向用户展示。如果没有设置,则默认为 "NAME=Linux". 例如: "NAME=Fedora" 或者"NAME="Debian GNU/Linux"".

VERSION=

一个标识操作系统版本号的字符串,也可以包含版本的代号,用于向用户展示。这个域是可选的。例如:"VERSION=17" 或者"VERSION="17 (Beefy Miracle)"".

ID=

标明操作系统的小写字符串 (不包含空格以及0-9,a-z, ".","_", "-"之外的字符),不包含版本信息和需要脚本处理的文件名。如果没有设置,默认为"ID=linux". 例如: "ID=fedora" or "ID=debian".

ID_LIKE=

语法和ID=相似,内容是以空格分隔的多个操作系统标识名称。这里应当列出在打包方式与编程接口上和当前操作系统最接近的一些操作系统的标识,例如列出一个或者多个当前OS的上游操作系统的标识。An OS should generally only list other OS identifiers it itself is a derivative of, and not any OSes that are derived from it, though symmetric relationships are possible. Build scripts and similar should check this variable if they need to identify the local operating system and the value of ID= is not recognized. Operating systems should be listed in order of how closely the local operating system relates to the listed ones, starting with the closest. This field is optional. 例如: 一个操作系统ID标注为"ID=centos",那么设置"ID_LIKE="rhel fedora""就是比较合适的做法。而对于"ID=ubuntu"的操作系统, 设置 "ID_LIKE=debian" 就比较适宜.

VERSION_ID=

标识操作系统版本的小写字符串 (包含数字、小写字母,点号、中线和下划线,不包含空格和其他特殊字符) , excluding any OS name information or release code name, and suitable for processing by scripts or usage in generated filenames. This field is optional. Example: "VERSION_ID=17" or "VERSION_ID=11.04".

PRETTY_NAME=

A pretty operating system name in a format suitable for presentation to the user. May or may not contain a release code name or OS version of some kind, as suitable. If not set, defaults to "PRETTY_NAME="Linux"". Example: "PRETTY_NAME="Fedora 17 (Beefy Miracle)"".

ANSI_COLOR=

A suggested presentation color when showing the OS name on the console. This should be specified as string suitable for inclusion in the ESC [ m ANSI/ECMA-48 escape code for setting graphical rendition. This field is optional. Example: "ANSI_COLOR="0;31"" for red, or "ANSI_COLOR="1;34"" for light blue.

CPE_NAME=

A CPE name for the operating system, in URI binding syntax, following the Common Platform Enumeration Specification as proposed by the NIST. This field is optional. Example: "CPE_NAME="cpe:/o:fedoraproject:fedora:17"" 

HOME_URL=, SUPPORT_URL=, BUG_REPORT_URL=, PRIVACY_POLICY_URL=

Links to resources on the Internet related the operating system. HOME_URL= should refer to the homepage of the operating system, or alternatively some homepage of the specific version of the operating system. SUPPORT_URL= should refer to the main support page for the operating system, if there is any. This is primarily intended for operating systems which vendors provide support for. BUG_REPORT_URL= should refer to the main bug reporting page for the operating system, if there is any. This is primarily intended for operating systems that rely on community QA. PRIVACY_POLICY_URL= should refer to the main privacy policy page for the operation system, if there is any. These settings are optional, and providing only some of these settings is common. These URLs are intended to be exposed in "About this system" UIs behind links with captions such as "About this Operating System", "Obtain Support", "Report a Bug", or "Privacy Policy". The values should be in RFC3986 format, and should be "http:" or "https:" URLs, and possibly "mailto:" or "tel:". Only one URL shall be listed in each setting. If multiple resources need to be referenced, it is recommended to provide an online landing page linking all available resources. Examples: "HOME_URL="https://fedoraproject.org/"" and "BUG_REPORT_URL="https://bugzilla.redhat.com/""

BUILD_ID=

A string uniquely identifying the system image used as the origin for a distribution (it is not updated with system updates). The field can be identical between different VERSION_IDs as BUILD_ID is an only a unique identifier to a specific version. Distributions that release each update as a new version would only need to use VERSION_ID as each build is already distinct based on the VERSION_ID. This field is optional. Example: "BUILD_ID="2013-03-20.3"" or "BUILD_ID=201303203". 

VARIANT=

A string identifying a specific variant or edition of the operating system suitable for presentation to the user. This field may be used to inform the user that the configuration of this system is subject to a specific divergent set of rules or default configuration settings. This field is optional and may not be implemented on all systems. Examples: "VARIANT="Server Edition"", "VARIANT="Smart Refrigerator Edition"" Note: this field is for display purposes only. The VARIANT_ID field should be used for making programmatic decisions. 

VARIANT_ID=

A lower-case string (no spaces or other characters outside of 0–9, a–z, ".", "_" and "-"), identifying a specific variant or edition of the operating system. This may be interpreted by other packages in order to determine a divergent default configuration. This field is optional and may not be implemented on all systems. Examples: "VARIANT_ID=server", "VARIANT_ID=embedded" 

If you are reading this file from C code or a shell script to determine the OS or a specific version of it, use the ID and VERSION_ID fields, possibly with ID_LIKE as fallback for ID. When looking for an OS identification string for presentation to the user use the PRETTY_NAME field.

Note that operating system vendors may choose not to provide version information, for example to accommodate for rolling releases. In this case, VERSION and VERSION_ID may be unset. Applications should not rely on these fields to be set.

操作系统发布者可以扩展这些内容并引入新的域。这里比较推荐新引入的域名前面加上操作系统特有的前缀以避免发生冲突。而应用程序在读取信息的时候就可以忽略这些具有特定前缀的域,例如:

    DEBIAN_BTS="debbugs://bugs.debian.org/"

示例

NAME=FedoraVERSION="17 (Beefy Miracle)"ID=fedoraVERSION_ID=17PRETTY_NAME="Fedora 17 (Beefy Miracle)"ANSI_COLOR="0;34"CPE_NAME="cpe:/o:fedoraproject:fedora:17"HOME_URL="https://fedoraproject.org/"BUG_REPORT_URL="https://bugzilla.redhat.com/"
0 0