Recovering from Empty /etc/passwd

At work I have an old Dell desktop running SLES 9 (among other systems I manage). I inherited the system, and it was configured to mount home directories with help of LDAP, a process that I am not familiar with. It also runs some legacy systems I do not feel like migrating to newer systems yet.

Recently the LDAP information changed, so I needed to find out how to update this information. I found the settings in YaST, and everything seemed to be functioning with the new settings. That is, until I tried to become root. I got informed that there is no such user. “That is weird,” I thought, “I don’t think I’ve ever seen this kind of error with a Linux box”. After some more experimenting it became clear that updating LDAP had somehow caused all local users to disappear. /etc/passwd was empty!

As luck would have it, I found several backups of /etc/passwd, one even made by YaST itself when I updated the LDAP information. But this file was only accessible by root, which I could not become! Ubuntu has a way to boot into a root prompt, but I could not see how to do that with the SLES 9 boot prompt.

If I had a system rescue CD or Knoppix or something similar I would have tried that next, but it seems the recent office move displaced a number of our CDs so that was not immediately available either. However, I found old Ubuntu and openSUSE Live CDs. The Ubuntu CD wouldn’t work in this aging Dell (I suspect flaky CD drive), but the openSUSE 11 Live CD booted ok. I could not start X, but I could login as root through the console. Almost there!

The Live CD had not mounted the hard drives, but I could see the devices with fdisk -l. Then it was a matter of issuing:

mkdir /tmp/hd1
mount /dev/sda1 /tmp/hd1

to mount the HD, and then finally copying the backup passwd file over the empty one. After reboot everything was nominal (I guess I’ve watched too much Defying Gravity).

Similar Posts:

    None Found

2 Comments

  1. ln:

    init=/bin/bash

  2. Heikki Toivonen:

    Thanks In! To help others, you need to add those to your kernel boot options. After that you get in, but your root file system is mounted read-only. To remount writeable, you can do:

    mount -n -o remount /

    and then do any changes you need, and reboot.