2

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!

1
  • What distro are you using on this machine ?
    – user9517
    Nov 19, 2011 at 12:15

3 Answers 3

7

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:

/etc/rc2.d:
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.

2
  • 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, 2011 at 15:12
  • 1
    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, 2011 at 15:29
3

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.

0
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .