LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   move /home (https://www.linuxquestions.org/questions/linux-newbie-8/move-home-935811/)

lld 03-22-2012 01:12 AM

move /home
 
Hi, I'm sure there is a lot about that title out there as much as in here.

But I don't want to move it to an exclusive partition. I want to move it to an existing partition as a folder/directory.

I tried not to post a new thread, trying to hook onto sth similar, but had no luck with it, so here goes the question. Please forgive me if I am not posting in the right place, it is my first post and I am already looking around for an hour...

--------------------------

So, my /home directory is "as is" by default. Here's my df by the way

Code:

[usr@pc ~]$ df
Filesystem          1K-blocks      Used Available Use% Mounted on
rootfs              112474480  70871480  35971000  67% /
udev                  2052100        0  2052100  0% /dev
tmpfs                  2060492      7928  2052564  1% /dev/shm
tmpfs                  2060492      772  2059720  1% /run
/dev/sda2            112474480  70871480  35971000  67% /
tmpfs                  2060492        0  2060492  0% /sys/fs/cgroup
tmpfs                  2060492        0  2060492  0% /media
/dev/sda4            370755860  81214344 270983208  24% /mnt/Datastore
/dev/sda1              508745    214868    268277  45% /boot
/dev/sda2            112474480  70871480  35971000  67% /tmp
/dev/sda2            112474480  70871480  35971000  67% /var/tmp
/dev/sda2            112474480  70871480  35971000  67% /home

Hence, I have my disk sda 500GB ,which was dd from a 120GB
sda1 is boot
sda2 is /
sda3 is swap
and
sda4 is the excess in that hdd from 120 to 500, made as partition (primary, ext4).

my fstab file is

Code:

#
# /etc/fstab
#
#
UUID=0857a373-668c-45af-9aa8-76d838d0da78 /                      ext4    defaults        1 1
UUID=ead41590-d877-4140-9eb1-ffd2f7dab3b9 /boot                  ext4    defaults        1 2
UUID=9c814d9e-42e3-472f-887e-abcf8c526f15 swap                    swap    defaults        0 0
tmpfs                  /dev/shm                tmpfs  defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                  /sys                    sysfs  defaults        0 0
proc                    /proc                  proc    defaults        0 0
/dev/sda4              /mnt/Datastore          ext4    defaults

======================================

So i am automounting sda4 in /mnt/Datastore.

Don't want to use sda4 exclusively for /home, i want to store there other data as well, virtual machines, etc. and I don't want to decide now how much space I should allocate by determining beforehand partition size for each thing. This I think is a terrible space management...

So, I would like to have my home contents in
/mnt/Datastore/home

and somehow make my system understand that location as /home.

I have already managed to copy successfully all the /home contents including all files, folders, maintained permissions etc.

(by the way, I went through a lot of articles about that, solutions with find, cpio, compressing/archiving and decompressing to a new location, etc, in order to also copy links, all hidden and file permissions. In my case, I booted with a linux live cd, mounted sda2 and sda4 and then, the following worked for me:
cp -avfR /mnt/sda2/home /mnt/sda4/)


Thereafter, I know as much as entering in "init 1" and mv /home to a useless name.

But that's how far I get...

I cannot seem to find a way to actually tell my system to automount

/mnt/Datastore/home as /home.

I attempted to automount that relationship in /etc/fstab, but that sort-of-looped my boot. As soon as I could see the fedora loading logo, it hangs there...

From my "df" output, I see that it understands /home in /dev/sda2, which is normal and by default, but i can't find where this is set, in order to change it... (and anyway, this in itself is a problem, because /dev/sda2 is a partition, which is actually "/" root, it was not initially configured as /home: Nevertheless, df sees /dev/sda2 both as / and as /home and as anything else it wishes to see that way...

So, in case the question isn't clear, I want to move /home to a directory in an existing partition with other directory trees in it, don't want to mount to a dedicated disk/partition for that purpose.

Is that possible?
Does it make sense? maybe it doesn't make sense by design.
Am I making a dumb mistake?

Any help would be appreciated.

Thanks

pan64 03-22-2012 02:27 AM

you do not need to mount it at all. try to remove that /home mount completely from fstab and create a symbolic link from /home to /mnt/Datastore/home - or you can replace the user's config so they will have their homes directly in /mnt/Datastore/home
if you want to mount /home you need to share /mnt/Datastore/home first and than configure an nfs mount for that share

dln 03-22-2012 02:44 AM

You could also bind mount it in fstab (/mnt/Datastore should be mounted first)
Code:

/mnt/Datastore/home        /home        none        bind
I had some issues when using a symlink.
Some functions returned the true path without symlink which could be annoying.

lld 03-22-2012 06:52 AM

OK,

thank you very much both of you, you were both helpful!

From pan64's reply I realised I don't have to mount, so looking into changing config for user, found out I can do that with usermod

Code:

usermod -d /mnt/Datastore/home/usr usr
(from what i've seen in man, if i hadn't already copied, including -m in the options would also move the home contents for the user)

takes care of setting the user environment to use this folder as home. So far so good, but in df output, /home still worked for the default location.

So then I followed dln's advice.

I automounted it in /etc/fstab the way he/she indicated. After a reboot, it works beautifully.

The mistake I was making, is that I was automounting in /etc/fstab with options "ext4 default" while I had to mount as "none bind" as dln indicated. I was close, but not close enough to do it without help... :)

So thanks to pan64 for setting my mind free, and dln for correcting my mistake.

Here's an output of df
Code:

[usr@pc ~]$ df
Filesystem          1K-blocks      Used Available Use% Mounted on
rootfs              112474480  70883612  35958868  67% /
udev                  2052100        0  2052100  0% /dev
tmpfs                  2060492      4868  2055624  1% /dev/shm
tmpfs                  2060492      764  2059728  1% /run
/dev/sda2            112474480  70883612  35958868  67% /
tmpfs                  2060492        0  2060492  0% /sys/fs/cgroup
tmpfs                  2060492        0  2060492  0% /media
/dev/sda4            370755860  81225160 270972392  24% /mnt/Datastore
/dev/sda4            370755860  81225160 270972392  24% /home
/dev/sda1              508745    214868    268277  45% /boot
/dev/sda2            112474480  70883612  35958868  67% /tmp
/dev/sda2            112474480  70883612  35958868  67% /var/tmp
/dev/sda4            370755860  81225160 270972392  24% /home

and just for the record, here's an output of /etc/fstab

Code:

#
# /etc/fstab
#
UUID=0857a373-668c-45af-9aa8-76d838d0da78 /                      ext4    defaults        1 1
UUID=ead41590-d877-4140-9eb1-ffd2f7dab3b9 /boot                  ext4    defaults        1 2
UUID=9c814d9e-42e3-472f-887e-abcf8c526f15 swap                    swap    defaults        0 0
tmpfs                  /dev/shm                tmpfs  defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                  /sys                    sysfs  defaults        0 0
proc                    /proc                  proc    defaults        0 0
/dev/sda4              /mnt/Datastore          ext4    defaults
/mnt/Datastore/home    /home                  none    bind

I think this can be considered solved.

Thanks a lot guys!


All times are GMT -5. The time now is 01:05 PM.