Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705
Rep:
Quote:
Originally Posted by Steve W
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!)
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.
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.
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.
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.
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.
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:
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.
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.
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
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"...)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.