LinuxQuestions.org
Help answer threads with 0 replies.
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

Closed Thread
 
Search this Thread
Old 03-12-2008, 03:22 AM   #1
Steve W
Member
 
Registered: Mar 2007
Distribution: Ubuntu 12.04, Mint 12 LXDE
Posts: 426

Rep: Reputation: 35
Home directory on separate partition


I'm looking for the best way to set up my /home directory on a separate partition to my root directory. This setup is widely recommended for any Linux distro and I understand the reasons why. I've been researching how to do this, in Linux magazines and on the internet, but I'm getting more and more confused as to the way it should be done.

Part of the problem is that some methods go into detail about creating and formatting the partition itself, as well as copying the /home directory over. This does not apply in my case as I already have a spare 17Gb partition formatted as ext3. I just need to get my stuff over and tell the system this is where my new /home is located.

Could someone please go into detail as to the exact terminal commands I will need to do this? From the different methods outlined on the internet, it seems to be done using a variety of weird and wonderful commands such as rsync and other; some just use "mv".

There is also the question of whether I need to amend fstab to take account of the new location. One method detailed in a Linux magazine makes no mention of fstab at all; is it necessary to amend it or will Ubuntu just locate and pick up the /home directory automatically?

For instance, here is one method detailed in a magazine. It assumes all your stuff is currently on hda1, and you want your new home partition to be hda2:

mkdir -p /mnt/{root,home}
mount /dev/hda1 /mnt/root
mount /dev/hda2 /mnt/home
mv /mnt/root/home/* /mnt/home/
rm -fr /mnt/root/home/*

And that's it. No mention of fstab at all. Would this work in those five lines?

Obviously, I could just try it and see, but without knowing exactly what is going to happen, I don't want to risk messing up my system as it is now...

Could someone please advise whether I should go ahead using the above method, or do they have a better way?

Steve Wylie
 
Old 03-12-2008, 03:25 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
What's with the triple post?!
 
Old 03-12-2008, 04:47 AM   #3
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,178

Rep: Reputation: 49
While what you've posted will work, it will be reset upon your next reboot. You can edit the /etc/fstab file (see man fstab for a very thorough list of options) so that your new harddrive is recognized as /home for the future.

For example, one (relatively) easy way of doing this is to mount the drive as a new folder, copy the relevant data over, change the fstab, and enjoy a nice cup of tea for a job well done.

Code:
# mkdir /tmp/newhome/
# mount /dev/hdb1 /tmp/newhome/
# cp -r /home /tmp/newhome/        [make sure to watch out for permissions errors here]
# vi /etc/fstab                    [Here you may add a line that puts /home/ on the /dev/hdb1 device]
# umount /dev/hdb1
# mount /dev/hdb1                  [Since the drive is now in your fstab, it will be placed 
                                   'over' your current /home directory]
Granted it's been awhile since I've swapped directories and drives, but I hope that the above will get you on the right track!

Last edited by Poetics; 03-12-2008 at 04:48 AM.
 
Old 03-12-2008, 04:49 AM   #4
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 366Reputation: 366Reputation: 366Reputation: 366
There are lots of ways of doing this (moving /home).
My method:
Boot your PC. Do not login to the GUI. You want home not-being-used as you make a copy of it.
<CTRL><ALT><F1> to get a terminal. Login as root.
Make a mountpoint for your new home partition, and then mount your new partition:
Code:
mkdir /mnt/newhome
mount  -t  ext3  /dev/whatever_it_is  /mnt/newhome
Copy (not Move, in case you mess things up) the old home to the new home, I like to do this with a "tar pipe" as this copies everything perfectly, preserving timestamps, permissions, ownerships etc.:
Code:
cd /home
tar  cf  -  .  |  (cd  /mnt/newhome  &&  tar  xBfp  -)
Wait while it copies.
Then unmount the new home, and mark the oldhome as such, by creating a file in it.:
Code:
umount  /dev/whatever_it_is
touch /home/I_AM_OLD
Now you'll need to add an entry like this to fstab so the new home is mounted at boot time:
Code:
/dev/whatever_it_is    /home    ext3    defaults   0 2
Now remount everything, according to what is in fstab:
Code:
mount  -a
Your new home partition will be mounted "over" your old home directory. All should be well. Make sure you cannot see the file /home/I_AM_OLD
If all is well (and you can also check /home is properly mounted with the mount command, with no parameters) then you can delete your old /home directory, to save space on the root partition. Be very careful here.
Logout.
Do not login to your GUI.
Login to a <CTRL><ALT><F1> terminal as root.
Unmount your new home partition
Code:
umount   /dev/whatever_it_is
Your old home will reappear. Cd to it and make sure you can see the file /home/I_AM_OLD before deleting everything in /home, like this: (The pwd is to make sure you really are in /home before you do a powerful, un-undoable deletion)
Code:
cd /home
pwd
rm  -rf  *
Now remount your new home:
Code:
mount  -t  ext3  /dev/whatever_it_is  /home
Logout.
Login to your GUI
Check all your new free space with df -h

Last edited by tredegar; 03-12-2008 at 04:51 AM.
 
Old 03-12-2008, 08:47 AM   #5
jukebox55
Member
 
Registered: Aug 2007
Distribution: slackware 11
Posts: 101

Rep: Reputation: 15
Quote:
Tredegar
Quote:
Copy (not Move, in case you mess things up) the old home to the new home, I like to do this with a "tar pipe" as this copies everything perfectly, preserving timestamps, permissions, ownerships etc.:
Code:
cd /home
tar  cf  -  .  |  (cd  /mnt/newhome  &&  tar  xBfp  -)
this is interesting, i was just wondering what the dash - signifies?

Last edited by jukebox55; 03-12-2008 at 08:53 AM.
 
Old 03-12-2008, 12:37 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Follow-ups here:
http://www.linuxquestions.org/questi...tition-627445/
 
  


Closed Thread

Tags
home, move, partition


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
Home directory on separate partition Steve W Linux - Newbie 23 03-19-2008 01:51 PM
Home directory on separate partition Steve W Linux - Newbie 2 03-12-2008 12:36 PM
Moving /home dir to separate partition before 7.10 install Thane Ubuntu 2 10-11-2007 06:18 PM
How - Kubuntu Dapper with separate /home partition Optiker Linux - Newbie 20 01-21-2007 05:20 PM
Does anyone here have a separate /root and /home partition? Kramer Linux - General 12 03-17-2004 05:52 AM


All times are GMT -5. The time now is 04:24 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration