LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2008, 11:12 AM   #1
UTKEngineer
Member
 
Registered: Jul 2003
Location: Tx, USA
Distribution: FC 7-64
Posts: 37

Rep: Reputation: 15
Moving /usr from hda1 to hda2


Hello everyone, I've painted myself into a corner here and I'm hoping you all can save me.

I'm running Fedora 7 on a machine w/ a 120 GB hard drive sectioned into 20 and 100 GB. The 20 GB is hda1 and used for the linux install. The 100 GB section is hda2 and mounted as /data. I'm using some high end computational programs (Fluent, IDL, AutoCAD, etc). Originally I had planned to install them to the 20 GB. However, some of these programs generate pretty large files and put them in their home directory. Therefore, I need to move my /usr file from the 20 GB hda1 to the 100 GB hda2. Basically, I want to change my current /data to /usr. I would normally re-install to do this, but the license files are tied to the machine name and other data that might change if I re-install. So, is it possible to move my /usr folder to the second partition without pooching my install? Thanks!

Scott
 
Old 01-31-2008, 11:56 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Try this (I hope you have backups of important data, but I doubt this will kill anything )
Stop any programs that might be writing to /usr Then:

Copy all of /usr to /data
("# " Means "As root", do not type the "#"):
Code:
# cd /usr
# cp -a * /data
# cd /
Now unmount your "data" partition ( /dev/hda2 )
Code:
# umount  /dev/hda2
Now remount it "over" your /usr directory
I am assuming you have an ext3 filesystem on /dev/hda2. Modify "ext3" if not.
Code:
# mount -t ext3 /dev/hda2 /usr
Your old /usr data should still be there, but invisible, and replaced with the data from /dev/hda2
To get your old /usr back, just unmount dev/hda2 from the /usr directory:
Code:
# umount /dev/hda2
# mount -t ext3 /dev/hda2 /data
Edit: It might be safest to do this from a "live CD" - it depends on what programs / data you have in /usr - it is not a good idea to move things about whilst they are in use. Then you'll need to update your fstab to reflect the new mounting

Last edited by tredegar; 01-31-2008 at 12:00 PM.
 
Old 01-31-2008, 11:58 AM   #3
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Try the following as root in single user mode:

Code:
# cd /usr
# tar -cvf - . | ( cd ../data ; tar -xvf - )
Check to make sure the two directories look the same and then edit your /etc/fstab file and change /data to /usr in the entry for /dev/hda2.

Now, the following steps may cause you to not be able to do anything, but they should be fine. The first one will certainly work. It is the second that may not work, but if it doesn't, all is not lost, you will just need to reboot from a rescue CD, so make sure you have one before you continue. What you will need to do in rescue mode is make the /usr directory and then reboot.

Code:
# mv /usr /usr-bak
# mkdir /usr
If that worked, try:

Code:
# mount /usr
Reboot to make sure everything is working, and then you can remove /usr-bak

HTH

Forrest
 
Old 01-31-2008, 12:01 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by UTKEngineer View Post
Hello everyone, I've painted myself into a corner here and I'm hoping you all can save me.

I'm running Fedora 7 on a machine w/ a 120 GB hard drive sectioned into 20 and 100 GB. The 20 GB is hda1 and used for the linux install. The 100 GB section is hda2 and mounted as /data. I'm using some high end computational programs (Fluent, IDL, AutoCAD, etc). Originally I had planned to install them to the 20 GB. However, some of these programs generate pretty large files and put them in their home directory. Therefore, I need to move my /usr file from the 20 GB hda1 to the 100 GB hda2. Basically, I want to change my current /data to /usr. I would normally re-install to do this, but the license files are tied to the machine name and other data that might change if I re-install. So, is it possible to move my /usr folder to the second partition without pooching my install? Thanks!

Scott
Yes, you can move /usr to /dev/hda2. You have the added complication of what are you going to do with /data? Assuming that you have moved the /data tree someplace else then you can move /usr to /dev/hda2 this way:

Log in as root

umount /dev/hda2

Format /dev/hda2. Assuming that you want /dev/hda2 to be ext3 then you format with:

mkfs -t ext3 /dev/hda2

Then mount /dev/hda2 on a temporary directory.

mkdir /newusr

mount -t ext3 /dev/hda2 /newuser

Then copy /usr to /newusr

cp -pR /usr/* /newusr

Then add an entry to /etc/fstab to describe /dev/hda2 as being mounted on /usr.

Reboot and check that everything is OK. If it is then boot a rescue CD and delete the old copy of data on /usr so that /usr is an empty directory:

Boot the rescue CD.
mkdir /part1
mount -t ext3 /dev/hda1 /part1
rm /part1/usr/* -R

---------------------
Steve Stites
 
Old 01-31-2008, 12:01 PM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Yes. And it is trivially simple. Reinstalling is never necessary in *nix when you move something.

You have two choices. Being lazy, I usually do it the first way that I will describe.

First choice: Copy the entire /usr file to the other partition, so that that partition has a directory named usr at its top level. Then on your boot partition, just make a symlink to the new usr directory. Specifically, assuming the hard drive is hda with partitions hda1 and hda2 mounted at /mnt/hda1 and /mnt/hda2, do this:
Code:
cd /
cp -pr /usr /mnt/hda2/usr
mv /usr /usrold
ln -s /mnt/hda2/usr usr
Then test it. When you are satisfied it works, delete usrold from /.

The second way is to copy the contents of usr to /mnt/hda2, but copy all the contents and not the directory /usr itself. The result is that you will have, for instance, a bin directory on /mnt/hda2, but it won't be a /usr/bin directory on hda2.

Then edit /etc/fstab and add this line:

/dev/hda2 /usr ext3 defaults 1 1

Save fstab, and reboot.

Now /usr is on hda2.
 
Old 01-31-2008, 12:17 PM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
4 similar, but different, ways to do it in 5 minutes

UTKEngineer will have a headache soon. I'm not sure which way is "best".

@forrestt: "Single user mode" (without your GUI running) is an excellent idea (so you can ignore my "live CD" comment)

Looking forward to hearing how you get on.
 
Old 01-31-2008, 12:24 PM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by tredegar View Post
4 similar, but different, ways to do it in 5 minutes

UTKEngineer will have a headache soon. I'm not sure which way is "best".

@forrestt: "Single user mode" (without your GUI running) is an excellent idea (so you can ignore my "live CD" comment)

Looking forward to hearing how you get on.
Actually, except for my symlink suggestion, they are all functionally equivalent methods.
 
Old 01-31-2008, 12:32 PM   #8
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Possibly off-topic:
Quote:
Actually, except for my symlink suggestion, they are all functionally equivalent methods.
Yes. I had thought of using a link, but there's something in the back of my mind about links across different partitions: Hard links, soft links & different drives / partitions (Alarm Bells are ringing in my ears)
I need to read those man pages again
 
Old 01-31-2008, 12:45 PM   #9
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by tredegar View Post

4 similar, but different, ways to do it in 5 minutes
Wait a little bit and Andy Tannenbaum will chime in with "It's best to do it on a microkernel."

---------------------
Steve Stites
 
Old 01-31-2008, 07:55 PM   #10
UTKEngineer
Member
 
Registered: Jul 2003
Location: Tx, USA
Distribution: FC 7-64
Posts: 37

Original Poster
Rep: Reputation: 15
Hey all,

I mistakenly tried to do this from the GUI today. My computer hung up after issuing the copy command. Upon restarting, the computer wouldn't load the GUI. So, tomorrow I'm going to go rooting around with a live cd and hope that I can fix whatever I've messed up. I may end up re-installing anyway

I really appreciate everyone's help and am sorry that I managed to screw up anyway.
 
Old 01-31-2008, 11:20 PM   #11
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by tredegar View Post
Possibly off-topic:

Yes. I had thought of using a link, but there's something in the back of my mind about links across different partitions: Hard links, soft links & different drives / partitions (Alarm Bells are ringing in my ears)
I need to read those man pages again
you can use soft links from pretty much anyplace to anyplace. Hard links can only be on the same filesystem.

I actually symlink /home from / to a different HD, and I also symlink the documents section of /usr to another HD.
 
Old 01-31-2008, 11:23 PM   #12
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by UTKEngineer View Post
Hey all,

I mistakenly tried to do this from the GUI today. My computer hung up after issuing the copy command. Upon restarting, the computer wouldn't load the GUI. So, tomorrow I'm going to go rooting around with a live cd and hope that I can fix whatever I've messed up. I may end up re-installing anyway

I really appreciate everyone's help and am sorry that I managed to screw up anyway.
you don't need a live cd. Just boot to a console.
 
Old 02-01-2008, 02:11 PM   #13
UTKEngineer
Member
 
Registered: Jul 2003
Location: Tx, USA
Distribution: FC 7-64
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jiml8 View Post
you don't need a live cd. Just boot to a console.
I'm sorry, can you give me a little more information? I'm pretty new to Linux and only know what I've had to figure out for my research (I'm a grad student).
 
Old 02-01-2008, 03:36 PM   #14
UTKEngineer
Member
 
Registered: Jul 2003
Location: Tx, USA
Distribution: FC 7-64
Posts: 37

Original Poster
Rep: Reputation: 15
how about I post a little more info and hopefully you can tell me if I'm beyond hope or not?


When I boot the computer, it starts going through it's boot checklist and arrives at the following error:

Checking filesystems [FAILED]

fsck.ext3:Unable to resolve 'LABEL=/data'



Then it asks for the root password and dumps me to a shell.


Any ideas? Thanks for any help you can offer.

Scott
 
Old 02-02-2008, 04:18 AM   #15
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Oooops! What have you done?

Just copying files to /data should not have done this!
There is a problem in your fstab where it is trying to fsck your data partition, but it cannot find it.
Quote:
Then it asks for the root password and dumps me to a shell.
Can you use this shell? (If not, you'll have to boot from a rescue CD)
Can you see or mount your root partition (/dev/hda1)?
The outputs from
mount
fdisk -l

would be useful to know

Edit your /etc/fstab file on /dev/hda1 so the line referring to 'LABEL=/data' refers to /dev/hda2 instead of the LABEL=/data. Then reboot.

If this is difficult, instead of editing fstab post it here, along with the output of fdisk -l and we'll see what can be done.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you change partition order from say hda2 to hda1, where hda1 does not exist r00tb33r Linux - Software 6 04-09-2007 11:33 PM
If hda1 is (0,0), What Are hda2, hda5, and hda6? rrrssssss Linux - General 2 01-21-2007 04:51 AM
Linux root moved from hda2 to hda1 dangerousdave Linux - Software 3 11-02-2005 06:18 PM
Can mount hda1, but not hda2,3,4,5, or 6? Dobie Linux - Newbie 4 06-13-2004 04:37 PM
mount filesystems from hda1 and hda2 jhirshon Linux - Newbie 3 01-29-2004 12:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration