Restoring /usr/bin with yum after accidental deletion
October 17, 2011
Restoring /usr/bin with yum after accidental deletion
I was recently writing a Makefile for cramfs, specifically the distclean and install sections. The installation would copy the program binaries to /usr/bin while the cleanup would remove them… simple enough right?
I wrote a for loop to go through $(PROGS) and remove them from $(INSTLOC):
01 INSTLOC = /usr/bin
02 PROGS = mkcramfs cramfsck
03
04 all: $(PROGS)
05
06 distclean clean:
07 for p in $(PROGS);\
08 do\
09 rm -rf $$p $(INSTLOC)/$$p;\
10 done
11
12 install:
13 cp $(PROGS) $(INSTLOC)
The problem was that I ran this as root (tsk tsk), and since Makefile requires that for loop variables be escaped (line 9: $$p not $p), the rm command translated to this:
1 rm -rf /usr/bin/
Great! So now I had no binaries in /usr/bin, which includes: yum, bash, crontab, python, perl… (800+ in total on a minimal install).
Since I only deleted the binaries, the programs were still listed as installed in the RPM database. The first thing I had to do was reinstall yum and it’s “usrbin” dependency python:
1 [root@demon ~]# mount /dev/sr0 /media/cdrom
2 [root@demon ~]# cd /media/cdrom/Packages
3 [root@demon ~]# rpm -Uvh --force python-2.6.5-3.el6.i686.rpm
4 [root@demon ~]# rpm -Uvh --force yum-3.2.27-14.el6.noarch.rpm
he next step was to figure out which packages had binaries in /usr/bin so I can reinstall them:
view sourceprint?
1 [root@demon ~]# rpm -qf $(rpm -qla|grep ^/usr/bin)|uniq|sort
… and finally send those to yum to do a reinstall and get the binaries back:
view sourceprint?
1 [root@demon ~]# yum reinstall $(rpm -qf $(rpm -qla|grep ^/usr/bin)|uniq|sort)
2 [root@demon ~]# ls -la /usr/bin|wc -l
3 848
4 [root@demon ~]#
… crisis averted! Snapshot time.
One last note: If you manually installed third party RPMs (not listed in the /etc/yum.repos.d repositories), they will not be reinstalled. You can perform reinstall these one by one using the rpm -Uvh command above. Keep in mind that if these RPMs have not undergone proper QA they may overwrite your current configuration files
You can run these RPMs through rpmlint to see if they produce any warnings or errors that may cause a problem when reinstalling:
view sourceprint?1 [root@demon ~]# rpmlint -iv iplog-2.2.1-1_RH7.i386.rpm
2 ...
3 iplog.i386: W: conffile-without-noreplace-flag /etc/iplog.conf
4 A configuration file is stored in your package without the noreplace flag. A
5 way to resolve this is to put the following in your SPEC file:
6 %config(noreplace) /etc/your_config_file_here
7 ...
8 [root@demon ~]#
I was recently writing a Makefile for cramfs, specifically the distclean and install sections. The installation would copy the program binaries to /usr/bin while the cleanup would remove them… simple enough right?
I wrote a for loop to go through $(PROGS) and remove them from $(INSTLOC):
01 INSTLOC = /usr/bin
02 PROGS = mkcramfs cramfsck
03
04 all: $(PROGS)
05
06 distclean clean:
07 for p in $(PROGS);\
08 do\
09 rm -rf $$p $(INSTLOC)/$$p;\
10 done
11
12 install:
13 cp $(PROGS) $(INSTLOC)
The problem was that I ran this as root (tsk tsk), and since Makefile requires that for loop variables be escaped (line 9: $$p not $p), the rm command translated to this:
1 rm -rf /usr/bin/
Great! So now I had no binaries in /usr/bin, which includes: yum, bash, crontab, python, perl… (800+ in total on a minimal install).
Since I only deleted the binaries, the programs were still listed as installed in the RPM database. The first thing I had to do was reinstall yum and it’s “usrbin” dependency python:
1 [root@demon ~]# mount /dev/sr0 /media/cdrom
2 [root@demon ~]# cd /media/cdrom/Packages
3 [root@demon ~]# rpm -Uvh --force python-2.6.5-3.el6.i686.rpm
4 [root@demon ~]# rpm -Uvh --force yum-3.2.27-14.el6.noarch.rpm
he next step was to figure out which packages had binaries in /usr/bin so I can reinstall them:
view sourceprint?
1 [root@demon ~]# rpm -qf $(rpm -qla|grep ^/usr/bin)|uniq|sort
… and finally send those to yum to do a reinstall and get the binaries back:
view sourceprint?
1 [root@demon ~]# yum reinstall $(rpm -qf $(rpm -qla|grep ^/usr/bin)|uniq|sort)
2 [root@demon ~]# ls -la /usr/bin|wc -l
3 848
4 [root@demon ~]#
… crisis averted! Snapshot time.
One last note: If you manually installed third party RPMs (not listed in the /etc/yum.repos.d repositories), they will not be reinstalled. You can perform reinstall these one by one using the rpm -Uvh command above. Keep in mind that if these RPMs have not undergone proper QA they may overwrite your current configuration files
You can run these RPMs through rpmlint to see if they produce any warnings or errors that may cause a problem when reinstalling:
view sourceprint?1 [root@demon ~]# rpmlint -iv iplog-2.2.1-1_RH7.i386.rpm
2 ...
3 iplog.i386: W: conffile-without-noreplace-flag /etc/iplog.conf
4 A configuration file is stored in your package without the noreplace flag. A
5 way to resolve this is to put the following in your SPEC file:
6 %config(noreplace) /etc/your_config_file_here
7 ...
8 [root@demon ~]#
Posted by Mohamed Adam. Posted In : Restoring /usr/bin with yum after accidental deletion