/etc/fstab
fstab is a conf file that describes filesystems. It specifies what filesystems are present and how they should be mounted at bootup time.
If you have recently edited any disk partitions, you likely want the system to automatically mount its partitions on bootup. If so, you'll want to update fstab.
At any time, we can check which disks we have in dmesg or /var/run/dmesg.boot:
$ dmesg | grep -E '(sd|wd)[0-9]' sd0 at scsibus1 targ 0 lun 0: <VirtIO, Block Device, > sd0: 20480MB, 512 bytes/sector, 41943040 sectors sd1 at scsibus2 targ 0 lun 0: <VirtIO, Block Device, > sd1: 256000MB, 512 bytes/sector, 524288000 sectors
In this case, we see there are two disks, sd0 with 20GB of storage, and sd1 with 256GB of storage.
disklabel creates a disklabel unique identifier (DUID) for each disk. To find the DUID of disk sd0:
$ doas disklabel sd0 | grep duid duid: fd7ecb3de7e46e12
We see disk sd0 has a DUID of fd7ecb3de7e46e12
.
/etc/fstab uses DUIDs instead of relative device names because device ordering may change over time.
# cat /etc/fstab fd7ecb3de7e46e12.b none swap sw fd7ecb3de7e46e12.a / ffs rw 1 1 fd7ecb3de7e46e12.k /home ffs rw,nodev,nosuid 1 2 fd7ecb3de7e46e12.d /tmp ffs rw,nodev,nosuid 1 2 fd7ecb3de7e46e12.f /usr ffs rw,nodev 1 2 fd7ecb3de7e46e12.g /usr/X11R6 ffs rw,nodev 1 2 fd7ecb3de7e46e12.h /usr/local ffs rw,wxallowed,nodev 1 2 fd7ecb3de7e46e12.j /usr/obj ffs rw,nodev,nosuid 1 2 fd7ecb3de7e46e12.i /usr/src ffs rw,nodev,nosuid 1 2 fd7ecb3de7e46e12.e /var ffs rw,nodev,nosuid 1 2
Take a look at the /home partition for example:
fd7ecb3de7e46e12.k /home ffs rw,nodev,nosuid 1 2
This could be rewritten with relative device names:
/dev/sd0k /home ffs rw,nodev,nosuid 1 2
This would mount partition k
on the first
sd (SCSI disk) disk to be /home
. The
drawback to using relative device names, however, is that disk ordering
can sometimes change. If you swap hard disks, then OpenBSD may mount
the wrong partition on the wrong disk. If it cannot mount the
partition, the system will refuse to complete bootup. For this reason,
using DUIDs is recommended.
Here's an analysis of some interesting lines in the fstab:
fd7ecb3de7e46e12.b none swap sw
none
indicates that partition b has no mount point. The filesystem
type is indicated as swap
and the sw
option is set to indicate
this partition will be used as swap space.
The operating system uses this swap partition? when all real memory has been exhausted. A swap partition at least as large as real memory is also needed for core dumps. Running out of swap space can cause your system to freeze or panic unexpectedly. You may consider adding a new swap partition? or swap file to increase swap space.
fd7ecb3de7e46e12.a / ffs rw 1 1
The root partition is ffs
or Fast Filesystem. It is mounted rw
for read-write, you could also mount partitions ro
, for read-only mode,
The next two numbers, 1 1
are used by dump and fsck?.
The first number tells dump how many days will pass before a dump is considered old.
A value of 0
tells dump(8) the filesystem
doesn't need to be backed up. The next number tells fsck the order in
which filesystem checks should be performed at reboot. Root should be
1
, and all others 2
. Filesystems with 0
will not be
checked.
fd7ecb3de7e46e12.k /home ffs rw,nodev,nosuid 1 2
The mount options nodev
indicates there will be no devices on the filesystem. nosuid
tells that the partition that set-user-identifier (setuid) or set-group-identifier can be ignored.
fd7ecb3de7e46e12.h /usr/local ffs rw,wxallowed,nodev 1 2
Normally, a process that wants memory both writeable and executable are
killed by OpenBSD
(W^X).
Setting the mount option wxallowed
allows processes to both write
and execute processes. This is often used for the /usr/local/
filesystem.
If you have created a new partition, find its DUID and create a new line for it in /etc/fstab.
To mount all partitions in /etc/fstab:
# mount -a