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
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
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