Grow FreeBSD UFS filesystem on VmWare HDDs
In this artice I’m going to show you how to expand your UFS filesystem under FreeBSD that runs in a Vmware Virtual Machine.
FreeBSD uses slices instead of traditional PC partitions. To sum it up shortly, it means that your whole disk contains only a single traditional partition with the partition type ‘freebsd(165)’. Inside this partition you will have slices. In a typical FreeBSD installation you have seperate slices for /, /usr, /var, /tmp and swap. In most cases the last slice on the partition is the /usr, and hopefully this is the one we have to extend, because in this case the only thing needed is to add some space to the end of the drive and extend the last slice. Sounds easy? Don’t think so!
The main steps are:
- Increase the actual (virtual) hdd size
- Extend the partition to cover the whole disk
- Extend the size of the last slice to cover the whole partition
- Extend the actual UFS filesystem on the newly modified slice
All the details:
First, forget livecds like gparted-live, knoppix, other partition hacking tools because they will not work.
- Stop your VM and Edit its settings
- Boot into single user mode (select 4 in the FreeBSD boot menu)
- check your new disk via dmesg, you will see the increased block number

but your partition is still at the previous size (fdisk -s)

- Let’s change the partition size using fdisk -u

In my example my partition starts at 63 and has the size of 18860247 blocks
What you would normally do is to adjust the new size to totalblocks-start. In this case fdisk will complain that the ending block is not on cylinder boundry. Fdisk will fix the value you entered but if you want to do the math yourself here is how it should be done correctly:
cylinder_size = 16065 [blocks]
new size = trunc(totalblocks/cylinder_size)*cylinder_size-startblock
in my case
trunc(25165824/16065)*16065-63 = 25157727
- Next step is to extend the slice size. Slices are edited with the bsdlabel utility. You might need to mount a couple of more partitions to access your editor.
EDITOR=<yourfav> bsdlabel -ewill bring up the slice table in your favorite editor. Now you need to change two things. - First the line where it says do not edit: change it to your new partition size.
- To get the new size of the last slice you need to do the following calculations:
new_size_of_last_slice=partition_size-offset_of_last_slice
- The last step is to extend the FS itself on the new slice. Make sure you don’t have the slice in question mounted. Then run growfs /dev/
. In my case it was /dev/da0s1f

- To check your results run fsck, mount -a, df -h
- If you’re happy, you can reboot into multiuser mode now
Posted 2009/11/30 07:31 by jos
Comments
← VIMAGE - Better virtualization in FreeBSD 8 PureFTPD virtual chroot →


BMac Says:
I followed your instructions exactly. Did the calculations you recommended and intentionally made it larger to see if fdisk would correct the value (to verify my calculations) and it was correct. I edited the disk label as instructed and it matches the values from fdisk -s (I verified that the fdisk -s size values matched the raw size in bsdlabel on two other FreeBSD machines and they did) however.. growfs STILL will not grow….
# growfs /dev/da0s1f
GEOM_LABEL: Label ufsid/4b60blahblah
growfs: we are not growing (3204711->3204711)
GEOM_LABEL: Label for provider da0s1f is ufsid 4b60blahblah
#
any advice?
Anesti Bubulya Says:
I had to boot into single user mode to run fdisk -u to change the geometry of the partition. I actually moved the files onto a backup slice. Then I had to boot using a boot CD/Floppy to make changes to the slice in question. I deleted the slice I was trying to grow, then created the slice again and moved all the files back. Cumbersome, but it worked.
Alexey Says:
Could you please expand the step
1.First the line where it says do not edit…
2.To get the new size…
What was before and what was after (bsdlabel screenshots). Thank you
David Basquin Says:
In case one get stucked at bsdlabel step, this might be helpful…
Before I found this article, I was having a hard time with bsdlabel. Even though my /tmp and /usr were mounted, I was unable to write changes.
So I ended up using another /tmp mount point by creating a specific file system in physical memory (#mdmfs -M -S -s 100m md /tmp). Problem solved.
luxury Bally bags Says:
Articles are moving every reader with heart, and full of appeal. Let us have to admire, thank your article!
D & G handbags wholesale Says:
Thank you! I LOVE this. I made one. I use it all the time. I will be posting a picture of mine and providing a link on my blog.
Ihor Kaharlichenko Says:
On FreeBSD-8.2 I get Operation not permitted from bsdlabel. In order to resize the /ad0s1f partition I used gpart:
# gpart resize -i 6 /dev/ad0s1
By default gpart resize makes the partition occupy all the available space saving you from messing with bsdlabel calculations. The parameter to -i flag is the index of the partition in the slice being edited (6 for f )and can be taken from gpart list output.