Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

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.

#!/bin/bash
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"
        else
            postinst="/var/lib/dpkg/info/$pkg.postinst"
            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
                else
                    if [ -e "/etc/init/$file.conf" ]; then
                        echo "$file has been moved to Upstart"
                    else
                        echo "No update-rc.d line found for $file"
                    fi
                fi
            else
                echo "No post-installation script found for $pkg"
            fi
        fi
    else
        echo "Not an executable, ignoring file: $file"
    fi
done

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

Resources:

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

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.