Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a KVM virual machine running FreeBSD 9.1, with a typical one-partition layout with slices for swap, /, /tmp, /var, /usr. Now I need to upgrade that virtual server, beside others to a larger harddisk.

I don't want to re-install the whole system and all server applications, so I would rather like to increase the slice sizes of the existing system.

I have seen onlilne that it is quite easy to increase the size of the last slice in the partition, usually /usr, using fdisk, disklabel, and growfs. However, I also need to increase the size of the /var slice as well.

root@chaos ~ % bsdlabel /dev/vtbd0s1
# /dev/vtbd0s1:
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
a:    1048576          0    4.2BSD        0     0     0
b:     980816    1048576      swap
c:   31456593          0    unused        0     0     # "raw" part, don't edit
d:    2586624    2029392    4.2BSD        0     0     0
e:    1048576    4616016    4.2BSD        0     0     0
f:   25792001    5664592    4.2BSD        0     0     0

root@chaos ~ % gpart show -l vtbd0
=>      63  31457217  vtbd0  MBR  (15G)
        63  31456593      1  (null)  [active]  (15G)
  31456656       624         - free -  (312k)

root@chaos ~ % df -h
Filesystem       Size    Used   Avail Capacity  Mounted on
/dev/vtbd0s1a    495M    215M    240M    47%    /
devfs            1.0k    1.0k      0B   100%    /dev
/dev/vtbd0s1e    495M     12k    456M     0%    /tmp
/dev/vtbd0s1f     11G    2.5G    8.5G    23%    /usr
/dev/vtbd0s1d    1.2G    562M    562M    50%    /var

Is there any "best practice" approach how to do so?
Or is this a no-go for all other slices other than the last one?

PS: The system uses UFS file system
PPS: Disk I/O via virtio drivers from ports

share|improve this question
Are you sure you're using slices? In 9.1 the default is to use GPT, not BSD disklabels. This information is needed as it will affect the procedure for changing the partition/slice sizes. –  James O'Gorman Apr 12 '13 at 12:02
I originally installed 8.0, then upgraded to 9.1. But I have not changed the disk layout or file system during the upgrade. But I am not 100% sure -- could you guide me to verify which system is used on my machine? –  Matthias Apr 12 '13 at 12:14
OK, thanks for clarifying. Yes, 8.0 only did BSD disklabels by default. You can tell if you are using GPT by running gpart list. bsdlabel is used to read BSD partitions. –  James O'Gorman Apr 12 '13 at 12:24
Hmm, frankly I am not really sure by checking both. I have updated my posting here accordingly. –  Matthias Apr 12 '13 at 12:39
add comment

1 Answer

up vote 2 down vote accepted

Couple thoughts:

  • There's no way to expand a BSD Slice to two physical locations on a disk (the new space on your disk is only at the end, slices that aren't at the end can't be expanded to that new space). I don't know of a tool that can move slices, but I'd be surprised if one didn't exist.

  • You don't need var on a separate partition. The clunky old installer will always give you the traditional partition layout, which is just as antiquated as the installer. I rarely divvy up the file system into little unmanageable chunks like the installer does, for these exact reasons.

    You can actually just remove the line for /var from /etc/fstab and the system will recreate the var hierarchy on the next reboot on the root slice. Chances are your root partition is also tiny however, again an installer default. This should Just Work™, but I've seen application software throw a fit when their files in /var get tossed.

  • If the current var slice is tiny, it's probably easier to just toss the whole slice and create a new one in the new free space. There should be plenty of directions around, but post if you need more details and I can fill in the blanks.

  • If your disk layout is really hosed, it's usually just easier to drop to single-mode, create a tar of the whole mess, blow away and recreate partitions/labels (using a boot CD or similar), and restore from the tar. I've been there a few times. It's even easier on a VM as you can usually mount a brand new vmdk/vhd/whatever, partition/slice/layout, drop to single-mode, and use a double tar pipe to copy the system without hosing the existing drives (handy in case you oops the process).

  • Update - You've got a /tmp slice that's basically unused adjacent to the var slice. You could unmount, delete the /tmp folder, symlink it into var (ln -s /var/tmp /tmp), remove the tmp and var slices, create a new var slice in that space, remount and Bob's your uncle.

share|improve this answer
Thanks Chris, that sounds well. I have to talk to my hosting provider though whether they could provide a temp. storage for me to save the tar file. –  Matthias Apr 12 '13 at 12:55
Quick question, what's running on this server that you have so much junk in /var? My servers range from 60-550 MB in var, but none are close to 1.2GB. –  Chris S Apr 12 '13 at 13:07
Thanks for the hint Chris, I see that freebsd-update left some files there in /var/db/freebsd-update folder, which I cleared now since I don't need to rollback to 8.0. Ok fine, so I guess it would be easiest now to simply increase the size of the /usr partition and leave the rest as it is now. Thanks! –  Matthias Apr 12 '13 at 14:36
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.