LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Moving /home to secondary disk? (https://www.linuxquestions.org/questions/linux-newbie-8/moving-home-to-secondary-disk-739601/)

arashi256 07-12-2009 05:16 PM

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.

stureedy 07-12-2009 05:37 PM

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...

Dinithion 07-12-2009 05:49 PM

Quote:

Originally Posted by stureedy (Post 3605455)
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 :)

bigrigdriver 07-12-2009 05:53 PM

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.

cmdln 07-12-2009 09:39 PM

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.

arashi256 07-13-2009 04:44 AM

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 :)


All times are GMT -5. The time now is 01:25 AM.