LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I move my home directory to another hard drive? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-move-my-home-directory-to-another-hard-drive-931717/)

ratman1 02-28-2012 05:11 AM

How can I move my home directory to another hard drive?
 
Hi

I am using linux mint 12 x64 gnome 3.

I would like to be able to move my /home directory off my SSD and onto my HDD. My hard drives are set up as follows:
SSD: almost everything on mint installed to this, 60gb so running out of space
HDD: /tmp, /var and swap on here, about 860gb free space (which I wish to be used for /home)
HDD2: windows

I installed mint with the configurations as above. The install worked, partitions worked as they shoud. However, I have the need to move my /home directory to the free space on one of my HDDs.

At first I made the free space into an ext4 partition with gparted, mounted it, although I was unable to write anything to it (the owner was root, meaning I didn't have permisions). I then followed the instructions at http://helpforlinux.blogspot.com.au/...partition.html although when I got down to copying the files over, I was unable to due to the lack of permissions. I googled around, and tried to automount it using the /etc/fstab file, however I still didn't have permissions.

I am at a loss, because whatever I do, I do not have permissions to write to the partition on my HDD.
Any help appreciated.

jimtony 02-28-2012 05:35 AM

May I ask a question?
Did you use root user to do that?

jimtony.

Satyaveer Arya 02-28-2012 05:46 AM

Quote:

I am at a loss, because whatever I do, I do not have permissions to write to the partition on my HDD.
Did you login with the root user and tried copying? Login with the superuser that is root and try again.

ratman1 02-28-2012 05:52 AM

Sorry, I should have specified a bit more. Yes, I can use the root account to write to the mounted partition. However, when I found I couldn't write to it normally, I did not continue because I thought that when I had moved the home directory to the new partition/HDD I would not be able to use my home directory, which would mess things up.

So, in summary, I can actually write to it using the root account, but I decided to stop because I thought I should fix the permission problems before continuing.

acid_kewpie 02-28-2012 05:56 AM

Do you have a dedicated /home partition already? If you don't copy anything, just use dd to lift and shift the entire filesystem nice and easily.

dd if=/dev/sda5 of=/dev/sdb3

for example. As long as the destination partition is larger than the original it should work just fine and then you can resize the filesystem to fill any remaining space in the partition easily enough.

ratman1 02-28-2012 06:00 AM

Thanks

I do not have a dedicated home partition, unfortunately. Normally I make one, although this time I decided not to. The current home directory is 'inside' the root partition, you could say. I do not have a dedicated partition mounted as /home.

The goal of what I am doing is to end up with a dedicated home partition :D

syg00 02-28-2012 06:07 AM

Check your current /home (and sub-dirs) for ownership. As root, use chown to assign ownership of the newhome to match.
Then do the copy (as the user).

ratman1 02-28-2012 06:15 AM

Thanks! That worked. I can't believe I didn't do that first! The files are copying as I speak. Two small questions:
First: the syntax I used was "chown james /mnt/newhome", is there a keyword that refers to all users? i.e. "chown any /mnt/newhome"?
Second: why wouldn't I have been the default owner, if I did the mounting in my own account?

Roken 02-28-2012 07:45 AM

Just a thought - are you copying the files using the terminal. if so, you DID cp -rP and not just cp -r didn't you? If not, all the copied files will be owned by whichever user you used to initiate the copy.

syg00 02-28-2012 03:48 PM

Quote:

Originally Posted by ratman1 (Post 4613996)
First: the syntax I used was "chown james /mnt/newhome", is there a keyword that refers to all users? i.e. "chown any /mnt/newhome"?
Second: why wouldn't I have been the default owner, if I did the mounting in my own account?

1) no - use mode bits to apportion allowed access to others
2) because you did the mkdir as root.

suicidaleggroll 02-28-2012 04:37 PM

Say your new partition is /dev/sdb1, as root run:

Code:

mkdir /mnt/newhome
mount /dev/sdb1 /mnt/newhome
cp -a /home/* /mnt/newhome/

log out as your user and switch to a terminal (Ctrl + Alt + F1 or similar)

mv /home /home.old
umount /mnt/newhome
mkdir /home
mount /dev/sdb1 /home

Make sure everything works, then throw it into fstab to automount it, reboot, make sure everything works again, and finally remove your /home.old directory.

I go through this almost every time I build a machine with /home on a hardware RAID. Depending on the RAID card, the kernel may or may not have support for it built in. Many of them require me to custom compile the driver and insert it into the kernel before I can access the RAID, which means the OS is already installed. In these cases, I install the OS like normal, set up the RAID drivers, set up the filesystem on the RAID, and then perform the above steps to migrate /home onto it.


If you have symlinks or other "complicated" tricks set up, you may wish to use rsync to migrate the data onto the new drive instead, but the process is similar.

lisle2011 02-28-2012 09:20 PM

Home on another drive
 
The best advice is not to do it. If you are crunched for space but have a bunch of space on another drive use it like a data directory. You can make life easier if you make symlinks to your data directory. Don't move the configuration files in your home directory though this is a bad idea. I know because I did it and now I am still regretting all the lost configuration files I transferred. I was able to scrape most of my data off the disk that went to hell and back but my personal configs were toast, not to mention the TIME it takes to fix the problem.
My nickels worth.


If I helped you then give me a pat on the back (add to my reputation)

acid_kewpie 02-29-2012 03:54 AM

Quote:

Originally Posted by lisle2011 (Post 4614646)
The best advice is not to do it. If you are crunched for space but have a bunch of space on another drive use it like a data directory. You can make life easier if you make symlinks to your data directory. Don't move the configuration files in your home directory though this is a bad idea. I know because I did it and now I am still regretting all the lost configuration files I transferred. I was able to scrape most of my data off the disk that went to hell and back but my personal configs were toast, not to mention the TIME it takes to fix the problem.
My nickels worth.


If I helped you then give me a pat on the back (add to my reputation)

Whilst I'm sure that often it's not worth the hassle, I'd be cautious to say solution X is better than Y based on the fact that you had trouble implementing it. Symlinks can cause a lot of pain and mess, and *IF* a fundamental change can be made that removes the need to use a work around, it's generally going to be preferable before going into effort / time / skillset / money issues.

My work around, should I not be able to move /home would more likely be to create a new partition in the spare space and mount it directly where the space is needed, not symlink.

lisle2011 02-29-2012 10:59 AM

Home is where the config files are
 
Actually I was only suggesting that symlinks to directories on another drive might be a solution. But that was not the main objective of my answer. Don't use symlinks but use the drive as a data drive leaving the config alone. The home directory has less content and the data drive has all your 'important files'. You can always rebuild your root partition but with data separated from the home directory a person can pull the hard drive and stick it in another machine and carry on as if nothing happened.

Caution was my only advice and I used a personal experience to illustrate that caution. I did not imply that X was better than Y, I was only suggesting that the questioner think about it.


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