1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Changing /home to another HDD

Discussion in 'Installing and Upgrading FreeBSD' started by caesius, Feb 19, 2011.

  1. caesius

    caesius New Member

    Thanks Received:
    I have a single HDD at the moment. I want to keep this drive but add a new 320GB HDD and make that the new /home.

    How should I go about this and are there any pitfalls to avoid? In my mind I will do this:

    1. Connect new HDD and format with UFS.
    2. Copy /home/* onto the new HDD.
    3. Edit fstab and add the line:
    /dev/ad2s1 /usr/home ufs rw 1 1

    How does this sound? Do I have to specify any flags to cp to retain permissions etc? Also, on tangential note, could I use ZFS for this new /home partition?

  2. wblock@

    wblock@ Administrator Staff Member Administrator Moderator Developer

    Thanks Received:
    Use at least -a with cp(1), but I would use net/rsync:
    # rsync -aH /usr/home/ /mnt/

    Might also want -A and -X or others.

    If the new drive is faster than the old, you might be better moving the whole system over to it.
    caesius thanks for this.
  3. jem

    jem Member

    Thanks Received:
    If your home directories are to reside in a seperate filesystem from /usr, then just mount it directly under /home, not under /usr/home.

    You'll have to delete the /home symlink to /usr/home first then create an empty /home directory to use as the new mountpoint.
  4. SirDice

    SirDice Moderator Staff Member Moderator

    Thanks Received:
    And if you just mount it under /usr/home/ you don't have to change anything at all :e

    This is from the top of my head:
    gpart create -s MBR ad2
    gpart add -t freebsd-ufs -l myhome ad2
    newfs /dev/gpt/myhome
    mkdir /mnt/home
    mount /dev/gpt/myhome /mnt/home
    tar -C /usr -cf - home | tar -C /mnt -xvf -
    umount /mnt/home
    rm -rf /usr/home/*
    mount /dev/gpt/myhome /usr/home/

    You can also try GPT instead of MBR for the partitioning scheme, see gpart(8). The piped tar commands will make sure everything is copied correctly, including hard and softlinks. The label makes it easier to 'handle' the disk. Now it won't matter which drive number or driver (ad0, ad1, da0, da1, ada0, etc.) it gets.

    And last but not least, edit /etc/fstab:
    /dev/gpt/myhome /usr/home/ ufs  rw  2   5

    Obviously you need this placed after the /usr/ entry. The 5 is to make sure the fsck is run after the others have finished, higher numbers are done last. Especially when you have multiple (big) filesystems it pays off not to run them all at the same time.
    caesius thanks for this.
  5. gkontos

    gkontos Active Member

    Thanks Received:
    You don't need to use gpt for that unless you want to boot from it. Instead label the disk:
    glabel label -v name /dev/ad2 (where ad2 is your new drive)

    And your fstab would look like this:
    /dev/label/name /usr/home/ ufs  rw  2   5

    Assuming you mount your new drive under /tmp you can easily copy your data like this:
    #(cd /home && tar cf - .) | (cd /mnt && tar xpf -)
    caesius thanks for this.