1

I wanted to move /usr on a Raspberry (Bullseye Linux) to an attached SSD, as I already and successfully did with /home.
I copied /usr with rsync to /media/ssd, then renamed /usr to /usr-bak, in order to have it as a backup in case something goes wrong.

Now I realize that I can't do anything anymore. All binaries are no longer executable.
They should be in /usr-bak/bin now, as I only renamed /usr instead of removing it.
I can see they are still there by typing /usr-bak/bin/ <TAB><TAB> that autocompletes to everything I could need.

Unfortunately I am not able to run ls and whatever, especially mv to rename that back and think about another and more clever way to continue.
Calling /usr-bak/bin/mv tells me: No such file or directory
Same for . /usr-bak/bin/mv, going into bin and only calling . mv and whatever else came to my mind.
I also can't run anything from /media/sdd/usr/bin where again, everything exists but doesn't execute.

What is happening here? Did the binaries lose their executable bit by moving the name?

What could I try before I get the raspberry out of where it is and plug it to monitor and keyboard?

Btw. I saw a bunch of similar questions here, but responses to them are not working for me as they rely on somehow executing something helpful. busybox, chmod and whatever... all that is no longer available to me.
For example see After accidentally renaming /usr, how do I rename it back? as mentioned in the comments. I found that and tried that, but I don't have sudo available with $PATH, neither can I run busybox or su or anything else.
This is what I get

user@#pi:/ $ /usr-bak/bin/busybox
-bash: /usr-bak/bin/busybox: No such file or directory
user@pi:/ $ . /usr-bak/bin/busybox
-bash: .: /usr-bak/bin/busybox: cannot execute binary file
5
  • 1
    So you didn't just rename /usr/bin, you renamed /usr entirely - and in a usr-merged system, everything, the loader, all the major libraries, etc. are in /usr. Commented Sep 22, 2024 at 16:40
  • @muru I added more to my question. Indeed this question is similar, but - what I don't understand - the symptoms and behavior of the system is not. Commented Sep 22, 2024 at 17:36
  • If you don't have a static binary like busybox installed, and no running root shell, then you're SOL. Boot from a live USB or attach the disk to another PC, or something Commented Sep 22, 2024 at 17:47
  • @muru busybox is installed, but in /usr/bin so not accessible or executable. Please see my next edit of my question, how I got it solved and how I wonder I could move this directory. Commented Sep 22, 2024 at 18:27
  • 2
    Please don’t add your solution in your question; instead, add it as an answer. You also shouldn’t add new questions to your question, but you can ask new questions! Commented Sep 22, 2024 at 18:54

3 Answers 3

4

Binaries are not just binaries. They are normally built with and depend on shared libraries normally located in /usr/lib64 (or /usr/lib/x86_64-linux-gnu/ on Debian derivatives) as of 2024.

Even in this scenario, distros build busybox statically, and if it's installed you could run and use it to revert your changes.

If busybox is not available, you could boot from any Live distro or from your own distro if it has a live mode.

1
  • It may also be possible to use the LD_LIBRARY_PATH environment variable to point out the directories to search for libraries in. Commented Sep 25, 2024 at 11:36
1

Moved from the question to an answer


The solution to this was quite simple.

I put the SD card of this Raspberry into a card reader that I plugged on a Linux computer. Here I was able to rename the directory there, now it works. Blood pressure is normalizing.

What remains is the question how on earth did the website that I followed manage to move this said /usr directory to the external drive?

I did what they described.

  • Create a directory on the external drive.

  • Copy /user away for backup.

  • Next step would be to edit fstab so that it bind-mounts the external directory to /usr.

What did they miss to explain?

And why is my experience so different from others who did the same as me but managed to access commands?

1
  • perhaps the last thing to do is rename /usr - editing fstab doesn't change anything until you either reboot or re-mount Commented Sep 23, 2024 at 0:13
1

As some other people hightlighted here, the problem is probably due to the fact the shared libraries has also moved as you actually renamed /usr (affecting all its subdirectories).

There is a chance you can workaround this using the LD_LIBRARY_PATH envionment variable like this: Execute LD_LIBRARY_PATH=/usr-bak/local/lib:/usr-bak/lib followed by export LD_LIBRARY_PATH. Then you should probabbly be able to execute /usr-bak/bin/ls and /usr-bak/bin/mv and fix this by renaming /usr-bak to /usr with /usr-bak/bin/mv /usr-bak /usr .

If the above alone doesn't work, there is a chance you also need to set the dynamic linker location by setting the environment variable LD_SO with /usr-bak/lib/ld-linux.so.2 (but this should not be necessary as the dynamic linker usually is under /lib and not /usr/lib (although many distributions symlink /lib to /usr/lib, so only do this additional step if the previous ones alone don't work).

Good luck!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.