Advanced Operations

Recovering Partitions After Deleting the Disk Label #

If you have a damaged partition table, there are various things you can attempt to do to recover it. A copy of the disklabel for each disk is saved in /var/backups as part of the daily system maintenance. Assuming you still have the /var partition, you can simply read the output, and put it back into disklabel with the -R flag.

In the event that you can no longer see that partition, there are two options: Fix enough of the disk so you can see it, or fix enough of the disk so that you can get your data off. The scan_ffs(8) utility will look through a disk to find partitions. You can use the information it finds to recreate the disklabel. If you just want /var back, you can recreate the partition for /var, then recover the backed up label and add the rest from that. The disklabel(8) utility will both update the kernel’s understanding of the disklabel and attempt to write the label to disk. Therefore, even if the area of the disk containing the disklabel is unreadable, you will be able to mount until the next reboot.

Soft Updates #

Soft updates are based on an idea proposed by Greg Ganger and Yale Patt and developed for FreeBSD by Kirk McKusick. Soft updates imposes a partial ordering on the buffer cache operations which permits the requirement for synchronous writing of directory entries to be removed from the FFS code. A large disk writing performance increase is seen as a result.

Enabling soft updates must be done with a mount-time option. When mounting a partition with the mount(8) utility, you can specify that you wish to have soft updates enabled on that partition. Below is a sample fstab(5) entry that has one partition sd0a that we wish to have mounted with soft updates.

/dev/sd0a / ffs rw,softdep 1 1

Root Partition Backup (/altroot) #

OpenBSD provides an /altroot facility in the daily(8) scripts. If the environment variable ROOTBACKUP=1 is set in either /etc/daily.local or root’s crontab(5), and a partition is specified in fstab(5) as mounting to /altroot with the mount options of xx, every night the entire contents of the root partition will be duplicated to the /altroot partition. Assuming you want to back up your root partition to the partition specified by the DUID bfb4775bb8397569.a, add the following to /etc/fstab

bfb4775bb8397569.a /altroot ffs xx 0 0

and set the appropriate environment variable in /etc/daily.local:

# echo ROOTBACKUP=1 >>/etc/daily.local

As the /altroot process will capture your /etc directory, this will make sure any configuration changes there are updated daily. This is a “disk image” copy done with dd(1) not a file-by-file copy, so your /altroot partition should be at least the same size as your root partition. Generally, you will want your /altroot partition to be on a different disk that has been configured to be fully bootable should the primary disk fail.

Duplicating Filesystems #

To duplicate everything under directory /SRC to directory /DST with dump(8) and restore(8), do:

# cd /SRC && dump 0f - . | (cd /DST && restore -rf - )

or use tar(1):

# cd /SRC && tar cf - . | (cd /DST && tar xpf - )

Disk Quotas #

Quotas are used to place limits on the amount of disk space available to certain users and groups.

Use the keywords userquota and groupquota to mark each filesystem in fstab(5) on which you want to enforce quotas. By default, the files quota.user and quota.group will be created at the root of those filesystems. Here is an example /etc/fstab line:

0123456789abcdef.k /home ffs rw,nodev,nosuid,userquota 1 2

To set the users’ quotas, use edquota(8). For example, issue

# edquota ericj

and edit the soft and hard limits:

Quotas for user ericj:
/home: KBytes in use: 62, limits (soft = 1000000, hard = 1500000)
        inodes in use: 25, limits (soft = 0, hard = 0)

In this example, the soft limit is set to 1000000k, and the hard limit is set to 1500000k. No limits on the number of inodes will be enforced, since the corresponding soft and hard limits are set to 0. Users who exceed their soft limit are warned and are given a grace period to get their disk usage below their limits. Grace periods can be set by using the -t option on edquota(8). After the grace period is over, the soft limit is handled as a hard limit. This usually results in an allocation failure.

Use quotaon(8) to enable quotas:

# quotaon -a

This will scan through fstab(5) and enable quotas on the filesystems with quota options. View quota statistics with quota(1).

Accessing Other Filesystems #

Start with the mount(8) manual, which contains examples explaining how to mount some of the most commonly used filesystems. A partial list of supported filesystems and related commands can be obtained with:

$ man -k -s 8 mount

Note that support may be limited to read-only operation.

Mounting Disk Images #

To mount a disk image in OpenBSD you must configure a vnd(4) device. For example, if you have an ISO image located at /tmp/ISO.image, you would take the following steps to mount the image.

# vnconfig vnd0 /tmp/ISO.image
# mount -t cd9660 /dev/vnd0c /mnt

Since this is an ISO 9660 image, as used by CDs and DVDs, you must specify type of cd9660 when mounting it. To unmount the image and unconfigure the vnd(4) device, do:

# umount /mnt
# vnconfig -u vnd0

For more information, refer to vnconfig(8) and mount(8).

Growing Disk Partitions #

If an existing partition is followed by unallocated free space, you may increase its size using the growfs(8) utility. Make sure the partition is not currently mounted. Edit your partition table interactively with disklabel -E sd0 and modify the size of the partition using the m command. Adjust the filesystem to use the entire partition with growfs(8):

# growfs sd0h

Before the partition can be mounted again, its integrity must be checked with fsck(8):

# fsck /dev/sd0h