# Changing extra Swap space to /usr



## DrinkingGuinness (Mar 11, 2009)

I recently just installed a proxy server and its running great.  However when I created the partitions and labels i messed up and created two swap partitions. 

1. 4096M  --- THE CORRECT SWAP I WANTED
2. 20480M --- THE PARTITION I WANTED AS /usr

My question is:  
Is there a way to remove the 20480M swap and make /usr without rebuilding the box?

Please be kind, as you can probably tell, I am fairly new to FreeBSD.  

Thanks in advace! :beergrin
Sean


----------



## mickey (Mar 11, 2009)

So where did your /usr go instead? I assume it's now sitting on the root filesystem?


----------



## DrinkingGuinness (Mar 11, 2009)

Yes it is.  I was hoping I could tar the entire /usr located on root and after /usr is created properly just untar it.  

Thanks for the reply!
Sean


----------



## Djn (Mar 11, 2009)

Let's see. If the partition you want to stop using as swap is ad0s1d, something like this might work:

```
swapoff ad0s1d
newfs /dev/ad0s1d
mount /dev/ad0s1d /mnt
cd /usr
pax -r -w * /mnt/
```
Then change /etc/fstab to mount it as /usr instead of swap, something like

```
/dev/ad0s1d             /usr            ufs     rw              2       2
```

That _should_ be it.

If you want to reclaim the space, I'd suggest that you first test rebooting to see if this works, then if it does, go singleuser, umount /usr, and empty the old /usr.


----------



## MG (Mar 11, 2009)

It's also possible to use a single file as swapspace.

make a file of 500 MB filled with zero's:
# dd if=/dev/zero of=swapfile.swp bs=1m count=500

create a virtual disk device with swapfile.swp as storage space:
# mdconfig -a -t vnode -f swapfile.swp -u 10

enable your swap space:
# swapon /dev/md10


----------



## Mel_Flynn (Mar 12, 2009)

The good thing about a swap partition is that it's not a file system. It's "unused space", so the OS just writes bytes to it, keeping a sector map in memory. No directories, no vnode locking, no vfs, no nothing.
When using a file-backed swap, you get rid of these advantages. For desktop use, it's not such a biggy, but for servers, when the OS needs to swap cause of a peak load, you don't want extra slow-downs as it has the potential to snowball.


----------



## DrinkingGuinness (Mar 12, 2009)

OK.  I must have done something wrong.  After I changed fstab, none of my commands worked anymore.  The /usr directory was empty.  I was under the gun so I just rebuilt the thing.  

If I have time I will try to recreate this in my lab and post my results.  

Thanks to all that helped!
:beergrin


----------



## DutchDaemon (Mar 12, 2009)

Did you mount one /usr on top of another /usr?


----------



## fronclynne (Mar 12, 2009)

Djn said:
			
		

> pax -r -w * /mnt/



You'll very likely want "-p e" and, for most of these kinds of situations, "-X".


----------



## Djn (Mar 13, 2009)

Ah, right - "-p e" does seem essential. I was writing from a windows machine, but should have looked at the online man pages.


----------

