Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I accidentally deleted the /lib directory on my Fedora 15 machine and I'm not sure how to go about fixing this. Any help in figuring out how to restore the directory along with symbolic links would be greatly appreciated.

share|improve this question
1  
This is probably non-trivial. It would be easier to back up your data files and reinstall. The only other option is to reinstall the packages which have files in /lib, which is likely to be painful and difficult. Does yum still work, for example? –  Faheem Mitha Dec 9 '11 at 8:14

4 Answers 4

/lib is a system directory, will contain the necessary library files installed during installation and later from any additional package installations using rpm or tarballs. Do you have any backups for the host, Is it on a RAID or LVM partition? For that, the procedure will be different. However /lib is a system directory and its availability in sane mode is essential for the functional running of the host.

I would be keen to suggest to look for a live-cd and boot the system using cd and get into rescue mode. Also, find if there is any machine on the same network with fedora 15 same image installation earlier. If not, setup a machine with fedora 15 same machine seperately. Lets call it a remote machine for sake of the explanation. This remote machine you can use to copy /lib entire structure with symlinks and all exactly using rsync later. Make sure you install the rsync package. Also, make sure you have ssh installed and running on the remote machine with root login allowed.

Note: If you do not have another machine then only alternative is to reinstall the OS with the option of without overwriting any of the Linux installed data. That way, you will ensure that all the local data on the machine post its previous installation is safe and untouched. And do not recreate any partitions. If you do have another machine then proceed next, because this could get your system recovered and make it up and running more earlier.

Once you are done booting off the cd and rescue mode on the local machine, setup the networking and get to know the ipaddresses of the to-rescue machine and from where /lib can be copied. Identify the /lib partition on the local hard disk. Is it a seperate partition or was mounted from /. Usually it is a directory structure under /, not a seperate partition. If it is directly under / of the root partition of the local disk, make sure you mount root the partition under say /mnt/localroot. Under /mnt/localroot/lib you will find your corrupted /lib tree structure. However, you make sure that you are not using /mnt/localroot but only /mnt/localroot/lib/ only. Be careful with trailing slashes and path.

mkdir /mnt/localroot
mount /dev/sda1 /mnt/localroot
ls -ld /mnt/localroot/lib

From the shell prompt, locate the rsync binary and start pulling the /lib contents from the remote machine to the local mounted lib directory at /mnt/localroot/lib/.

/usr/bin/rsync --delete -avz -e /usr/bin/ssh <remote-machine-ip-address>:/lib/ /mnt/localroot/lib/

Once the sync is complete, run the same rsync command again. After that, restart the system, take out the boot cd and then try booting from grub in normal mode and identify the logs that every service got started properly with out any errors.

share|improve this answer

If you have another system with a similar Fedora 15 setup, you can boot your system from a livecd, and sync the contents from the other system to repopulate your /lib directory (rsync -avH will do it). Some of your commands may not work then you need to install those packages again.

share|improve this answer
    
@THE DOCTOR: I was going to suggest a similar approach. Actually, if you know the list of packages on your system, you can just do a Fedora installation with the same list of packages. This won't work well unless you have a pretty good idea of the list of packages available though. Plus you could use one of the other system directories to make sure that your list of packages matches closely with the original, by doing a binary recursive diff. Perhaps /usr/lib? –  Faheem Mitha Dec 9 '11 at 16:48

I would suggest that recovery of the /lib is the easy angle to take in that case.

so first of all you must stop using the fedora in question, and run on it a live CD with some recovery program like here (it is a good guide), and recover to a separate HD (since you don't want to destroy the potential of the recovery), then after you have the results from one program and is satisfy you copy it back to the fedora in question, if not try another program.

Probably you wouldn't be able to recover every lib file in the directory, but you can install it afterwards.

In case you can't recover, backup any system files that you have changed to your like, and install the Fedora box again with the "Upgrade" option at the installation stage, that would install only the removed files that associate with your base system.

share|improve this answer

Other answers have explained how to recover your system by rebooting into a live CD/USB. You won't be able to shut down your system cleanly, so press Alt+SysRq+S then Alt+SysRq+U Alt+SysRq+B to unmount filesystems cleanly then directly reboot. There's a small chance that you don't need even that, but that depends on what you have available.

First, you need to be able to execute some process as root. That means having a root shell running, or having a root account with a statically linked shell and a way to log on the console or over ssh. What you can do then will depend on the statically linked tools you have at your disposal. If you have a statically linked mount (e.g. in sash or from Busybox), you can mount a USB stick or NFS filesystem that contains a copy of lib from another version of Fedora. If you still happen to have the rpm packages available, reinstall the ones that provide libraries, starting with libc; as far as I know Fedora's rpm binary is statically linked.

See also Moved bin and other folders! How to get them back?, a different situation but with enough in common that the answers might provide helpful complements.

share|improve this answer
    
Magic SysRq key is off in most systems these days. –  Kwpolska Jun 8 '13 at 9:32
    
@Kwpolska Not in my experience, no. Ubuntu enables it by default (some functions are disabled, but not S/U/B), which alone accounts for a lot of systems. Which distribution turns it off? –  Gilles Jun 8 '13 at 9:47
    
Arch Linux does, AFAIK. –  Kwpolska Jun 8 '13 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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