# Changing /home to another HDD



## caesius (Feb 19, 2011)

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?

Cheers.


----------



## wblock@ (Feb 19, 2011)

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.


----------



## jem (Feb 19, 2011)

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.


----------



## SirDice (Feb 19, 2011)

jem said:
			
		

> 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.



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.


----------



## gkontos (Feb 19, 2011)

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:
[CMD=]#(cd /home && tar cf - .) | (cd /mnt && tar xpf -)[/CMD]


----------

