Partitioning Disks

After selecting the disk you want to install, you will be presented with how you want to layout the disklabel partitions on the disk.

By default, disklabel suggests an automatic layout that is usually sensible and works for most cases. However, it often makes sense to edit the default layout.

If you want to edit the disklabel partitions, make sure you read about OpenBSD's filesystem hierarchy. In this guide, we will provide a sample layout that makes sense for a typical server.

NOTICE: Your needs will likely be different. Do NOT blindly copy and paste commands. Take the time to read about OpenBSD's filesystem hierarchy and make adjustments accordingly.

The auto-allocated layout for sd0 is:
#                size           offset  fstype [fsize bsize   cpg]
  a:           624.9M               64  4.2BSD   2048 16384     1 # /
  b:          1029.8M          1279840    swap                    
  c:         20480.0M                0  unused                    
  d:           879.8M          3388864  4.2BSD   2048 16384     1 # /tmp
  e:          1314.7M          5190752  4.2BSD   2048 16384     1 # /var
  f:          2449.8M          7883296  4.2BSD   2048 16384     1 # /usr
  g:           668.9M         12900448  4.2BSD   2048 16384     1 # /usr/X11R6
  h:          2448.7M         14270432  4.2BSD   2048 16384     1 # /usr/local
  i:          1690.0M         19285344  4.2BSD   2048 16384     1 # /usr/src
  j:          5499.9M         22746368  4.2BSD   2048 16384     1 # /usr/obj
  k:          3873.5M         34010176  4.2BSD   2048 16384     1 # /home

If you want to (E)dit the layout, type E:

Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout? [a] E

If you want to print all partitions, type p:

sd0> p  
OpenBSD area: 64-41943040; size: 41942976; free: 4
#                size           offset  fstype [fsize bsize   cpg]
  a:          1279776               64  4.2BSD   2048 16384     1 # /
  b:          2109020          1279840    swap                    
  c:         41943040                0  unused                    
  d:          1801888          3388864  4.2BSD   2048 16384     1 # /tmp
  e:          2692544          5190752  4.2BSD   2048 16384     1 # /var
  f:          5017152          7883296  4.2BSD   2048 16384     1 # /usr
  g:          1369984         12900448  4.2BSD   2048 16384     1 # /usr/X11R6
  h:          5014912         14270432  4.2BSD   2048 16384     1 # /usr/local
  i:          3461024         19285344  4.2BSD   2048 16384     1 # /usr/src
  j:         11263808         22746368  4.2BSD   2048 16384     1 # /usr/obj
  k:          7932864         34010176  4.2BSD   2048 16384     1 # /home

The first column at the very left shows the partition names for each of the partitions. Each partition is a letter. By convention, partition b is used for swap space?, and partition c is not an actual partition but represents the entire disk.

Notice that by default, sizes are listed in sectors. You can type p followed by g to print out partition sizes in gigabytes:

sd0> p g
OpenBSD area: 64-41943040; size: 20.0G; free: 0.0G
#                size           offset  fstype [fsize bsize   cpg]
  a:             0.6G               64  4.2BSD   2048 16384     1 # /
  b:             1.0G          1279840    swap                    
  c:            20.0G                0  unused                    
  d:             0.9G          3388864  4.2BSD   2048 16384     1 # /tmp
  e:             1.3G          5190752  4.2BSD   2048 16384     1 # /var
  f:             2.4G          7883296  4.2BSD   2048 16384     1 # /usr
  g:             0.7G         12900448  4.2BSD   2048 16384     1 # /usr/X11R6
  h:             2.4G         14270432  4.2BSD   2048 16384     1 # /usr/local
  i:             1.7G         19285344  4.2BSD   2048 16384     1 # /usr/src
  j:             5.4G         22746368  4.2BSD   2048 16384     1 # /usr/obj
  k:             3.8G         34010176  4.2BSD   2048 16384     1 # /home

At any time, we can type h to print out the help message, and M to display the disklabel(8) man page:

sd0> h
Available commands:
 ? | h    - show help                 n [part] - set mount point
 A        - auto partition all space  p [unit] - print partitions
 a [part] - add partition             q        - quit & save changes
 b        - set OpenBSD boundaries    R [part] - resize auto allocated partition
 c [part] - change partition size     r        - display free space
 D        - reset label to default    s [path] - save label to file
 d [part] - delete partition          U        - undo all changes
 e        - edit label description    u        - undo last change
 i        - modify disklabel UID      w        - write label to disk
 l [unit] - print disk label header   x        - exit & lose changes
 M        - disklabel(8) man page     z        - delete all partitions
 m [part] - modify partition

Suffixes can be used to indicate units other than sectors:
 'b' (bytes), 'k' (kilobytes), 'm' (megabytes), 'g' (gigabytes) 't' (terabytes)
 'c' (cylinders), '%' (% of total disk), '&' (% of free space).
Values in non-sector units are truncated to the nearest cylinder boundary.

The two partitions /usr/src and /usr/obj are used to build OpenBSD from source code. Most users will not need these two partitions, so we will delete them to recover about 7GB of disk space. d followed by the partition letter will delete that partition:

sd0> d i
sd0*> d j
sd0*> p g
OpenBSD area: 64-41943040; size: 20.0G; free: 7.0G
#                size           offset  fstype [fsize bsize   cpg]
  a:             0.6G               64  4.2BSD   2048 16384     1 # /
  b:             1.0G          1279840    swap                    
  c:            20.0G                0  unused                    
  d:             0.9G          3388864  4.2BSD   2048 16384     1 # /tmp
  e:             1.3G          5190752  4.2BSD   2048 16384     1 # /var
  f:             2.4G          7883296  4.2BSD   2048 16384     1 # /usr
  g:             0.7G         12900448  4.2BSD   2048 16384     1 # /usr/X11R6
  h:             2.4G         14270432  4.2BSD   2048 16384     1 # /usr/local
  k:             3.8G         34010176  4.2BSD   2048 16384     1 # /home

Notice the prompts change from sd0 to sd0*, indicating that there are now unsaved changes that need to be written to disk. If you decide you don't want to save any changes, you can type x to exit and lose all changes:

sd0*> x
Label editor (enter '?' for help at any prompt)

Now type p and you'll notice all partitions were deleted:

sd0> p
OpenBSD area: 64-41943040; size: 41942976; free: 41942976
#                size           offset  fstype [fsize bsize   cpg]
  c:         41943040                0  unused                    

If you type x again, you'll exit disklabel.

We don't want to exit, but instead we want to auto partition all space, so type A:

sd0> A
sd0*> p
OpenBSD area: 64-41943040; size: 41942976; free: 4
#                size           offset  fstype [fsize bsize   cpg]
  a:          1279776               64  4.2BSD   2048 16384     1 # /
  b:          2109020          1279840    swap                    
  c:         41943040                0  unused                    
  d:          1801888          3388864  4.2BSD   2048 16384     1 # /tmp
  e:          2692544          5190752  4.2BSD   2048 16384     1 # /var
  f:          5017152          7883296  4.2BSD   2048 16384     1 # /usr
  g:          1369984         12900448  4.2BSD   2048 16384     1 # /usr/X11R6
  h:          5014912         14270432  4.2BSD   2048 16384     1 # /usr/local
  i:          3461024         19285344  4.2BSD   2048 16384     1 # /usr/src
  j:         11263808         22746368  4.2BSD   2048 16384     1 # /usr/obj
  k:          7932864         34010176  4.2BSD   2048 16384     1 # /home

We will again delete partitions i and j, /usr/src and /usr/obj, respectively:

sd0*> d i
sd0*> d j

If you plan to install large software packages, /usr/local should be enlarged. I find 5GB to be a comfortable size for a server. Typing R followed by a letter will resize that disklabel partition if the partition automatically allocated.

NOTE: R will NOT work if the partition is NOT automatically allocated.

sd0*> R h
[+|-]new size (with unit): [5014912] 5G
sd0*> p g
OpenBSD area: 64-41943040; size: 20.0G; free: 4.4G
#                size           offset  fstype [fsize bsize   cpg]
  a:             0.6G               64  4.2BSD   2048 16384     1 # /
  b:             1.0G          1279840    swap                    
  c:            20.0G                0  unused                    
  d:             0.9G          3388864  4.2BSD   2048 16384     1 # /tmp
  e:             1.3G          5190752  4.2BSD   2048 16384     1 # /var
  f:             2.4G          7883296  4.2BSD   2048 16384     1 # /usr
  g:             0.7G         12900448  4.2BSD   2048 16384     1 # /usr/X11R6
  h:             5.0G         14270432  4.2BSD   2048 16384     1 # /usr/local
  k:             3.8G         24756192  4.2BSD   2048 16384     1 # /home

The benefit of using R is that it will compact any unused space automatically for you.

We still have 4.4G of free space left. /var is used for hosting email and webpages, and since this install will be used for a server, I will allocate all remaining space to /var:

sd0*> R e
[+|-]new size (with unit): [2692544] +4.4G
sd0*> p g                                                                                
OpenBSD area: 64-41943040; size: 20.0G; free: 0.0G                            
#                size           offset  fstype [fsize bsize   cpg]       
  a:             0.6G               64  4.2BSD   2048 16384     1 # /
  b:             1.0G          1279840    swap                    
  c:            20.0G                0  unused                    
  d:             0.9G          3388864  4.2BSD   2048 16384     1 # /tmp
  e:             5.7G          5190752  4.2BSD   2048 16384     1 # /var
  f:             2.4G         17110752  4.2BSD   2048 16384     1 # /usr
  g:             0.7G         22127904  4.2BSD   2048 16384     1 # /usr/X11R6
  h:             5.0G         23497888  4.2BSD   2048 16384     1 # /usr/local
  k:             3.8G         33983648  4.2BSD   2048 16384     1 # /home

To write our changes to the disklabel, we type w. To save and exit, we type q.

sd0*> w
sd0> q

If disklabel was started as part of the installer, it will automatically run newfs to construct the new filesystem. Otherwise, you will need to run it manually.