Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

I accidentally deleted all of the symlinks in /etc/rc1.d/. How can I regenerate them?

share|improve this question
up vote 6 down vote accepted

The most reliable way to get the symlinks back would be reinstalling the packages which have an initscript in it.

I've noticed that neither dpkg-reconfigure nor apt-get --reinstall install restores the symlinks. Not all scripts comply with the LSB standards and do not provide a # Default-(Start|Stop) line.

The below (tested) script looks in the post-installation script of packages for the update-rc.d command which adds the startup script. Previous links had to be deleted in order to work, hence the update-rc.d -f [script-name] remove line. I've verified that all links are properly put back, the only missing file was a README file, but that's not critical.

cd /etc/init.d && for file in *; do
    if [ -x "$file" ]; then
        pkg=$(dpkg-query -S "/etc/init.d/$file" | cut -d: -f1)
        if [ -z "$pkg" ]; then
            echo "**WARNING** No related package found, skipping file: $file"
            if [ -r "$postinst" ]; then
                update=$(grep -Po "(?<!#)\s*update-rc\.d\s+$file\s+((start|stop|defaults)[\s\dS\.]+)+" "$postinst" | sed -e 's/^\s*//' -e 's/\s\+/ /g')
                if [ -n "$update" ]; then
                    sudo update-rc.d -f "$file" remove
                    sudo $update
                    if [ -e "/etc/init/$file.conf" ]; then
                        echo "$file has been moved to Upstart"
                        echo "No update-rc.d line found for $file"
                echo "No post-installation script found for $pkg"
        echo "Not an executable, ignoring file: $file"

If you want to repair it manually, you can use the following:

  • dpkg-query -S /etc/init.d/[script-name] - retrieves the package name responsible for the file
  • less /var/lib/dpkg/info/[package-name].postinst - search for "update-rc.d" to get the command needed to install the startup scripts


share|improve this answer
You're a lifesaver. My results, for interested readers. – ændrük Jun 14 '11 at 18:53

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.