# Shrinking UFS and Adding new mirrored slices



## tkpnewbie (Oct 2, 2012)

Can any kind soul please give me a step by step guide to do the following:

Unmirror the current 2T root partition
Shrink the root partition to say 200G (is there an easy way ?)
Add partitions to disk to give 2 extra slices for /var/appl (600G) and /usr/home (1T)
copy existing data on /var/appl and /usr/home to new partitions
Setup new mirror slices for these new partitions which contain /var/appl and /usr/home.

Current config as follows:

OS version:

```
FreeBSD hostname 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:15:25 UTC 2012     
[email]root@obrian.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC  i386
```


```
$df
Filesystem       1K-blocks      Used      Avail Capacity  Mounted on
/dev/mirror/m0p2 1918673584 52146040 1713033660     3%    /
devfs                    1        1          0   100%    /dev
```


```
$ gmirror status
     Name    Status  Components
mirror/m0  COMPLETE  ada0 (ACTIVE)
                     ada1 (ACTIVE)
```


```
$ gpart show
=>        34  3907026987  mirror/m0  GPT  (1.8T)
          34           6             - free -  (3.0k)
          40         128          1  freebsd-boot  (64k)
         168  3898605432          2  freebsd-ufs  (1.8T)
  3898605600     8388608          3  freebsd-swap  (4.0G)
  3906994208       32813             - free -  (16M)
```


Your help will be much apprecicated.

A newbie to FreeBSD.

Many Thanks


----------



## SirDice (Oct 2, 2012)

tkpnewbie said:
			
		

> Shrink the root partition to say 200G (is there an easy way ?)


Backup and restore, that's the only way.


----------



## tkpnewbie (Oct 2, 2012)

SirDice said:
			
		

> Backup and restore, that's the only way.



Dear Sir,

Thanks for your speedy reply. Can you elaborate a little bit more ?

Does that mean I have to re-install FreeBSD and repartition the second disk to the required partitions before doing backup (from 1st disk) and restore (to 2nd disk) ? (Something I try to avoid...lol)

Will "gpart resize" help at all ?


----------



## SirDice (Oct 2, 2012)

The traditional way to do this is to backup the data, remove the partition, create a smaller one and restore the data.

I've never used *gpart resize*, try it. Make sure you have a backup of the whole disk though.


----------



## wblock@ (Oct 2, 2012)

resize is just going to delete and recreate a partition.  It will not resize the filesystem on that partition, just destroy it.

There are also concerns with using gmirror(8) on a GPT disk.  MBR is preferred, because it does not conflict with gmirror(8) metadata at the end of the disk.

Back it up.  See Backup Options For FreeBSD.
I'd recommend setting up a new, blank disk.  Create a mirror with just that one disk as a member.  Use gpart(8) or fdisk(8)/bsdlabel(8) to set up MBR and the desired FreeBSD partitions on that mirror.  Restore the backup to the new mirror.  Do not modify the original disks; physically disconnect them and connect the new disk for testing.  Once it works, the original disks can be added to the mirror.


----------



## tkpnewbie (Oct 2, 2012)

wblcok,

Thanks for your reply.



			
				wblock@ said:
			
		

> I'd recommend setting up a new, blank disk.



Unfortunately, I don't have a third disk to work with.

I really hope that one can shrink a FreeBSD-ufs filesystem with live data on it.....any suggestions ?

Best Regards.


----------



## tingo (Oct 2, 2012)

If you want to live dangerously, you can always break the mirror (in other words, disconnect one drive, this is you backup), clear, partition and install on the other drive, then connect your backup drive and copy the data to the new system drive. When you are happy with your new setup, clear the backup drive, partition it like the first one and mirror again.
Note: be careful, if you make a mistake, you might destroy your backup before getting the data off it.


----------

