Skip to content

Recovering /etc/name_to_major

September 7, 2009

What do you do if you manage to delete or corrupt /etc/name_to_major? Assuming you don’t have a backup a ZFS snapshot or an alternative boot environment, in which case you probably are in the wrong job, you would appear to be in trouble.

First thing is not to panic. Do not reboot the system. If you do that it won’t boot and your day has just got a whole lot worse. The data needed to rebuild /etc/name_to_major is in the running kernel so it can be rebuilt from that. If your system an x86 system it is also in the boot archive.

However if you have no boot archive or have over written it with the bad name_to_system this script will extract it from the kernel, all be it slowly:

#!/bin/ksh i=0 while ((i < 1000 )) do print "0t$i::major2name" | mdb -k | read x && echo $x $i let i=i+1  done

1Redirect that into a file then move the remains of your /etc/name_to_major out of the way and copy the file in place.

Next time make sure you have a back up or snapshot or alternative boot environment!

1You will see lots of errors of the form “mdb: failed to convert major number to name” these are to be expected. They can be limited to just one by adding “|| break” to the mdb line but that assumes that you have no holes in the major number listings which you may have if you have removed a device, so best to not risk that.

Advertisements

From → Solaris

3 Comments
  1. Thommy M. Malmström permalink

    Wow, that I should have known som 10 years ago… 😉

  2. Faster (runs in two seconds on my system):
    i=0
    while ((i < 100 ))
    do
    print "0t$i::major2name"
    print "::echo $i"
    ((i+=1))
    done | mdb -k 2>&1 | while read x
    do
    [[ "$x" = "mdb: failed to convert major number to name" ]] && break
    if [[ "$x" != +([0-9]) ]]
    then
    major=$x
    else
    print "$major $x"
    fi
    done

  3. Thanks nico.
    However you do need to go higher than 100 and also you need to not stop on the first error as there can be holes in the name_to_major name space if when drivers are removed.
    Although the gains in your script are from not forking so many copies of mdb, which is good.
    So up the number to 1000 and change the "break" to "continue" and it is good.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: