Click to See Complete Forum and Search --> : Moving /usr partition
blooper60
07-09-2002, 07:50 AM
I need some help in moving my /usr partition from sdb to sda.
My Linux box (Linux only) has two 20gig hard drives on it, sda and sdb. The first hard drive has most of the system on it, including a huge /home partition. The second hard drive is fully occupied with the /usr partition.
I would like to clear out the second hard drive to use it as a backup drive. The requires:
1. Reducing the size of the /home partition on sda.
2. Creating a new /usr partition in the space made on sda.
3. Moving the /usr stuff from sdb to sda.
Can anyone give me a simple route to end? BTW, this is a remote administered system. I have no physical access to the box.
Many thanks.
George
jdctx
07-10-2002, 12:11 AM
I'm not a scsi expert so I don't know if the following applies.
1. I'd create a folder in sdb and copy or move the contents of /home there.
2. Remove the /home partition from sda
3. create the /usr partition in sda. don't forget to format.
4. recreate the /home partition in sda again format.
5. move your files from /dev/sdb, /usr to /dev/sda, /usr
do the same for /home contents
6. fix fstab to reflect changes. I would also rename /usr in sdb to something different like /usrbkup just incase.
Alex Cavnar, aka alc6379
07-10-2002, 12:13 AM
Hrm... That's a pretty interesting question...
How's this:
You've got partitions on sda, theoretically:
sda1:/
sda2:swap
sda3:/home
And sdb is like this:
sdb2:/usr
If you have enough space to copy the files from /home to / (or some other directory) then make a new directory, say /new_home. Then, you would do this:
cp -aRv /home/* /new_home/
That will copy all of the files in /home to /new_home, and keep all of the permissions. Next, you need to use fdisk to delete the /home partition. then, when you remake it, use this formula:
(The old size of /home) - (the size you want /usr to be)
example:
(old home)10GB-(new /usr) 4GB=6GB.
So your new partition would be 6 gb for /home. Then you will need to make a new /usr partition with the space left over.
Once you've done this, format the partitions. The new /home will have the same partition number as the old /home partition:
mke2fs /dev/sda3
mount /dev/sda3 /home
cp -aRv /new_home/* /home/
Next, you will need to mount the new /usr partition:
mkdir /new_usr
mke2fs /dev/sda4
mount /dev/sda4 /new_usr
cp -aRv /usr/* /new_usr
Now you will need to edit fstab to mount /dev/sda4 as /usr instead of /dev/sdb1:
/dev/sda4 /usr ext2 defaults 0 0
( You probably already knew that, sorry!)
Now you just have to reformat /dev/sdb1, and you have a new partition to use for backups!
PM me if you have any questions...
blooper60
07-10-2002, 11:07 AM
Alex.
Thanks very much for your suggestion, which seems to cover it very well. Before I try it, however I have just one question.
You suggest that I create a new partition on SDA called /new_user but then set up fstab to point /user to that partition.
Is this correct? Will all the program interactions that are set to look for files in /user know where to go? Or do I have to create a new directory in the new partition, label it /user and re-move all the files there. (After copying files and deleting the /usr directory on SDB of course.)
In other words, I'm not sure I understand the implications of partition names and directory names and how that works here.
camelrider
07-10-2002, 12:01 PM
Darnn! I wish I'd kept the notes when I did this a couple of years ago. I moved several partitions via tarball. I think at the end I just did e.g. mv /usr /old_usr, then mv /new_usr /usr but I don't remember for sure. Then of course make the adjustments to /etc/fstab.
fancypiper
07-10-2002, 12:19 PM
I would pipe through tar as there are less headaches with permissions that way. Check the O'Reilly article (http://linux.oreillynet.com/pub/a/linux/lpt/18_16.html)
janet loves bill
07-10-2002, 01:09 PM
I am such a newbie, he he haw haw haw, I know better than to do this again, I wanted to move /usr and /var, he he -- So from kde I opened /etc/fstab with text editor and added /dev/hda6 /usr default 1 1 and /dev/hda7 /var default 1 1 ----- I made these with partition magic, he he you guys know what came next so I wont even mention it-- :o
next time will pay attention to what you experienced users are saying!! well I am still learning,, he he-- ouch, this hurts.
he he UPDATE: with use of boot disk I deleted those 2 lines off fstab and now have system back, he he --- now to read up and do it right. he he :o
Alex Cavnar, aka alc6379
07-11-2002, 04:24 PM
Originally posted by blooper60
Alex.
Thanks very much for your suggestion, which seems to cover it very well. Before I try it, however I have just one question.
You suggest that I create a new partition on SDA called /new_user but then set up fstab to point /user to that partition.
Is this correct? Will all the program interactions that are set to look for files in /user know where to go? Or do I have to create a new directory in the new partition, label it /user and re-move all the files there. (After copying files and deleting the /usr directory on SDB of course.)
In other words, I'm not sure I understand the implications of partition names and directory names and how that works here.
Not quite. What I meant was to make a new directory. You need a place to mount the new partition to copy the data from the old partition. /new_usr is where I suggested you mount it. After you finish copying the files from the old /usr partition, you would mount the new partition where the old one was mounted.
If a program expects something to be in /usr, then it will not work unless it is in /usr. Basically, you are making a directory to mount the new partition, running 'cp -av /usr/* /new_usr/', unmounting both /usr and /new_usr, and then remounting the new partition (I used /dev/sda4 for my example) under the /usr dir.
I think maybe you're getting confused about the directories. When you unmount a partition, the directory it was mounted under still exists.
Also, partitions and directories are different. Partitions are always devices. They get mounted under directories. Your new partition isn't called /new_usr, it's called /dev/sda4-- /new_usr is just where it was mounted. Once you finish copying the files from /usr over, you will mount /dev/sda4 as /usr, not /new_usr.
I hope this clears things up.
Originally posted by fancypiper
I would pipe through tar as there are less headaches with permissions that way. Check the O'Reilly article
That's a good idea, but I accomplish the same thing by using the -a option. The -a option preserves permissions, recurses the directories, and it even preserves symlinks.