Page 1 of 1 [ 8 posts ] 

gamefreak
Veteran
Veteran

User avatar

Joined: 30 Dec 2006
Age: 30
Gender: Male
Posts: 1,119
Location: Citrus County, Florida

14 Nov 2009, 12:47 am

I have a Dell Dimension 2350 that I installed Ubuntu on. However I have 2 10GB Hard Drives. Both drives are already mounted and I use gParted to format and mount the second one. However I wonder how to put MY Documents directory on the slave drive. The 1st drive will my OS and programs and second will be for documents.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 71
Gender: Male
Posts: 9,608
Location: Somerset UK

14 Nov 2009, 8:50 am

There's the "proper" way, and the improper (quick) way.

There is no "My Documents", for starters.

What there is is (usually) a /home directory, under which each user gets their own home directory, such as /home/gamefreak

Within your home directory, there will be everything you own, plus some "hidden" files (which are anything that starts with a period - and are not usually shown. These contain all personalised settings, etc.)

So... using a second drive (or indeed, any partition, anywhere), usually involves copying some stuff there, and telling Linux that it is now there.

===========

The classic way to go, is to make an entire partition be where /home is to be found. This is done by putting a line into the text file /etc/fstab saying that /home should be found on a specific mounted partition.

As you don't really want to be logged in, while copying your active files, I'd suggest that you use a "Ctrl/Alt/F1" and login as root (who you may need to give a password to, as these days, root tends not to have one. So, to be able to login as root, start with e.g. a "sudo passwd root".)

Assuming your new partition is an ext3 filesystem in /dev/sdb9 (I do like using lots of partitions)...

Code:
mkdir /home.old
mv /home/* /home.old
echo UUID\=`vol_id --uuid /dev/sdb9` /home ext3 defaults 0 2 >> /etc/fstab
mount /home
cp -a /home.old/* /home

The lines are:
  1. mkdir /home.old
    Make a new directory, just to hide away all the initial contents of the /home directory.
  2. mv /home/* /home.old
    Move all of /home to the save area. This line has a bug. There are normally NEVER any hidden files under /home (with the exception of . and ..). You can verify this with "ls -A /home". At this point, your user logins are broken. However, should disaster strike, you merely need to do the reverse: "mv /home.old/* /home".
  3. echo UUID\=`vol_id --uuid /dev/sdb9` /home ext3 defaults 0 2 >> /etc/fstab
    A bit of "shell magic". Enclosing a bit of a line in back-quotes (grave accents) asks the shell to execute that text as a command, and replace the text with the output of the command. The backslash preceding the equals sign makes that be just treated as text, and not interpreted. In fact, this whole "UUID..." lump could just left as the old style: "/dev/sdb9". The final ">>" tells the shell to send all the line to the tail end of your fstab. DO NOT make the mistake of using a single ">", or it will overwrite the file - which would be inconvenient. Maybe a "cp -a /etc/fstab{,.backup}" before doing his would be a good idea!! Also, do this line just the once, or you'll start collecting redundant extra lines at the end of the file. (Whew?)
  4. mount /home
    Now that fstab has an entry for your new partition, mount it. Maybe there already was an entry, after all this, and instead of all my messing about with the preceding line, above, introducing the new fstab line, you could have just edited the one already there?
  5. cp -a /home.old/* /home
    Finally. The bit that will take all the time. Actually copying all your users' home directories across to the new partition. Just don't bother to try logging in until this has completed.
That should do it all... without deleting your old home directory at all.
As I've just typed all that off the top of my head, I'd advocate waiting for everyone else to proofread it, before you go typing it in!! !
Also, the whole method is somewhat suspect, as there could conceivably be cron scripts active, which may not like all the home directories being (temporarily) moved away.
It would all be more safely done by dropping to single user, or even better, running off a live CD.
The nasty part of the whole process is that I never am fully happy when I have a partition that start "one level down". I.e. seen on its own, the new partition has all the user names at the top level, with no clear indication that "/home" is where they all really start from. (Does that makes sense?)

===========

My favoured method, these days, is just to use symlinks to "bend" parts of my file system to other places.

I organise mounted partitions to look just like parts of my root filesystem.

If I wanted user "fred" to have all his files on the mounted partition "/media/hdb9", I would do this:
Code:
mkdir /media/hdb9/home
cp -a /home/fred /media/hdb9/home
mv /home/fred{,.old}
ln -s {/media/hdb9,}/home/fred
cp -a /home/fred{.old,}


More often, I use the same sort of thing to bend sub-directories of my home directory off onto other partitions. E.g. I might keep my images in /home/myself/images, but that will be symlinked to /media/sdc5/home/myself/images

I do the same trick when I find my root filesystem is getting a bit unwieldy. E.g.
Code:
ls -ld /usr/share/doc
lrwxrwxrwx 1 root root 25 2008-01-11 22:53 /usr/share/doc -> /media/hdb9/usr/share/doc


==========

Oh... and finally, once you are happy that everything is working in its new place, and reboots fine, etc, you could delete the backups - or you could just leave them all as backups!


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Last edited by lau on 15 Nov 2009, 8:21 am, edited 1 time in total.

Fuzzy
Veteran
Veteran

User avatar

Joined: 30 Mar 2006
Age: 48
Gender: Male
Posts: 5,223
Location: Alberta Canada

14 Nov 2009, 1:38 pm

The best time to set this up is when you are installing. Gparted will let you name partitions things such as /home. /home could be the second disk. Then when the file system is installed, all will be transparent.

Likewise, you can divide up any portion of the operating system like this - though some divisions make no sense. I am currently storing /usr/local on its own partition.


_________________
davidred wrote...
I installed Ubuntu once and it completely destroyed my paying relationship with Microsoft.


CloudWalker
Veteran
Veteran

User avatar

Joined: 26 Mar 2009
Age: 30
Gender: Male
Posts: 711

14 Nov 2009, 9:38 pm

What about cloning the first disk to the second, and then delete everything except /home on the second drive.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 71
Gender: Male
Posts: 9,608
Location: Somerset UK

15 Nov 2009, 8:19 am

CloudWalker wrote:
What about cloning the first disk to the second, and then delete everything except /home on the second drive.

This sounds a rather slow way of copying one directory - although that's not really a big deal.

However, it would leave /home splattered across some indeterminate bits of a 10 gig partition.

Also, the UUID of the partition on the second drive will be the same as the UUID of the original partition, which will cause (not insurmountable) problems.

PS. I got my code section wrong.... I left out the "UUID\=" in there. Although I corrected it in the explanation of the line, I hadn't corrected it in both places. Done now. (Where are my proofreaders?)


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


CloudWalker
Veteran
Veteran

User avatar

Joined: 26 Mar 2009
Age: 30
Gender: Male
Posts: 711

17 Nov 2009, 7:50 am

I was thinking about hardlinks. Apparently "cp -a" can handle it with no problems. So, there's really no reason to use the clone method unless cp run out of memory.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 71
Gender: Male
Posts: 9,608
Location: Somerset UK

17 Nov 2009, 8:46 am

There is one difference that does crop up - after a "cp -a", you will usually find that some tiny amount of space has been saved. I believe that is just the effect of recovering slight fragmentation effects, within directory files. E.g. a directory with files "000" to "999" created, then "000" to "998" removed, will not automatically squash back down.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer


Vexcalibur
Veteran
Veteran

User avatar

Joined: 17 Jan 2008
Age: 35
Gender: Male
Posts: 5,398

17 Nov 2009, 9:25 am

take your second drive, create a folder called "docs". Then right click and do "create link"

Then move this link to your home folder with copy paste.

Grats, your home now has a folder which uses goes to the second drive.


_________________
.