LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ELF header trouble great! :( (https://www.linuxquestions.org/questions/linux-newbie-8/elf-header-trouble-great-92912/)

Baran 09-15-2003 02:12 AM

ELF header trouble great! :(
 
The story of the trouble is long...

Two days ago I tried to install MATLAB R13 on my Red Hat 9.0 machine. It was going right until the install GUI crashed under KDE. I turn off the computer, the next time I tried to boot linux, I had errors, like this...


...
date: cannot load /lib/librt.so.1 no such file or command
...
sleep:cannot load /lib/librt.so.1 no such file or command
...

Linux boots, however X is not available. Afterward I went to directort /lib to look at the file librt.so.1 , therewas !librt.so.1 there. Fortunately I was using Midnight Commander, it was writing that, !librt.so.1 is a broken symbolic link to lijrt.2-3-2.so , I found that there isn't file like lijrt.2-3-2.so but there was one which is librt.2-3-2.so, I thought that this should be the link so I created a file named librt.so.1 which is a symbolic link to librt.2-3-2.so. I thought that I was doing the right. However when I reboot my system, this time I got such errors

...
date: cannot load /lib/librt.so.1 invalid ELF header
...
sleep: cannot load /lib/librt.so.1 invalid ELF header
...

System boot again but without X, I then thought that it should wise to install ELF-devels from the RedHat9.0 installation CDs, I found some files like elfutils, elf-devels, like things anyways, when I wrote...

rpm -ivh elf-devels.....

I got this error:

rpm: cannot load /lib/librt.so.1 invalid ELF header

Now I am stuck to this ELF header business, what should I do?

unSpawn 09-15-2003 02:58 AM

I thought that this should be the link so I created a file named librt.so.1 which is a symbolic link to librt.2-3-2.so. I thought that I was doing the right.

If you don't know if what you're doing, experimenting til it breaks is cool :-] Running (as root): "rpm -qf /lib/librt.so.1" shows it's part of the Glibc rpm. There's two ways to fix this, and that's manually linking librt.2-3-2.so to librt.so.1 or force reinstalling the package. Sure there's more ways like extracting and running the scripts part of the rpm and running ldconfig could update the links as well.
If you opt for reinstalling the rpm you don't have to, else run ldconfig to update the library cache after you're done.

Baran 09-15-2003 03:05 AM

But I cannot run rpm command, I tried this just to test if I can use it

rpm -qa

just this command gace the same error

rpm: cannot load /lib/librt.so.1 invalid ELF header

I mean I cannot install any rpms

I tried ldconfig as well, it says

ldconfig:there is no such file or command

they told me that ldconfig comes with glibc package this must be installed, but I guess I don't have that

say something :) I don't want to reinstall all the system...

unSpawn 09-15-2003 03:10 AM

Have the rpms ready (ftp 'em from a local RH mirror or like that) and run rpm from the RH bootdisk/cdr.

Baran 09-15-2003 03:14 AM

I don't know if this is the same thing:

I boot the system with installation CD-ROM, there is a rescue option there, so I did that, afterwards,

chroot /mnt/sysimage (it was saying that this is my system)

then I tried rpm again, but I had the same error, I can try from a bootdisk also, but I think it is same, isn't it?

unSpawn 09-15-2003 04:14 AM

Yeah it's the same. Boot the rescue cdr and point rpm to use the database on the disk. It should work. If it doesn't post the exact commands and errors you got. One way to get these in one file is to start a logging session using "script <filename>" (make file is on a writable disk, not the cdr). When you're done type "exit" to exit "script". Make sure you edit out any control commands and other garbage before you post the logfile.

Baran 09-15-2003 04:17 AM

thank you for your help, unfortunately I can do that tomorrow :(
I wish you will be around :)

Baran 09-15-2003 04:18 AM

I am sorry I forget to ask, what does this mean:

"Boot the rescue cdr and point rpm to use the database on the disk"

unSpawn 09-15-2003 04:44 AM

Rpm has a flag "--root" you use to tell it where the rpm databases are, because the ones you want to use are not on the cdr.
Btw, did you try manually linking librt?

Baran 09-15-2003 04:49 AM

yes I can manually link librt. In fact I tried it already, I wrote it in the first massage, I got that ELF header errors after I linked that. Before I made the link, it was saying that there isn't such file or command...

I guess what you are telling is

rpm --root <my database>

but where is my database?

I am sorry I still don't know enough about linux :(

Baran 09-16-2003 02:12 AM

I got the exact error at the boot:

/bin/date: error while loading shared library
libraries: librt.so.1 cannot open shared object file: No such file or directory

after that booting goes on, and the when the system is done, X doesn't start instead I get this:

INIT: Id "x" respawning too fast: diabled for 5 minutes




Up to now I tried these:
1) I manually created link for librt.so.1 to librt-2.3.2.so because when I look at file information for librt.so.1, it was saying that it is a broken link to lijrt-2.3.2.so so I thought it should be librt-2.3.2.so :)

2)Then I tried /bin/date again
[root@localhost root]# /bin/date
/bin/date: error while loading shared libraries: /lib/librt.so.1 : invalid ELF header

3) then
[root@localhost root]# ldconfig
ldconfig: /lib/librt-2.3.2.so is not an ELF file-it has the wrong magic bytes at the start
/lib/librt.so.1 is not an ELF file-it has the wrong magic bytes at the start
usr/lib/librt.so is not an ELF file-it has the wrong magic bytes at the start

I then thought that I may be massing things up and modified the librt.so.1 as it were before linking lijrt-2.3.2.so, afterwards


4) Boot from CD, then

bash-2.05b# ldconfig -r /mnt/sysimage
ldconfig: /lib/librt-2.3.2.so is not an ELF file-it has the wrong magic bytes at the start

5)
bash-2.05b# rpm --root /mnt/sysimage -qf /mnt/sysimage/lib/librt-2.3.2.so
file /mnt/sysimage/lib/librt-2.3.2.so is not owned by any package

6) I tried these also
bash-2.05b# rpm --root /mnt/sysimage --force -ivh elfutils-libelf-0.76-3.i386.rpm
/sbin/ldconfig: /lib/librt-2.3.2.so is not an ELF file-it has the wrong magic bytes at the start
rpm db:/var/lib/rpm/Triggername: No such file or directory
rpm db:/var/lib/rpm/Triggername: cannot sync:No such file or directory
error:db4 error(2) from dbenv-> close: No such file or directory


I guess I wrote everything...

what can be done now?

unSpawn 09-16-2003 07:01 AM

//First of all you shouldnt crosspost your questions. I can imagine you need it fixed fast, but crossposting is bad netiquette, a waste of time for LQ members and respectless towards those who provide you with resources (LQ, Jeremy, that is). Bump your thread if you need to instead of crossposting. If still impatient, consider supporting the Linux cause by hiring a local Linux guru.

That said, first open up /etc/inittab and change the "5" in the line starting with "id:5:initdefault:" to "3": "id:3:initdefault:". This will load up the system in *single user* mode to prevent loading X while you work out your solution and you won't get hassled with the "INIT: Id "x" respawning too fast: diabled for 5 minutes" messages.
Execute "telinit 3" to enter runlevel 3. Make sure you stop any network services you don't need to provide right now ("chkconfig --list").

I guess what you are telling is
rpm --root <my database>
but where is my database?

Should be the /var/lib/rpm dir (do an "ls -al" on it to see).

I am sorry I still don't know enough about linux
No prob. That's what LQ is here for.

For any of the commands below (between quotes), if you can't run them, boot the Red Hat cd in rescue mode: do not make it boot your Red Hat on your harddisk.

1) I manually created link for librt.so.1 to librt-2.3.2.so because when I look at file information for librt.so.1, it was saying that it is a broken link to lijrt-2.3.2.so so I thought it should be librt-2.3.2.so
I don't know any library called "lijrt-2.3.2.so", "ln -sf /lib/librt-2.3.2.so /lib/librt.so.1" should do.

2)Then I tried /bin/date again
Of course that should not work, it isnt fixed yet.

3) ldconfig: /lib/librt-2.3.2.so is not an ELF file-it has the wrong magic bytes at the start
Fsck! Corrupted library. Last ditch effort, gotta extract from rpm and restore manually before running ldconfig.
Locate your Glibc rpm, I'm using glibc-2.3.2.i386.rpm as example:
"mkdir /var/tmp/glibc; cd /var/tmp"
"rpm2cpio glibc-2.3.2.i386.rpm > glibc-2.3.2.cpio"
"mv glibc-2.3.2.cpio glibc/; cd glibc"
"cpio --make-directories --force-local --extract --no-absolute-filenames --no-preserve-owner --verbose -F glibc-2.3.2.cpio"
"cp -f lib/librt-2.3.2.so /lib; ln -sf /lib/librt-2.3.2.so /lib/librt.1.so"
(don't know if necessary: "ln -sf /lib/librt.1.so /lib/librt.so")
"rm -rf /var/tmp/glibc"
Now run "ldconfig" (from cd if you cant make it work).
Then running "ldconfig -p|grep librt" should show the libraries.

If it works you should "refresh" the glibc rpm to be consistent with the database. I guess this means you'll have to use --force to update it with the same version.


4) Boot from CD, then
ldconfig -r /mnt/sysimage

Wasn't fixed yet, right?

5) rpm --root /mnt/sysimage -qf /mnt/sysimage/lib/librt-2.3.2.so
file /mnt/sysimage/lib/librt-2.3.2.so is not owned by any package

Shouldn't that be "rpm --root /mnt/sysimage -qf /lib/librt-2.3.2.so"?

6) I tried these also
rpm --root /mnt/sysimage --force -ivh elfutils-libelf-0.76-3.i386.rpm

AFAIK librt isnt in elfutils-libelf...

rpm db:/var/lib/rpm/Triggername: No such file or directory
rpm db:/var/lib/rpm/Triggername: cannot sync:No such file or directory
error:db4 error(2) from dbenv-> close: No such file or directory

Auch! List your (/mnt/sysimage)/var/lib/rpm and check for temporary files (starting with two underscores AFAIK)
"ls -al /var/lib/rpm".
if errors persist, make a backup copy of /var/lib/rpm and rebuild the database with "rpm --rebuilddb".


Hope this helps, if any errors occur, be sure to post the output and the commands leading up to it. One way to have 'em all in one file is to run your session under "script": login and run "script </path/to/filename>". If you boot the cdr, then make sure the logfile goes to a readable dir like /mnt/sysimage/tmp.
Be aware the "script" logfile also logs control chars, scrub them before you post any lines.

Baran 09-17-2003 06:43 AM

Did anyone said you are a great man unSpawn? I tried what you have said. Then everything started working as before. The solution was easier then I have imagined, however I learned that understanding the problem is much more harder sometimes.
Thank you for everything. By the way about the crossposting business: I didn't think that this would be a bad thing, I thought that the threads were listed according to their first date of post, this thread was on the third page when I wrote a new thread. But I then realised that a thread becomes the first one on the list when a new post is send, however it was so late, I had already sent the new thread which was the same. If I had known that the procedure was like this, I wouldn't do that. I am sorry again.

One suggestion: I tried to erase the second thread but I couldn't manage to do that. I guess there must such an option, owner of the tread should be able to erase his/her tread.

Take good care...

unSpawn 09-17-2003 07:20 AM

Did anyone said you are a great man unSpawn?
No, and I just ain't, LOL.

The solution was easier then I have imagined, however I learned that understanding the problem is much more harder sometimes.
Just try to formulate your problem clearly, find out the dependencies and test each part of the equation. If you do that in a methodical way then you'll definately get better at troubleshooting.

One suggestion: I tried to erase the second thread but I couldn't manage to do that. I guess there must such an option, owner of the tread should be able to erase his/her tread.
LQ doesn't allow members to delete threads or posts. Only thing you can do is edit out the text from the post and call for a mod to close the thread. Only root (Jeremy) can delete threads, and he will only do that if it is in violation of the LQ rules.

Baran 09-17-2003 09:22 AM

OK then unSpawn, next time when I want to delete my thread I will call you :)


All times are GMT -5. The time now is 01:01 AM.