2

I want to move this directory in following way:

sudo mv /usr/lib /tmp/bad_files/
sudo mkdir /usr/lib
sudo mv /tmp/bad_files/lib/* /usr/lib/

Why do I want do do this?

I have filesystem-related problems and I am unable to use fsck to fix them (http://talk.radxa.com/topic/949/how-to-fsck-nand for people who think that's weird) so I want to trick FS to move all files I can't utilize into some dump directory (away from place where they are doing damage because they are not readable).

I tried, I can't move only that single file I have problems with

/usr/lib → sudo mv ./libpostfix-tls.so.1 /tmp/bad_files/
mv: cannot stat ‘./libpostfix-tls.so.1’: Input/output error

I will use apt-get install -- reinstall to reinstall the problematic files from the original package.

Why don't I just do it

if I do

sudo strace mv ./libpostfix-tls.so.1 /tmp/bad_files/

I see that mv command itself utilizes /usr/lib so I am afraid that I might kill my OS by doing this

...
open("/usr/lib/locale/C.UTF-8/LC_COLLATE", O_RDONLY|O_CLOEXEC) = 3
...

so my question: can I move this folder safely or not? OS and device info:

Distributor ID: Linaro
Description:    Linaro 14.04
Release:        14.04
Codename:       trusty
/dev/mtdblock1 on / type ext4 (rw)
1
  • Think you have to restore from your latest backup. Apr 19, 2015 at 13:18

1 Answer 1

4

If you can't take the system down for maintenance, that is a very hard task to actually move the system files while they are being used (if at all possible). If you can take the system down for maintenance, I can think of two ways:

Booting a rescue system

You will need to boot from another system, maybe a rescue disk or something like gparted, then mount your root partition and move /usr as you suggested. This is the safest way I can see so you don't disturb your original system by moving its own files while it is actually running.

Same system: Single user mode + LD_LIBRARY_PATH

If you don't have any other system to boot from for whatever reason, I think you can still do it to the same system in the following way:

  1. Reboot your system into single user mode (runlevel 1 on most linux distros)

  2. Copy /usr/lib/* somewhere safe, say cp /usr/lib/* /tmp/tmplib/

  3. Set LD_LIBRARY_PATH to point to it: assuming you have a bash shell, you will use export LD_LIBRARY_PATH=/tmp/tmplib

  4. Move the files as you are trying to do.

DISCLAIMER: I don't have a chance to try that on a live system, so take it with a grain of salt and always ensure you have a backup of all your files.

6
  • I am unable to do that because of hardware constraints. That server (Radxa Rock Pro, ARMv7) does not allow access to internal NAND memory if booted from secondary media (SD card). Yes, it sucks, but it's cheap and powerful small little thingy Apr 19, 2015 at 17:00
  • Ok, that sounds sad. But now, can you go into single user mode runlevel 1? Do you have physical access to the server or just over the network? If you can, can you try my suggestion to actually copy the /usr/lib and use LD_LIBRARY_PATH? The rational behind going into single user is to make sure almost all services are turned off and you will cause as small disruption as possible.
    – Bichoy
    Apr 19, 2015 at 17:08
  • Forget about my first comment, you updated your answer in meantime with far more details, I promise I will try your tactic and report. The one with LD_LIBRARY_PATH is a very neat trick Apr 19, 2015 at 17:16
  • Good, your question is a very interesting one. Please share your finding and how does it work at the end ...
    – Bichoy
    Apr 19, 2015 at 18:40
  • It worked :) I checked with strace before running, mv indeed fetched libraries from the /tmp/tmplib, thus making it possible for the move to work safely. I was able to restore files from apt-get, I am aware of the fact that it would be best to stop using this NAND memory altogether but for now all my problems were solved thanks to this neat trick Apr 19, 2015 at 19:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .