After accidentally renaming /usr, how do I rename it back?
Since you have set a password for root, use su
and busybox
, installed by default in Ubuntu. All of su
's required libraries are in /lib
. Busybox is a collection of utilities that's statically linked, so missing libraries shouldn't be a problem. Do:
su -c '/bin/busybox mv /usr_bak /usr'
(While Busybox itself also has a su
applet, the /bin/busybox
binary is not setuid and so doesn't work unless ran as root.)
If you don't have a root password, you could probably use Gilles' solution here using (Gilles says this won't work with setuid binaries like sudo) reboot and edit the GRUB menu to boot with LD_LIBRARY_PATH
, orinit=/bin/busybox
as a kernel parameter and move the folder back.
In addition to muru's answer:
you could have used some rescue boot USB key to repair your system; e.g. if your system is some Debian or Ubuntu, boot the installation USB key in rescue mode, and do the appropriate
mount
andmv
andumount
.to be able to repair more easily such mistakes, I generally also install a static shell with several builtin commands (notably with some
cp
,rm
,mv
-like builtins) such assash
(it is packaged in Debian & Ubuntu, and also available as sash-3.8.tar.gz in source form) and boot withinit=/bin/sash
passed to Grub.
PS: sash
is slightly buggy, and not entirely Posix compliant, but still very useful.
I think the best safest way is to reboot using a USB, CD or DVD booted OS (Debian, Ubuntu, Suse, etc). Then mount the drive containing the problems and do the rename.
Safer than booting into a minefield with /usr or /lib effectively missing.