# Resize a partition



## lefta (Feb 17, 2011)

Hello!

First of all, I'm quite new to FreeBSD (about a month), and I'm French, so excuse me if my English is not really correct (don't hesitate to correct me )

I would like to resize my FreeBSD partition. I had got some other operating systems on my computer, but I removed them. So I have now a lot of free space. I wish to allocate it to FreeBSD. I found about growfs, but a part of the free space is before the OS.
How can I use the entire disk without re-installing the system please?

Thanks.


----------



## nakal (Feb 17, 2011)

Well, if you read the handbook properly, it will tell you that when you install FreeBSD for the first time, prepare to install it once again later.

I guess it will take longer to resize the partitions than to dump(8) everything on an USB drive, partition it from scratch and restore it back. That's how I would do it.


----------



## _martin (Feb 17, 2011)

Well, you'll be a little bit disappointed - FreeBSD is not that good with resizing partitions (or slices, as the case may be) as other OSes; especially if you have the free space before the FreeBSD partition. Not sure if even gparted can deal with it appropriately. 

You could use rsync  to copy the old system to new partition - depending how much free space you have and what is your FS layout right now. Or even rescue CD can help - trick is the same - create new partition, slice it , mount it somwhere and do a dump/restore or rsync -- whichever you are more comfortable with. Then you can use this system's partition for other use.

World is a better place when you use GPT instead of MBR on disks, but still doesn't solve your problem (and as of yet not possible to choose during sysinstall). 

Nakal's choice suits you the best - there is just too much to deal with and it can be a big deal for a newbie.


----------



## wblock@ (Feb 17, 2011)

lefta said:
			
		

> I would like to resize my FreeBSD partition. I had got some other operating systems on my computer, but I removed them. So I have now a lot of free space. I wish to allocate it to FreeBSD. I found about growfs, but a part of the free space is before the OS.
> How can I use the entire disk without re-installing the system please?



AFAIK, there aren't any utilities to do that for UFS filesystems.  This isn't anything to do with the OS, it's just that no one has written one.

So back up your data, modify the disk layout, then restore.  A full system backup is described in Backup Options For FreeBSD.

matoatlantis suggests rsync(1).  It's a great program, and I use it a lot, but not for full system backups.  There are weirdnesses in UFS that only dump(8) understands.  If you're only backing up certain directories, and know for sure there is nothing more exotic than hardlinks, then rsync is fine.  You might be able to back up just /etc, /usr/local/etc, and your user's home directory; then do an install, setting up the disk like you want, and copy those directories back.


----------



## lefta (Feb 19, 2011)

Thanks for all your replies. I will make a new partition on my external hard drive, and make a backup as you say.
I won't need to reinstall the system, just restore the backup, right?


----------



## nakal (Feb 19, 2011)

You also need to make your harddisk bootable. You need to write a boot block there.

If you have an MBR based disk read about 
	
	



```
fdisk -B
```
in fdisk(8).

If you have GPT partitioning scheme, read about

```
gpart bootcode
```
in gpart(8).


----------



## lefta (Feb 20, 2011)

I did a dump(8), a minimal installation and a restore(8).
I had some little problems, but nothing important. Now, almost all are fixed.

There is just a last little annoying one: my installed packages/ports is empty, so I can't know when a new release is out!
How can I fix it please?


----------



## wblock@ (Feb 20, 2011)

lefta said:
			
		

> There is just a last little annoying one: my installed packages/ports is empty, so I can't know when a new release is out!



Could you explain what you mean by that?  If /usr/ports is empty, just repopulate it with portsnap(8).


----------



## lefta (Feb 21, 2011)

No, /usr/ports is not empty. In desktopbsd package manager, the "Installed packages" tab is empty and when I do a pkg_version :

```
# pkg_version
pkg_version: no packages installed
```


----------



## nakal (Feb 21, 2011)

Looks like you haven't backed up or restored /var properly. dump(8) operates on partitions. You need to dump each partition separately.


----------



## lefta (Feb 21, 2011)

I did. I backed up each slice separately and then restored them.
I tried 

```
#make index
```
but nothing changed.
My ports database was not dumped, I had to reinstall it. Can it be the same problem? Where is the installed software database located?


----------



## nakal (Feb 21, 2011)

First, partition is not the same as a slice. You need to backup all the filesystems separately (usually on BSD partitions).

Then, you need to chdir in every mountpoint you saved and run restore(8) there. Maybe you did not chdir and got everything restored onto the rootfs?

Example to restore /var:

```
mkdir /var
cd /var
restore -rf /backups/var-backup.dump
```


----------



## lefta (Feb 21, 2011)

That is what I did. I followed the instructions given in wblock's link.
I was unable to restore from the DVD's live filesystem, so I did a minimal installation, and then restored from the OS.
Could it be problem?
If yes, how can I restore only the files I need?

PS : Installed french firefox translation today. Now 2 soft in the database...


----------



## lefta (Feb 21, 2011)

You were right, nakal. /var did not restore well, I must have done a mistake somewhere.
Restoring manually, I hope it will be fixed now.


----------



## wblock@ (Feb 21, 2011)

lefta said:
			
		

> No, /usr/ports is not empty. In desktopbsd package manager, the "Installed packages" tab is empty and when I do a pkg_version :
> 
> ```
> # pkg_version
> ...



That you're using DesktopBSD probably should have been mentioned earlier.  It may have a different stock partition layout.


----------



## DutchDaemon (Feb 21, 2011)

wblock said:
			
		

> That you're using DesktopBSD probably should have been mentioned earlier.  It may have a different stock partition layout.



Exactly. You should really have mentioned that from the outset, because you may have nuked your system.

Topics about PC-BSD | FreeNAS | *DesktopBSD* | m0N0WALL | pfSense | Debian GNU/kFreeBSD


----------



## nakal (Feb 21, 2011)

Hmm... I really don't know how DesktopBSD expects the drive to be partitioned and if it expects anything at all. As long as you backed up everything correctly, the system should not be unusable, in my opinion.


----------



## wblock@ (Feb 21, 2011)

If just /var was lost, that's probably survivable.  Ports will still work, and everything can be reinstalled to recreate the database.  The tricky part is figuring out which leaf ports need to be installed.  Possibly there's a way to automate that, although it seems non-trivial.


----------



## lefta (Feb 21, 2011)

Everything is OK now. I restored /var manually (I kept the dump).
I'm not using DesktopBSD, only the DesktopBSD tools, which provide a graphical ports manager. (Uh... Don't sure my sentence is correct... Did you understand? :$)


----------



## lefta (Feb 22, 2011)

I found my mistake : when I restored /etc/fstab, /var and /tmp were inverted...


----------



## piggy (Feb 24, 2011)

lefta said:
			
		

> I found my mistake : when I restored /etc/fstab, /var and /tmp were inverted...


What inverted means? u copied /var files in /tmp and /tmp files in /var?


----------



## lefta (Feb 24, 2011)

Yes and no: I copied /var files in /var, but when I restored /etc/fstab, /var became /tmp and /tmp became /var.


----------



## Beastie (Feb 24, 2011)

This is related so I thought it would be appropriate to mention it.

From the 8.2 detailed release notes:


> The gpart(8) utility now supports a resize command to resize partitions for all schemes but EBR.


----------



## cpul (Feb 25, 2011)

your problem is same what I want to ask


----------

