# Moving directories the right way



## cj (Jul 16, 2013)

I need help with moving /usr /var /tmp from the / mount into newly created slices. I used `gpart recover`, `add`, and newfs to format the unused space.  Here is my question. What are the proper steps to move the directories to the new slices?  I want to avoid any unforeseen issues and I want to avoid any issues with performance so I'm asking the experts for a definitive answer.   I've searched for a guide but it wasn't clear or didn't directly relate to my setup.


```
root@:/ # df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ada0p2     36G    2.2G     31G     6%    /
devfs          1.0k    1.0k      0B   100%    /dev
```



```
root:/ # gpart show
=>       34  167772093  ada0  GPT  (80G)
         34        128     1  freebsd-boot  (64k)
        162   79691776     2  freebsd-ufs  (38G)
   79691938    4194109     3  freebsd-swap  (2G)
   83886047   20971520     4  freebsd-ufs  (10G)
  104857567    4194304     5  freebsd-ufs  (2.0G)
  109051871   58720256     6  freebsd-ufs  (28G)
```



```
var /dev/ada0p4
tmp /dev/ada0p5
usr /dev/ada0p6
```


----------



## SirDice (Jul 16, 2013)

You definitely want to do this from single user mode. You basically mount the new filesystem on /mnt/ and copy everything. I usually use tar(1) for this as it keeps ownership, permissions and doesn't mess up soft and hardlinks.

Something like this usually does the trick:
`# tar -C /tmp -cf - * | tar -C /mnt -xvf -`
(this copies everything from /tmp to /mnt)

Once everything is copied correctly you can clear out the old directories and edit /etc/fstab to mount the new filesystems in place.

NB. There's no real need to copy the contents of /tmp/. Just clear it out and mount a clean filesystem on it. The system will create any directories it needs during booting. I would also suggest using tmpfs(5) for /tmp/, especially if you have lots of memory.


----------



## cj (Jul 16, 2013)

Thank you for the prompt and clear answer.


----------



## wblock@ (Jul 16, 2013)

Copying Filesystems shows how to do it with dump(8) and restore(8).  tar(1) means well, but the others know more about UFS.


----------



## wblock@ (Jul 16, 2013)

Rereading, now I see you are splitting up a lone / into separate filesystems.  For that, I would use rsync(1).  Compile it with the FLAGS option on.  Then:

`# rsync -axHAXS --delete --fileflags --force-change [i]source dest[/i]`

Comparing a filesystem copied that way to one copied with tar(1) might be interesting.


----------



## cj (Jul 16, 2013)

I'm trying to `rsync` /usr but I get the follwing:



```
> rsync: link "/mnt/bin/ypchfn" => bin/ypchsh failed: Operation not permitted (1)
> rsync: link "/mnt/bin/chpass" => bin/ypchsh failed: Operation not permitted (1)
> rsync: link "/mnt/bin/chsh" => bin/ypchsh failed: Operation not permitted (1)
> rsync: link "/mnt/bin/chfn" => bin/ypchsh failed: Operation not permitted (1)
> rsync: link "/mnt/bin/passwd" => bin/yppasswd failed: Operation not permitted (1)
```

Any ideas?


----------



## wblock@ (Jul 16, 2013)

Do you have the latest net/rsync?  Was it compiled with the FLAGS option enabled?


----------



## cj (Jul 16, 2013)

Yes. I do.


```
rsync-3.0.9_2       A network file distribution/synchronization utility

===>  Patching for rsync-3.0.9_2
===>  Applying extra patch /usr/ports/net/rsync/work/rsync-3.0.9/patches/fileflags.diff
===>  Configuring for rsync-3.0.9_2
```


----------



## wblock@ (Jul 16, 2013)

The latest is rsync-3.0.9_3.  That's the one that adds the system file flag change support: http://svnweb.freebsd.org/ports/head/net/rsync/Makefile?r1=306932&r2=310222.


----------



## cj (Jul 16, 2013)

Do I need to update /usr/ports?  Hmmm... I think I should reinstall the OS with the partitioning I desire.  This is taking way too long.  I will setup a junk box to practice this some other time.

I thank you for your input though.


----------



## cj (Jul 16, 2013)

I updated ports and recompiled rsync 


```
===>  Patching for rsync-3.0.9_3
===>  Applying extra patch /usr/ports/net/rsync/work/rsync-3.0.9/patches/fileflags.diff
===>  Applying extra patch /usr/ports/net/rsync/files/extrapatch-syscall.c
===>  Configuring for rsync-3.0.9_3
```

Thanks, again.


----------



## cj (Jul 17, 2013)

Got it set up correctly and compiled a custom kernel with tmpfs(5) as you suggested.


```
root@:/var/tmp # df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ada0p2     35G    689M     32G     2%    /
devfs          1.0k    1.0k      0B   100%    /dev
/dev/ada0p4    9.7G    171M    8.7G     2%    /var
tmpfs          5.3G    4.0k    5.3G     0%    /tmp
/dev/ada0p6     27G    4.6G     20G    18%    /usr
```

Nice!


----------

