Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I've made a huge mistake and moved /lib and /opt folders to subfolder. Now almost every command returns "No such file or directory" or "/bin/sh: bad interpreter: No such file or directory". I need to move these files back, but I can't run mv. Can I do it somehow or should I start restoring server from backups?

EDIT:

My provider allowed external access to file system, so I was able to move directories to main directory and everything went back to normal:) Thanks for help.

share|improve this question
    
Possibly, you can boot using live CD and try to fix it –  Khaled Jan 6 '12 at 15:03
    
@Khaled: I don't have physical access to server, so I can't mount filesystem from outside. –  LukLed Jan 6 '12 at 15:05
    
Do you have an out of band access like iLOM or IPMI? If so you can do a network boot. –  Mircea Vutcovici Jan 6 '12 at 17:17
    
Be sure to post your solution and mark it as the accepted answer. –  jscott Jan 6 '12 at 17:53

4 Answers 4

up vote 4 down vote accepted

Step 1: Boot from live-cd...

Step 2: Mount the Hard Disk

Step 3: and move the files back.

Step 4: NEVER do that again.

(if you need specific instructions... just ask)

share|improve this answer
    
Thanks. Sorry I didn't mention it earlier. I don't have physical access to server. I am in the shell now using putty. –  LukLed Jan 6 '12 at 15:06
    
it looks like you moved your /bin folder as well. You could try specifying the full path to executables you need... for mv & such... i.e. /opt/bin/mv /opt/bin / I am not sure if that will work... but worth a shot... –  TheCompWiz Jan 6 '12 at 15:10
    
I can't specify full path, it just doesn't work, there is the same error. I didn't move bin folder. –  LukLed Jan 6 '12 at 15:15
    
I guess at this point... you need to do some digging and figure out what commands do work... if there are any. Maybe cat? i.e. cat /opt/dir/file > /dir/file –  TheCompWiz Jan 6 '12 at 15:36
1  
Yep. It relies on the underlying OS to be sane in order to do its tasks. At this point... I think you're screwed. Time to get someone on the phone over there... and step them through a live-cd. –  TheCompWiz Jan 6 '12 at 15:55

You might be able to undo the move by something like:

 export LD_LIBRARY_PATH=/subfolder/lib
 /subfolder/lib/ld-linux.so.2 /bin/mv /subfolder/lib /lib

...replacing /subfolder with whatever directory you moved /lib into. If a 64-bit Linux host, try ld-linux-x86-64.so.2 instead.

I haven't fully tested this, because I'm not going to break a system in order to do so!

share|improve this answer
    
I would gladly try to use your solution, but I was able to solve it by mounting file system from outside, so the problem is over. If this could work, we will never know:) –  LukLed Jan 6 '12 at 17:52

Don't logout that Putty session ! You probably won't be able to get back into the server.

Can you run busybox ? (it usually lives in /bin so try "/bin/busybox")

Busybox is almost completely self-contained and has build-in versions of most standard Unix commands'. Busybox without any parameters gives you a list of all commands that it can emulate.

You run the commands like "/bin/busybox {command} ".

E.g.: "/bin/busybox mv file1 file2"

If you have it on the system you can probably use it to move everything back to the original locations.

share|improve this answer
    
I won't be able to get back to server. "/bin/busybox" doesn't work too:| –  LukLed Jan 6 '12 at 15:19
    
That's not good. Next thing to try is if you can connect a FTP or SCP client to the server and rename the folders back with that. (Is probably not going to work unless you are allowed to do FTP (or SCP) as root, which is usually disabled for security reasons.) –  Tonny Jan 6 '12 at 15:28
    
I can't do it. FTP works, SCP doesn't, but root access is not allowed. I am so happy now to have secured server... –  LukLed Jan 6 '12 at 15:33
    
Time to restore then: at least you will be able to pull copies of critical config files and such using FTP. That may help to fix configuration issues after the restore (depending how old the backups are). –  Tonny Jan 6 '12 at 15:37
    
No need to restore, see my solution below. :) –  Mattias Ahnberg Jan 6 '12 at 17:06

You have a tool called sln which is a statically linked ln. You can use this one to symlink the folders to the previous place, and then work from there. So say, if you moved /lib to /datadrive/lib and then you broke the system, you could type this to temporarily fix it:

sln /datadrive/lib /lib

Do this for each library path you might have moved.

share|improve this answer
    
I was not able to run any command, including ln and sln. –  LukLed Jan 6 '12 at 17:42
    
That is very very strange. What OS is it? And what happened when you tried to run sln? The point with sln is that it statically linked, compared to dynamically linked, which means it doesn't require any external libraries. Its self-included. I tried it myself just to verify before I gave you the recommendation, I moved /lib and /lib64 into a subfolder, and everything stopped working like for you, then symlinked it back and voila. Worked. :) But glad it worked out with your Edit baove. –  Mattias Ahnberg Jan 6 '12 at 18:48
    
I am using debian and sln is not found:) Thanks for trying:) –  LukLed Jan 6 '12 at 19:12
    
Oh darn. I thought Debian/Ubuntu had it too, I tried on RedHat/CentOS machine. Sorry. :( But glad it worked out! :) –  Mattias Ahnberg Jan 6 '12 at 19:35

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.