Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is kind of scary! I removed /etc/init.d directory! How can I recover this directory? I know that if I restart my computer now I won't see my linux again!

Please advice!

share|improve this question
What distro are you using on this machine ? – Iain Nov 19 '11 at 12:15
up vote 7 down vote accepted

Look at the /etc/rc?.d directories. You will find symlinks in those that point to the scripts that were in /etc/init.d. You will know what startup scripts you will need to restore to /etc/init.d. So, something like:

$ ls -l /etc/rc?.d

and you will see something like:

total 4
-rw-r--r-- 1 root root 556 2009-01-23 15:01 README
lrwxrwxrwx 1 root root  18 2009-10-27 00:05 S10sysklogd -> ../init.d/sysklogd
lrwxrwxrwx 1 root root  15 2009-10-27 00:05 S11klogd -> ../init.d/klogd
lrwxrwxrwx 1 root root  13 2009-10-27 00:05 S16ssh -> ../init.d/ssh
lrwxrwxrwx 1 root root  18 2010-06-07 22:04 S20bluepill -> ../init.d/bluepill

To get a copy of those scripts, do what Martin suggests, or, alternatively, spin up another machine (on a spare computer or in a virtual environment) using the same Linux distro, and copy the relevant /etc/init.d files from there; you may have to install additional packages. The latter might be easier.

After you copy the files, you should run the "ls -l /etc/rc?.d" again. The broken symlinks should now be there. If there are broken links, figure out what packages provide those, etc., install those on the VM, and keep doing this until things look correct.

After that, you're probably going to be OK, though you should be prepared to get console on the machine in case something goes wrong.

share|improve this answer
Good answer, but this will only restore scripts that were set to run at startup. For instance you had mysqld installed and it was not set to launch at boot then the symlink to /etc/rcX.d/ will not be present. If you want full file recover look into Filesystem recovery. – Andrey Nov 19 '11 at 15:12
True, but it should be sufficient to get the user to the point of being able to reboot the system again. If the user later has to run non-startup services via /etc/init.d scripts, and the script is missing, the user will know why. – cjc Nov 19 '11 at 15:29

Install the same Linux distri in a VM, if you have extra services like Apache etc. install them too, and copy the /etc/init.d directory to your machine.

share|improve this answer
Nice one! Thanks for your answer – user24912 Nov 19 '11 at 14:09

Maybe you could find developer infrastructure (issue trackers, repositories, ...) for your distribution and checkout the scripts out of there.

This would work for basic init scripts. For various program's init scripts you can either checkout the init scripts for each such program, or simply reinstall appropriate package.

share|improve this answer

Your Answer


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.