1

If I made a backup of /usr with:

# cp -r /usr /usrRESERVE1

how can i switch it back after some time:

1# mv usr usrRESERVE2
2# mv usrRESERVE1 usr

second command will not work because mv is inside /usr/bin/mv and it does not exist after first line execution.

//answering to my self...

Solution 1: Using 'mount --bind' as dummy-var

(pointed by comment of user MarkPlotnick):

# mount --bind /usrRESERVE1 /usr  #usr points --to--> usrRES1 from now
# mkdir /dummy
# mount --bind / /dummy           #contains original root folders
# cd /dummy ; mv usr usrRESERVE2
#             mv usrRESERVE1 usr
# cd / ; umount dummy ; umount usr ; rmdir dummy 

Solution 2: using single process - moving tool

# package manager install mmv
# mmv /usr /usrRESERVE1 -- /usrRESERVE2 /usr
  • 1
    What exactly happens when you run /usrRES/bin/mv? Error message please. (I would guess you've also lost your shared libraries.) – Chris Davies Mar 16 '15 at 14:04
  • 1
    and result of ldd mv also. You might need to edit LD_LIBRARY_PATH var as well. – Archemar Mar 16 '15 at 14:06
  • @roaima ... zsh said something like 'no such command nor file' but i will check again now, after both of you think that command should work – Asain Kujovic Mar 16 '15 at 14:09
  • @Omer, I get similar error messages with ksh, but it works for me with bash. Open a bash shell and try my answer below in that shell again. – Janis Mar 16 '15 at 14:16
  • @Janis i just tried bash, same result '/usrRES/bin/mv no such file or directory' – Asain Kujovic Mar 16 '15 at 14:26
  • maybe /usr/bin/mv is still in hash from shell, have you tried ? ( /usr/bin/mv usrRES usr ) – Archemar Mar 16 '15 at 14:38
  • @Archemar i will try :) ... but i think that you pointed LDD well to me, and that i just need do redirect links of 3 libraries libattr libc and libacl .so.1 – Asain Kujovic Mar 16 '15 at 14:45
  • "My full problem indeed was to move my usr to SDCARD because i was running out of space:" WHAT !? move /home or /usr/local or /opt or /data but not /usr ! – Archemar Mar 16 '15 at 14:51
  • size of usr 2GB size of var 2gb, size of home+opt+data ... 100mb. – Asain Kujovic Mar 16 '15 at 14:56
  • 1
    You can use /bin/busybox to move or copy without needing any shared libraries. I'd still do all this from a rescue CD or single-user mode, because any time you remove stuff from /usr, even for a moment, programs may fail. If this is just an academic exercise, then the procedure would roughly be to copy (not mv) /usr to the new filesystem, unmount the new filesystem, mount it on top of /usr, restart all processes with open /usr files, use mount --bind to mount the old /usr somewhere, then clean it out. – Mark Plotnick Mar 16 '15 at 16:31
  • @MarkPlotnick yes, that is what am i after. it is academic research and it was a very real pain for me to reboot system 100 times just to make a tmp=a; a=b; b=tmp; switch. busybox depends on libc.so.6 and mount --bind could be a solution ... can you provide an answer with it? – Asain Kujovic Mar 16 '15 at 18:54
  • I can try to set up a VM and come up with a tested solution. What distro and version are you using? – Mark Plotnick Mar 16 '15 at 19:08
  • @MarkPlotnick i am using archlinux and everything is inside usr, lib is link to usr/lib ... cp -r usr usrRES; mount --bind usrRES usr; works great and it is 50% of problem solved... how to delete underlaying /usr that mount --bind hides – Asain Kujovic Mar 16 '15 at 19:14

0 Answers0