12

I accidentally deleted /etc/redhat-release file. How can I restore or create a new one? I have CentOS Linux release 7.0.1406 (Core).

  • 1
    Easy: restore from backup – Anthon Jun 15 '15 at 15:16
23

You can use RPM to see what RPM that file belongs to:

$ rpm -qf /etc/redhat-release
centos-release-7-0.1406.el7.centos.2.5.x86_64

You can then fix it using yum:

$ yum reinstall centos-release

Might not work

If the RPM that was used to do this install is no longer available then the above will not work:

$ yum reinstall centos-release-7-0.1406.el7.centos.2.5.x86_64
...
Installed package centos-release-7-0.1406.el7.centos.2.5.x86_64 (from updates) not available.

In this case you can look for that RPM in the CentOS Vault (I search via Google for it), for example. NOTE: The specific package you want is here.

You can then download the RPM directly and do the re-install using rpm or yum.

$ wget http://vault.centos.org/centos/7.0.1406/updates/x86_64/Packages/centos-release-7-0.1406.el7.centos.2.5.x86_64.rpm
Using RPM
$ sudo rpm -Uvh --replacepkgs centos-release-7-0.1406.el7.centos.2.5.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:centos-release-7-0.1406.el7.cento################################# [100%]
Using YUM
$ sudo yum reinstall centos-release-7-0.1406.el7.centos.2.5.x86_64.rpm
Loaded plugins: dellsysid, fastestmirror, langpacks
Examining centos-release-7-0.1406.el7.centos.2.5.x86_64.rpm: centos-release-7-0.1406.el7.centos.2.5.x86_64
Resolving Dependencies
--> Running transaction check
---> Package centos-release.x86_64 0:7-0.1406.el7.centos.2.5 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================
 Package                     Arch                Version                              Repository                                                   Size
========================================================================================================================================================
Reinstalling:
 centos-release              x86_64              7-0.1406.el7.centos.2.5              /centos-release-7-0.1406.el7.centos.2.5.x86_64               31 k

Transaction Summary
========================================================================================================================================================
Reinstall  1 Package

Total size: 31 k
Installed size: 31 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : centos-release-7-0.1406.el7.centos.2.5.x86_64                                                                                        1/1
  Verifying  : centos-release-7-0.1406.el7.centos.2.5.x86_64                                                                                        1/1

Installed:
  centos-release.x86_64 0:7-0.1406.el7.centos.2.5

Complete!

Why didn't reinstall work?

This is a snafu that was created when the individualized RPMs to specific versions of CentOS were deprecated.

This directory (and version of CentOS) is deprecated. For normal users, you should use /7/ and not /7.0.1406/ in your path. Please see this FAQ concerning the CentOS release scheme:

https://wiki.centos.org/FAQ/General

If you know what you are doing, and absolutely want to remain at the 7.0.1406 level, go to http://vault.centos.org/ for packages.

Please keep in mind that7.0.1406 no longer gets any updates, nor any security fix's.

--- Source: http://mirror.centos.org/centos/7.0.1406/readme

So you typically have to reach into the CentOS Vault for packages that fall into this state.

  • Good answer though generally the -i flag to rpm should be avoided as it is almost always less useful then the -U flag (and, yes, -U can install entirely new packages). – Etan Reisner Jun 15 '15 at 22:49
  • @EtanReisner - good point, changed. – slm Jun 16 '15 at 0:36
  • @slm - Why is just touching the file is not enough? How does re-creating the file from package re-installation differ from just touching the file in this case? – Sree Jun 16 '15 at 4:00
  • 1
    @Sree - there's content inside the file. There are a variety of ways to reconstruct this file, it is simply a text file with the version of CentOS in it. However this method will guarantee that the file is recreated as it was prior to being deleted. Think ownership, permissions, etc. in addition to the contents too. – slm Jun 16 '15 at 4:33
4

It should be okay. You can re-create the file. The content of the file is:

[root@server ~]# cat /etc/centos-release
CentOS Linux release 7.0.1406 (Core)
[root@server ~]#

This file belongs to the package centos-release-7-0.1406.el7.centos.2.5.x86_64, so as long as you haven't removed that package, just touching this file manually should be fine.

[root@server ~]# rpm -qf /etc/redhat-release
centos-release-7-0.1406.el7.centos.2.5.x86_64

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.