LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 03-12-2008, 03:20 AM   #1
Steve W
Member
 
Registered: Mar 2007
Distribution: Ubuntu 12.04, Mint 12 LXDE
Posts: 433

Rep: Reputation: 36
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, 06:00 AM   #2
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 54
Quote:
Originally Posted by Steve W View Post
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
Hi Steve,

If you want to use the whole 17G as your home you can do something like this. Supposing your new partition is /dev/hda8 for example:

Code:
As root:

mkdir /mnt/hda8               # make a temp mountpoint for new /home
mount -w /dev/hda8 /mnt/hda8  # mount the new /home r/w
rsync -axv /home/ /mnt/hda8/  # copy everything from /home
                              # note trailing '/' must be present!
umount /dev/hda8              # don't need new /home at the moment
Now update /etc/fstab to look something like:

Code:
/dev/hda8     /home     ext3    defaults    1 2
then as root:

Code:
mount /dev/hda8 /home
make sure it worked:

Code:
mount
You should see something like this:

Code:
/dev/hda8 on /home type ext3 (rw)
Check your files under /home to make sure everything's ok. If not, stop, go back, and find your mistake (or mine).

If everything worked your new /home is operational and you can delete home from the / partition. As root:

Code:
umount /dev/hda8       # temp unmount real /home
rm -rf /home           # delete old /home under /
mkdir /home            # someone else can probably do this simpler 
                       # maybe just cd /home and rm -rf * but I tremble whenever I do
                       # rm * so I would do it in the steps I outlined here
chmod 755 /home        # make sure perms are correct
mount /dev/hda8        # real /home now activated
If not, DO NOT delete (rm) anything until you've figure what you've done wrong (or what mistake I made here!)

Last edited by Randux; 03-12-2008 at 06:13 AM.
 
Old 03-14-2008, 04:09 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,351

Rep: Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041
Might I add that this is well worth doing.
I just had the Hardy (Ubuntu 8.04) alpha go down big time. After screwing around for a while, I decided to go back to Gutsy - clean install, "over the top" of the Hardy partition.

It all worked fine - and with /home safely isolated, everything came up as if nothing had ever happened. In my case I needed the mail back - I didn't have to actually do anything to get it back up.
Very impressive - especially as I went back a release. Going forward I expect to work, but this was a nice result.
 
Old 03-14-2008, 11:45 AM   #4
Duck2006
Member
 
Registered: Sep 2006
Distribution: Ubuntu 8.04 Hardy Heron LST
Posts: 346

Rep: Reputation: 33
This may help.

http://www.psychocats.net/ubuntu/separatehome
 
Old 03-16-2008, 03:43 AM   #5
Steve W
Member
 
Registered: Mar 2007
Distribution: Ubuntu 12.04, Mint 12 LXDE
Posts: 433

Original Poster
Rep: Reputation: 36
Thanks for the information. I see my original thread was closed by the moderator as apparently it is duplicated on this one. Not sure how this happened as I only submitted one question to one thread! However, my progress is that I am almost there. I have done:

mkdir -p /mnt/{root,home}
mount /dev/hda6 /mnt/root
mount /dev/hda2 /mnt/home
rsync /mnt/root/home/* /mnt/home/

... and how have a complete copy of my /home directory on hda2, where my new /home is intended to be. However, I'm not sure if I've done the mounting and stuff correctly, as I am still seeing my old /home in the file manager. I put in fstab the line:

/dev/hda2 /home ext3 defaults 0 0

... and it's still not working. But I have not deleted my old /home on the root directory yet (just in case something goes wrong). How do I, at this stage in the game, get my Ubuntu to recognise the hda2 directory as proper /home and forget about the /home directory on root (hda6)? Just delete it?

Steve

PS My apologies if this message produces three different redundant threads... still not sure how that happened.
 
Old 03-16-2008, 03:53 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,351

Rep: Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041
You don't happen to have two entries for /home in fstab ???.
 
Old 03-16-2008, 04:21 AM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Quote:
Originally Posted by Randux View Post
chmod 755 /home # make sure perms are correct
mount /dev/hda8 # real /home now activated
Mount the home partition first.
mount /dev/hda8 /home
chmod 755 /home
 
Old 03-16-2008, 07:15 AM   #8
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,017

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
I put in fstab the line:

/dev/hda2 /home ext3 defaults 0 0

... and it's still not working.
just altering the entry in fstab doesn't remount your /dev/hda2 at the new place.

Note: If you are running from a live cd, mounting /home at this stage is a bit pointless.
Also, if you are running from a live cd, do not edit /etc/fstab (because that belongs to the live CD) you need to edit /mnt/root/etc/fstab (because that is your hdd install's fstab !)

On reboot (to your hdd install), things will automatically be mounted according to the entries in fstab, and your /home should appear.
 
Old 03-16-2008, 08:04 AM   #9
simplicissimus
Registered User
 
Registered: Mar 2008
Posts: 104

Rep: Reputation: 15
My solution for this has been quite easy in the paste. I have used actually two methods for doing this.


1)
move the entire home directory to the new drive
$ mv /home /mnt/newdrive
$ ln -s /mnt/newdrive/home /home

Change '/mnt/newdrive' according to the mountpoint of your new drive. Using this method you don't have t change /etc/fstab (assuming that your new drive is already mounted at boot time) and you can anytime move the home directory back. Your home directory will be a softlink to the new location.


2)
move the entire home directory to the new drive
$ mv /home /mnt/newdrive
create a new empty directory as a mountpoint
$ mkdir /home
Modify /etc/fstab by adding a line like:
/dev/sdd1 /home ext3 defaults 1 1

If you want to copy the home directory instead of moving, then use something like:
$ cp -dpR /home /mnt/newdrive
to keep permissions intact.

Hope this helps,
Regards,
SIMP

Linux Archive

Last edited by simplicissimus; 04-02-2008 at 04:35 AM.
 
Old 03-16-2008, 08:21 AM   #10
Steve W
Member
 
Registered: Mar 2007
Distribution: Ubuntu 12.04, Mint 12 LXDE
Posts: 433

Original Poster
Rep: Reputation: 36
I do not understand the significance of mounting the drive, and am getting confused as to how and where I am supposed to be mounting the new /home.

I tried:

sudo mount /dev/hda2 /home

in a terminal and was told "mount: special device /dev/hda2 does not exist"

How can it not exist? I am list it in the file manager if I want to...

And message to Tredegar: I did amend the fstab in the proper root directory, not the one for the live CD.

I think I'm going to need someone to spell out the mounting procedure for this new /home, or I'm not going to get it. At the moment, it's on hda2, but the home showing up in the file manager is on hda6. Both locations contain the same files.

Steve
 
Old 03-16-2008, 08:36 AM   #11
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,017

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
OK, it's time to go back to basics. Please boot to your hdd install post the outputs of

Code:
sudo fdisk -l
mount
cat /etc/fstab
and we'll take it from there
 
Old 03-16-2008, 03:05 PM   #12
Steve W
Member
 
Registered: Mar 2007
Distribution: Ubuntu 12.04, Mint 12 LXDE
Posts: 433

Original Poster
Rep: Reputation: 36
sudo fdisk -l produces:

Disk /dev/sda: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x86aa86aa

Device Boot Start End Blocks Id System
/dev/sda1 * 1 5166 41495863+ 7 HPFS/NTFS
/dev/sda2 5167 7491 18675562+ 83 Linux
/dev/sda3 7492 8722 9888007+ 83 Linux
/dev/sda4 8723 10011 10353892+ 5 Extended
/dev/sda5 9901 10011 891576 82 Linux swap / Solaris
/dev/sda6 * 8723 9844 9012402 83 Linux
/dev/sda7 9845 9900 449788+ 82 Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/sdb: 10.1 GB, 10110320640 bytes
16 heads, 63 sectors/track, 19590 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x6929e695

Device Boot Start End Blocks Id System
/dev/sdb1 1 19590 9873328+ 83 Linux



"mount" produces:

/dev/sda6 on / type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
lrm on /lib/modules/2.6.22-14-generic/volatile type tmpfs (rw)
securityfs on /sys/kernel/security type securityfs (rw)


... and "cat /etc/fstab" (which I really, really don't understand the output of), produces:

# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# /dev/sda6
UUID=15e3d9a0-7aaf-48a3-b923-06f4cea88fe7 / ext3 defaults,errors=remount-ro 0 1
# /dev/sda7
UUID=71a57c2b-b2f5-4d51-8ac0-47ad12d07d3c none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec 0 0
/dev/scd1 /media/cdrom1 udf,iso9660 user,noauto,exec 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec 0 0
/dev/hda2 /home ext3 defaults 0 0


The final line is the one I added myself, which I thought would make Linux think my /home directory was on hda2.

Thank you for all your help with this! I think what I really need is a basic lesson is how mount and the /mnt directory work. If you could post a link to any really useful (i.e. really basic!) webpages on this, it would also be appreciated.

Steve
Learning Linux one day at a time...
 
Old 03-16-2008, 03:56 PM   #13
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Rep: Reputation: 46
Quote:
Originally Posted by Steve W View Post
... and "cat /etc/fstab" (which I really, really don't understand the output of), produces:

# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# /dev/sda6
UUID=15e3d9a0-7aaf-48a3-b923-06f4cea88fe7 / ext3 defaults,errors=remount-ro 0 1
# /dev/sda7
UUID=71a57c2b-b2f5-4d51-8ac0-47ad12d07d3c none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec 0 0
/dev/scd1 /media/cdrom1 udf,iso9660 user,noauto,exec 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec 0 0
/dev/hda2 /home ext3 defaults 0 0


The final line is the one I added myself, which I thought would make Linux think my /home directory was on hda2.

Thank you for all your help with this! I think what I really need is a basic lesson is how mount and the /mnt directory work. If you could post a link to any really useful (i.e. really basic!) webpages on this, it would also be appreciated.

Steve
Learning Linux one day at a time...
For information on mount, you can read man mount. For information on move, you can read man mv. For information on fstab, you can read man fstab.

Starting to see the pattern?

Basically, you might think of mounting something like this (*warning*: hilariously simplistic and generally poor analogy to follow): you have a pie cut into several pieces (i.e., the partitions on your hard drive), but before you can eat a piece of the pie, you first have to put it on a plate (i.e., mount the partition, or filesystem, actually). Once it's on the plate, you can then "access" it (write to it, read from it, etc.).

As it appears that your /home directly currently is in the subdirectory tree (or whatever it's called) of /, you then have to temporarily mount the partition you want to use as /home somewhere else (put the pie on the plate) so that you can copy files to it.

So if /dev/hda2 is the partition you want to use as /home, that's what you have to mount somewhere so you can use it. /mnt is the logical choice here, so first you make the "plate" in the /mnt directory (mkdir hda2 -- it doesn't matter what you call it -- you could even call it "plate" if you wanted ), then you mount the partition there (mount /dev/hda2 /mnt/hda2). Once it's mounted, you can then write data to it.

Once everything you want from /home is moved into /mnt/hda2, delete anything left over in the /home directory. When you reboot, /dev/hda2 should now mount at /home instead of /mnt, since that's what's in your fstab.

Hope that (and the silly pie example) helps you conceptualize it a little better.

>> edit: after typing that out, just noticing that you should make sure you are using /dev/sda instead of /dev/hda. I think most distros are now using sda designation as the default for some reason. /dev/hdax might still mount, not sure, but your other ones are sda, so go with that just to be sure.

Last edited by slackhack; 03-16-2008 at 04:14 PM.
 
Old 03-16-2008, 05:07 PM   #14
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,017

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
My assumptions, based on your previous posts (Please check these against reality):

You currently have two /home directories, on separate partitions but both with the same files in them. I hope. Re-Read your "Colsed as duplicate" thread - I gave you good advice.

You want your new "big home" mounted as /home

You want your new /home to be on /dev/hda2

But the output of your mount command in post #12 is referring to your disks as /dev/sda[some number]
So perhaps that is why you previously received (please read ALL this thread again) messages like:

"mount: special device /dev/hda2 does not exist"
It doesn't exist because your distro is referring to your disks as /dev/sda[some number]

You are not referring to your disk partitions correctly. Your distro names disks as
/dev/sd[some letter][some number] not /dev/hd[some letter][some number]

My analysis of the information you have kindly provided follows:

Your distro is referring to hard disks as /dev/sda[somenumber]

You are trying to refer to them as /dev/hda[somenumber]

Now we have that cleared up, I hope:

The output of mount shows that you haven't mounted any partition as /home

The output of cat fstab shows that you haven't asked for any valid partition to be mounted as /home at boot time.

If you changed the entry in /etc/fstab to read instead of
Code:
/dev/hda2 /home ext3 defaults 0 0
to
Code:
/dev/sda2 /home ext3 defaults 0 0
and rebooted, it might work
 
Old 03-17-2008, 02:07 PM   #15
Steve W
Member
 
Registered: Mar 2007
Distribution: Ubuntu 12.04, Mint 12 LXDE
Posts: 433

Original Poster
Rep: Reputation: 36
Yep, you were spot on. Changed that one letter from "h" to "s" in fstab and it worked first time. I'm not sure why this Ubuntu distro is using sda instead of hda (I got the distro off a magazine coverdisk - it has loads of extra stuff loaded onto the standard Ubuntu distro, but obviously the people compiling the disk could put anything they wanted into fstab); from my limited experience of Linux, I always thought internal hard drives were called hd[something] and memory sticks and USB hard drives were called sd[something]. Ah, well.

The only minor problem I have now, is how to delete the unwanted /home on the root directory. When I click on /home now, it goes to the new /home on sda2. How can I reference the old /home on sda6 in order to delete it?

(PS. do I actually go and delete root/home? Someone said earlier I should leave it there as a "mount point"...)

Steve
 
  


Reply

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
Moving /home dir to separate partition before 7.10 install Thane Ubuntu 2 10-11-2007 06:18 PM
Put /home/username/.* files in separate partition? General Linux - Hardware 10 02-12-2007 02:02 AM
How - Kubuntu Dapper with separate /home partition Optiker Linux - Newbie 20 01-21-2007 05:20 PM
Migrate Directory to Separate Disk Partition Neapolitan Red Hat 1 01-18-2006 01:51 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 12:49 AM.

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