Hard Disk Partition Sizes
Before we get started, I am acting under the impression that the reader is a relative newbie to the world of FreeBSD, and is attempting to figure out how to partition their disks for the first time. I also assume that the reader is aware of the official FreeBSD documentation related to installing located here: The FreeBSD Handbook Install Section. More aware users will have discovered the partitioning information available under man tuning under FreeBSD 6.0 . By the existence of this page, however, you have also realized that some tweaking to both the default setup and the information in tuning is necessary for many installations.
It is worth repeating that FreeBSD looks at hard disk partitions in a slightly different way from windows and linux. When I refer to partitions in the following sections, I am refering to FreeBSD style partitions, which are a bit different from what you may be used to under linux or Windows. To make a long story short, FreeBSD can hold many partitions inside of a single slice (a FreeBSD slice = a windows or linux partition). This frees FreeBSD from being limited to a rather inconvenient number of 4 or so partitions. Read the handbook carefully for more details
The Default Install
As of FreeBSD 6.0, sysinstall will create partitions sized approximately as follows by default:
/ 128MB SWAP two times the system RAM /var 256MB /tmp 256MB /usr remainder of the disk
Many of these partitions are entirely too small, and they are not sized with any thought regarding the usage of the machine. There are a few basic reasons to make a separate partition:
- to nicely size a partition for a weird backup scheme that cannot handle unusually large backup dumps.
- to protect the space needed by something (particularly the base system) from being stepped on by other programs
- to limit particularly hungry programs from stepping on the space of everything else.
Some thought about what you are trying to protect and what you are trying to limit is in order for configuring a system.
One Big Partition
The default install contrasts strongly with a fairly popular partitioning scheme for a system for an individual user. (NOTE: as of Release 9.0 sysinstall has been replaced with bsdinstall, and the default partition in now a single partition.)
SWAP two times the system RAM / remainder of the disk
Although this will work, this layout should never be used on an important system, for two major reasons:
- In case of a serious system failure (repeated reboots), the entire drive will need to have it's file system checked with fsck on every reboot. The core systems of FreeBSD do not require very much disk space. Sensible partitioning would allow you to only check critical partitions, and put off the rest of the checks until the system is stable. This can be the difference between 2 minutes per reboot-with-fsck and thirty minutes per reboot-with-fsck on larger drives! (Note: this is not an issue with ZFS, since ZFS does not require fscks).
- One of the primary reasons to separate things out, is to prevent one partition from filling up all the space and making other things stop working because they run out of space.
The SWAP partition
This one is fairly easy. The twice the amount of system RAM rule of thumb is a good one. If you have multiple hard disks on the system, man tuning and Partitioning Tips and Tricks#Multiple Disks? Multiple /swap have some good suggestions.
The /tmp partition
It is extremely common for this partition to be undersized. This partition is used in building ports, and several programs will keep fairly large temporary files here. You want to make it a separate partition:
- To protect the system from either a very large port compile (such as the larger windowmanagers or an X graphical interface system)
- To prevent a run-away process that is simply filling the disk with as much data as possible from infringing on your / filespace.
- To minimize the probability that the often-accessed /tmp directory will cause excessive file corruption on your / partition in the event of a crash.
The danger of making this partition too small is that you will cause yourself unnecessary grief when you want to build a large package or when a program you are running needs alot of temporary space (such as a video editor).
If you are not installing a graphical system and are unlikely to be editing large files, a fairly small tmp should work fine. Even compiling the larger ports should work inside of 128MB-256MB of tmp. If you will be editing either large numbers of image files or video files on the system (or other large files), a large sized tmp partition does seem more reasonable. A bit more than two times the largest file size you are likely to be editing would seem to be a reasonable limit.
Another consideration for /tmp size is whether the system will be used for writing a CD or DVD. If so, /tmp needs to be sized to hold the interim file created, which can be just under 10GB for a dual-layer DVD.
The /var partition
var also depends highly on your intended use of the machine. Email, logs, the default mysql databases, another tmp directory, and print spooler information are all held in subdirectories of this partition. You may want to separate this off to prevent logs or emails from overrunning the system. If you plan to run a system with large mysql databases (such as a major mysql-backed forum or wiki site), you may want to consider replacing the /var/mysql directory with a soft link to a mysql directory on another, larger partition.
The /var/tmp directory
The /var/tmp directory can be deleted, and replaced with a soft link to the /tmp partition (or vice versa). This can be done with either ln -s /tmp /var/tmp or ln -s /var/tmp /tmp as root. This is recommended since there is essentially no difference between /var/tmp and /tmp on modern systems, but some programs use one instead of the other.
It is not a good idea to place /var or any of its subdirectories on RAM, except on certain Read Only operating systems. Var and its subdirectories usually contain needed information that is normally not supposed to be emptied on reboot. The programs md or tmpfs would be used in conjunction with /etc/fstab to achieve this.
The /usr partition
The /usr partition contains a few major sections. There are a few approaches to this section. One is to give it it's own largish partition. Second - and absolutely not recommended - is to lump it into the main / partition (and either move the ports tree or watch its size carefully). Third is to split off several sections either into their own partitions or to symlink them from the / partition to a larger partition. Tuning recomends up to 3Gigs for /usr if you are going to have X installed with source, but I personally feel this would be a little bit limiting. 5-10 gigs seems more reasonable if you have the room.
The /usr/src/ directory
This contains the source code for the operating system, this is needed if you want to do a source update of the operating system via cvsup at some point. This really doesn't need its own partition, leaving it in /usr is fine.
The /usr/ports directory
By default /usr/ports contains the ports collection. /usr/ports/distfiles, which contains the packaged ports downloads, can grow quite large on a system that has many ports installed. On the other hand, you can keep it under control manually by deleting things periodically. Most ports do some of their compilation and install work in their own directories, however, and this will require a bit of stretching room. You might consider symlinking this to a larger partition if you decide to keep a small, essentials-only /usr to speed reboots-with-fsck after system crashes.
The /usr/local directory
This contains most of the files related to installed ports, in addition to your personal configurations in /usr/local/etc. This will need to be roughly sized with whatever you are installing. It will be very large for an X system, but fairly small for a simple ftp server.
The /home or /data partition
Assuming this is not a firewall or similarly specialized machine. Users (even if it is only yourself) will likely log in and want to use files. This partition, not created by the default install, is often given most of the disk. This is particularly true for personal servers and personal machines, which are likely to keep most of their files in this partition.
The default partitioning scheme follows the idea of creating a link from /home to /usr/home, and giving /usr most of the disk. The problem with this is that /usr is needed to bring a system up, and in a situation where you may have as much as 250gigs (or more) of space under /usr, it will take quite awhile to file system check before you can bring the system up to check it. Which is particularly bad if you're having consistent crashes. One way to deal with this is to give /usr and /home their own partitions -- if /home has its own slice, it will not be made a link to /usr/home during the install.
See also Partitioning Tips and Tricks.