reinstalling debian /bin

Alex Pennace alex at pennace.org
Tue Sep 19 09:45:00 EDT 2006


On Sun, Sep 17, 2006 at 01:53:35PM -0400, James Kramer wrote:
> While working on Xen setup I managed to delete /bin  by using the command
> rm -R /bin. I don't think that I can recover the /bin files but I
> should be able to reinstall the packages. I have a backup of all my
> data files and most config files that were in /etc.  I can boot into a
> different debian OS using grub so I can access the partition and
> files.  I can chroot the particular partition.  Can someone suggest
> how to reinstall the system.  If I do a complete debian reinstalll
> from CD on top the partition would it retain my old directories and
> files.  I tried to chroot the root partion figuring that I could use
> apt-get to reinstall the packages but I can not figure out the proper
> way to do it. 

You are going to encounter a chicken-and-egg scenario that is not
going to be easy to back out of. The problem is many, many packages
depend/predepend on programs in /bin. It is probably that an apt-get
--reinstall will fail due to the missing files.

"dpkg -S /bin" will list most packages that have files in /bin. (If
the root directory in question is under /mnt, use "dpkg --root=/mnt -S
/bin".) The files that are missed would be files created by package
maintainer scripts instead of being unpacked through dpkg. This is
almost a non-issue for /bin, but would be an issue for most other
directories.

Gather up the corresponding debs. For each deb, run dpkg -x (deb)
(tmpdir). Copy over the files in (tmpdir)/bin into the target's
/bin. Check the target's /bin/sh; make it a symlink to bash if it
isn't already.

You now have a Debian system that is 95% of the way to being
whole. Boot into it and run apt-get --reinstall install (packages in
question).

As hinted above, there may be packages that do not unpack any files
into /bin (and thus won't appear in dpkg -S /bin), but have maintainer
scripts that create files in /bin behind dpkg's back. If you are
truely concerned about that, then apt-get --reinstall install all the
packages on the system. Be warned that this can cause other problems:
It calls the maintainer scripts for every package, and some of them
are not idempotent.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Discuss mailing list