By default, when the user installs software through the RPM Package Manager or through YUM, usually, the software’s configuration files included in the RPM do not replace the existing configuration files on the filesystem, but, if they differ from those that currently exist, they are saved with the rpmnew extension. In case the rpm is already installed and is the latest version, the quickest way to get the original configuration file back is to uninstall and install the package again. Today, while on CentOS 6.2, I needed to restore the original
/etc/sysctl.conf file, which is part of the initscripts package. In this case, uninstalling initscripts was out of the question as it would also remove half of the installed packages due to dependencies. So, I grabbed the chance to figure out and document what would be the quickest and easiest way to restore
/etc/sysctl.conf, excluding downloading the package itself and extract the RPM contents. Fortunately, as soon as I opened yum’s man page and having spotted the new reinstall command, the solution was quite obvious.
For completeness, I hereby document the whole procedure that involves the verification and restoration of the original
/etc/sysctl.conf hoping that new users might find these notes helpful.
First of all, I needed to know whether the
/etc/sysctl.conf I had on my box differed from the original one. But, before doing that, I had to know which RPM package had installed that file. So, I used the rpm command to query this file:
# rpm -qf /etc/sysctl.conf initscripts-9.03.27-1.el6.centos.1.i686
So, the initscripts package had installed
Then I verified the initscripts package:
# rpm -V initscripts S.5....T. c /etc/sysconfig/init S.5....T. c /etc/sysctl.conf
According to the following table:
S file Size differs M Mode differs (includes permissions and file type) 5 MD5 sum differs D Device major/minor number mismatch L readLink(2) path mismatch U User ownership differs G Group ownership differs T mTime differs P caPabilities differ
the attributes: size, MD5 checksum and the modification time of
/etc/sysctl.conf that existed on my system differed from the attributes of the original file.
Since I had no idea the exact changes I had made to that file at some earlier time, I needed to restore the original and re-modify it from scratch. The new yum “reinstall” command could be used to to do this quite easily.
First, I kept a copy of the current file:
# mv /etc/sysctl.conf /etc/sysctl.conf.modified
Then I reinstalled initscripts using YUM’s reinstall command:
# yum reinstall initscripts Loaded plugins: downloadonly, fastestmirror, priorities Setting up Reinstall Process Loading mirror speeds from cached hostfile * base: ftp.ntua.gr * epel: ftp.ntua.gr * extras: ftp.ntua.gr * ius: mirror.rackspace.co.uk * updates: centosr3.centos.org 6 packages excluded due to repository priority protections Resolving Dependencies --> Running transaction check ---> Package initscripts.i686 0:9.03.27-1.el6.centos.1 will be reinstalled --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================= Reinstalling: initscripts i686 9.03.27-1.el6.centos.1 updates 934 k Transaction Summary ============================================================================================================================================================= Reinstall 1 Package(s) Total download size: 934 k Installed size: 5.4 M Is this ok [y/N]: y Downloading Packages: initscripts-9.03.27-1.el6.centos.1.i686.rpm | 934 kB 00:02 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : initscripts-9.03.27-1.el6.centos.1.i686 1/1 Installed: initscripts.i686 0:9.03.27-1.el6.centos.1 Complete!
Verify the initscripts package again:
# rpm -V initscripts S.5....T. c /etc/sysconfig/init
No verification errors for
/etc/sysctl.conf. Note that reinstalling the package did not touch the
/etc/sysconfig/init file. It has been mentioned previously that rpm packages do not overwrite existing configuration files.
I had the original file back and I could then start customizing it from scratch.
Restore original configuration files from RPM packages by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2012 - Some Rights Reserved