Link to home
Start Free TrialLog in
Avatar of pai
pai

asked on

Change directory assignment

I partition my hard disk into several parts. Three of them are for Linux. In the begining, I set up one partition for everythin, eg. /root,/usr,/var,/etc.... And I use another partition to try out new distributions. Now I am satisfied with one distribution, and putting more and more stuff in that partition. Recently, I almost run out of space in that partition. However, I have plentify of space left in another partition, as now I'm not trying out new distributions. How can I move some of the directories to the spare partition? For example, /usr, or /var. That way, I can make full use of all the disk space. It took me quite a while to setup the environment that I like now, so reinstalling the whole system is the last option. I use rpm to install most of the programs, and I don't know how to instruct it to put files in diffrent directories than the ones assigned, which are /usr and /etc  in most of the cases. If there is a way, I would like to know, too.

Thanks!

ASKER CERTIFIED SOLUTION
Avatar of joe_h
joe_h

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fremsley
fremsley

exactly as joe_h described it. if you haven't done such things before, here are the steps (as root, and no hard words if something should go wrong):

  - mount your other partition somewhere (i'll assume /mnt)
  - delete anything on that partiontiom (rm -R /mnt)
  - copy e.g. /usr to the file system (cd /usr; cp -a * /mnt)
  - check if anything is on the new file system
  - rename the old directory (mv /usr /usr.old)
  - re-create /usr (mkdir /usr)
  - unmount partition (umount /mnt)
  - go to single user mode (init S)
  - mount the partition under /usr
  - switch to runlevel 2 or 3 (init 2 or init 3)
  - check whether everything is working
  - if yes, make mounting permanent in /etc/fstab (you may delete /usr.old)
  - if not, you can restore your old /usr by removing /usr and renaming /usr.old

hope this helps a bit

Avatar of pai

ASKER

The answer looks fine to me. But, I still have a problem. Can I move more than one directory to a partition. The method given can only mount one directory to one partition if I understand right. Besides, I have some data and programs in that partition that I don't want to destroy. How do I do that? I thought about another method myself. It is to copy /var to a directory the second partition. That's say, it is /2nd/var. Then make a symbolic link of /var to /2nd/var. This way, I can put more than one directory over. I tried that, and it worked so far. My question is that will there be any problem in some special situation? Is it a good solution?
I can't think of a situation where this would be a problem. (Of course, I can't think of all possible situations :) You are right, this method lets you move more than one directory to the other partition, and it is actually used in some cases - e.g. many Linux distributions implement /bin as a link to /usr/bin.

AFAIK, the only thing to keep in mind would be not to move important tools (like mount, sh, vi, etc.), that are usually located in /sbin, to the other partition. You might run into trouble if you ever have a problem mounting the second partition.

Joe
joe_h: in which distribution is /bin linked to /usr/bin? that would mean that /usr has to reside on the root partition to avoid problems when booting.
Oops, wasn't quite right on this one. It is linked e.g. on Solaris (SunOS 5.7); however, I did not check a Linux box until now - and it's not linked there (at least not on my Mandrake 6.1).