LinuxQuestions.org
Review your favorite Linux distribution.
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 07-12-2009, 06:16 PM   #1
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Rep: Reputation: 61
Moving /home to secondary disk?


I have just installed a secondary 500GB HDD (/dev/sdb) and have it automounting as /mnt/sdb1. I have a /home already on the primary HDD. How can I move /home from the primary drive to the secondary drive so simply the OS is on the first drive and /home is on the second drive?

I have partitioned the secondary drive with a single primary partition and formatted it with the ext3 filesystem. My /etc/fstab entry for this currently looks like: -

/dev/sdb1 /mnt/sdb1 ext3 defaults 2 1

Any ideas what I need to do? Thanks.
 
Old 07-12-2009, 06:37 PM   #2
stureedy
Member
 
Registered: Jul 2009
Location: Lexington, Kentucky, USA
Distribution: Slackware
Posts: 37
Blog Entries: 4

Rep: Reputation: 1
Before you start, it would be best to back up everything from /home. Always back up!

--- update: as bigrigdriver pointed out, using a liveCD is a better idea. Then, as Dinithion notes, you could mount the volume currently containing /home read-only. ---

You'll need to be logged in as root. If that's not possible, you can become root on many systems using: sudo -i

First, make sure that no one is using /home: no users logged in other than you. You can check to see if any files are open on /home using:

lsof | grep /home

Since you already have the new disk mounted, copy the home stuff there, using:

cp -rp /home/* /mnt/sdb1

(The r means recursive, the p means keep permissions)

Once it's all copied, you can rename the old /home directory to something else:

mv /home /was_home

(This is for safety's sake. If something goes wrong you can restore everything -)

Make the new /home mount point:

mkdir /home

Unmount the drive that will be home:

umount /dev/sdb1

Change the line in fstab to:

/dev/sdb1 /home ext3 defaults 2 1

Finally, mount the new /home:

mount /home

While still logged in as root, try to log in as a user and make sure that user's home directory copied. Once you're sure everything has copied, you can remove the old (saved) home directory:

rm -rf /was_home

I've checked this three times, so it should be fairly accurate. Of course, I can't come and fix it if it fails, so use at your own risk.

Hope that helps!
Stu...

Last edited by stureedy; 07-13-2009 at 07:14 AM. Reason: better ideas from others
 
Old 07-12-2009, 06:49 PM   #3
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
Quote:
Originally Posted by stureedy View Post
First, make sure that no one is using /home: no users logged in other than you. You can check to see if any files are open on /home using:

lsof | grep /home
It is good practice to remount /home read-only (If home is on a separate partition). On a desktop computer it probably doesn't hurt without remounting, but it doesn't hurt to do it either
 
Old 07-12-2009, 06:53 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Use a liveCD. Mount the root partition (containing /home) and sdb1. Move the contents of /home to sdb1. Edit fstab to show /dev/sdb1 /home instead of /dev/sdb1 /mnt/sdb1. Verify the move was successful: ls /home should show nothing in /home. Run ls on the sdb1 partiton and it should show the contents of /home.

Reboot, remove the liveCD before it starts up, and you should boot into your Linux installation with /home on sdb1.

You can also do it without a liveCD. Mount /mnt/sdb1. Move the contents of /home to /mnt/sdb1. Verify the move was successful. Edit /etc/fstab as shown above, then reboot.
 
Old 07-12-2009, 10:39 PM   #5
cmdln
Member
 
Registered: Apr 2009
Location: Lawrence, KS
Distribution: Debian, Centos
Posts: 102
Blog Entries: 1

Rep: Reputation: 24
I recommend going into init 1 and using rsync.

this is what I would do .... yes its quite a few steps but it really doesnt take that long.

log out
goto virtual terminal (ctrl+alt+F2)
log in as root
type init 1
mkdir /mnt/newhome
mount /dev/sdb1 /mnt/newhome
rsync -avz /home/* /mnt/newhome
umount /mnt/newhome
mount /dev/sdb1 /home
int 5
log in check things out
log out
goto virtual terminal (ctrl+alt+F2)
log in as root
type mount and just make sure that /home is mounted on /dev/sdb1
if it is (it should be since we did that)
umount /home
rm -rf /home/*
mount /dev/sdb1 /home
add line to fstab


should be good. You could a few reboots in there for good measure if your paranoid.
 
Old 07-13-2009, 05:44 AM   #6
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 12.04 / CentOS 6.5
Posts: 394

Original Poster
Rep: Reputation: 61
Thanks all - I'm using the first suggestion so far (doesn't matter if it doesn't work - nothing important on there) but I'll give the others a go as well. Can't have too many alternatives for doing things
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Unable to Boot up from Secondary disk k1ll3r_x Linux - Newbie 4 05-29-2007 11:47 AM
Need access to secondary hard disk: EYEdROP Linux - Software 4 04-01-2007 02:00 AM
disk crashing and moving /home to a new server but all permissions are root HELP! nocnoc Linux - Newbie 4 11-29-2006 12:29 PM
NTFS Secondary Hard disk Rayning Slackware 13 11-08-2006 11:24 AM
How should I setup my secondary HD as /home mount Sagara Sanosuke Linux - Newbie 1 10-13-2004 08:16 PM


All times are GMT -5. The time now is 12:59 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration