OpenBSD: Difference between revisions

From Leo's Notes
This page was last edited on 27 April 2022, at 03:54.
No edit summary
No edit summary
Line 45: Line 45:
|}
|}


== Tasks ==
== Storage ==
 
=== Disk partitions ===
Disk partitions are treated slightly differently on OpenBSD (or any other BSDs for that matter) compared to Linux. Recall that MBR disks can have only up to 4 primary partitions and any additional partitions can only be made as extended partitions. In OpenBSD, partitions are generally created as subdivisions of one of the primary partitions using something called a BSD disklabel.


===System update===
The term 'partition' and 'slice' comes up when dealing with storage in BSD. To be clear, they refer to the following:
To update a OpenBSD system, run:
{{Highlight
| code = # syspatch
# pkg_add -Uu
# sysmerge -d
| lang = terminal
}}


=== Finding all available disks ===
* A partition refers to the primary MBR partitions
There is no utility that does this similar to <code>lsblk</code>. Rather, you can find all disks using <code>sysctl | grep disk</code>.
* A slice refers to the subdivisions of a primary MBR
{{Highlight
| code = # sysctl -a {{!}} grep -i disk
hw.disknames=wd0:94a4943e88c9a60f,wd1:,cd0:,fd0:
hw.diskcount=4
machdep.bios.diskinfo.128=bootdev = 0xa0000200, cylinders = 1023, heads = 255, sectors = 63
machdep.bios.diskinfo.129=bootdev = 0xa0010200, cylinders = 1023, heads = 255, sectors = 63
| lang = terminal
}}
Disks are named either <code>wd*</code> (IDE, SATA, flash devices) or <code>sd*</code> (SCSI devices, USB drives via the ahci interface, or disks via a RAID controller).


=== Partitioning and formatting disks ===
In OpenBSD, we create a primary partition of type <code>0xA6</code> (the ID for the OpenBSD disklabel) and then partition this primary partition out using the <code>disklabel</code> utility into individual partitions that are visible on the system. Partitions in OpenBSD are named with letters (such as wd0a, wd0b) rather than with numbers (sda1, sda2) as on Linux. Up to 15 partitions can be created. For the disk containing the operating system, the first partition (a) must be the root partition from which the system is bootstrapped from and the second partition (b) should be used for swap. The third partition (c) overlaps the entire disk
Disk partitioning can be done using OpenBSD's version of <code>fdisk</code>. fdisk supports both MBR and GPT disks. For MBR based disks, fdisk will allow you to create a primary partition in each of the available 4 slots (as shown below). Each primary MBR partition that's set to the OpenBSD MBR partition type (0xA6) will have its own 16 entry partition table which can be edited with <code>disklabel</code>. These 'disk labels' outline the start and end of the underlying primary partition which can then be formatted with a filesystem.


For more info, refer to [https://www.openbsd.org/faq/faq14.html? OpenBSD's FAQ].
==== Creating disk partitions and disk labels ====
Primary partitions can be created using OpenBSD's version of <code>fdisk</code>. <code>fdisk</code> supports both MBR and GPT disks, but the example below is for a MBR disk. Running <code>fdisk</code> on a MBR disk will list all four primary partitions as shown below. To be able to use BSD disk labels, you will have to create a primary partition using OpenBSD's disk label type (<code>0xA6</code>). For more info, refer to [https://www.openbsd.org/faq/faq14.html? OpenBSD's FAQ].


A blank MBR disk looks like the following:
A blank MBR disk looks like the following:
Line 87: Line 74:
| lang = terminal
| lang = terminal
}}
}}
To create a new primary partition, edit one of the entries and specify a start and end size. Create a new partition of type 0xA6 which is a OpenBSD partition which allows you to further partition out the disk with disklabel. The start and end values can be specified in other units such as 1G for 1 gigabyte.  
To create a new primary partition, edit one of the entries using the <code>edit</code> command and specify a start and end size. Specify the type as 0xA6. The start and end values can be specified in other units such as 1G for 1 gigabyte. You will typically want to make this partition span the entire disk and then partition it out further with a disk label.  


Each disk can only have one primary OpenBSD partition. If you specify more than one, you'll get a warning from fdisk when you try to write. If you do continue, the first OpenBSD partition will be used by disklabel.
Each disk can only have one primary partition of the OpenBSD partition type. If you specify more than one, you'll get a warning from fdisk when you try to write. If you do continue, the first OpenBSD partition will be used by disklabel.
{{Highlight
{{Highlight
| code = ## Create a new primary partition
| code = ## Create a new primary partition
Line 114: Line 101:
| lang = terminal
| lang = terminal
}}
}}
With a partition created, you can then partition out the space with <code>disklabel</code>. Note that the 'c' partition always exists and covers the entire disk. You can create up to 15 other partitions as you see fit as <code>a, b, d, ..., p</code>. Just be aware that you need to make sure the partition ranges do not overlap (because it lets you).
With the OpenBSD partition created, you can then partition out the space with the <code>disklabel</code> utility. Recall that the first partition (a) must be the root partition from which the system is bootstrapped from and the second partition (b) should be used for swap. The third partition (c) always exists and should overlap the entire disk. Leave the 'c' partition alone. Take special care that your partitions do not overlap with each other because nothing will stop you from doing so.
{{Highlight
{{Highlight
| code = ## Create a new secondary partition
| code = ## Create a new secondary partition
Line 141: Line 128:
| lang = terminal
| lang = terminal
}}
}}
== Tasks ==
===System update===
To update a OpenBSD system, run:
{{Highlight
| code = # syspatch
# pkg_add -Uu
# sysmerge -d
| lang = terminal
}}
=== Finding all available disks ===
There is no utility that does this similar to <code>lsblk</code>. Rather, you can find all disks using <code>sysctl | grep disk</code>.
{{Highlight
| code = # sysctl -a {{!}} grep -i disk
hw.disknames=wd0:94a4943e88c9a60f,wd1:,cd0:,fd0:
hw.diskcount=4
machdep.bios.diskinfo.128=bootdev = 0xa0000200, cylinders = 1023, heads = 255, sectors = 63
machdep.bios.diskinfo.129=bootdev = 0xa0010200, cylinders = 1023, heads = 255, sectors = 63
| lang = terminal
}}
Disks are named either <code>wd*</code> (IDE, SATA, flash devices) or <code>sd*</code> (SCSI devices, USB drives via the ahci interface, or disks via a RAID controller).


=== Disabling library ASLR ===
=== Disabling library ASLR ===
<code>rcctl disable library_aslr</code>
<code>rcctl disable library_aslr</code>


== Questions ==
=== Boot into system rescue ===
Enter the boot shell and run: <code>boot bsd.rd</code>. When given a prompt, select <code>(S)hell</code>.


# Why is the 'c' disk label always the entire disk and left unused?
=== Integrating with FreeIPA ===
#
There is no sssd available. You might need to set up OpenLDAP and Kerberos authentication manually...

Revision as of 03:54, 27 April 2022

OpenBSD is a UNIX-like operating system.


Package management

https://cdn.openbsd.org/pub/OpenBSD

  1. export PKG_PATH=scp://user@company-build-server/usr/ports/packages/%a/all:https://trusted-public-server/%m:installpath

The common programs that you'll use to manage packages are:

Command Description
pkg_add installing and upgrading packages
pkg_check checking the consistency of installed packages
pkg_delete removing installed packages
pkg_info display and search for information about packages

Common package tasks:

Task Command Example
Search for a package pkg_info -Q <search> pkg_info -Q unzip
Find out what package provides a specific file. Eg. like yum whatprovides pkglocate <file/path> pkglocate vim
Install a new package pkg_add <package> pkg_add vim
Update a package and its dependencies pkg_add -u <package> pkg_add -u vim

Storage

Disk partitions

Disk partitions are treated slightly differently on OpenBSD (or any other BSDs for that matter) compared to Linux. Recall that MBR disks can have only up to 4 primary partitions and any additional partitions can only be made as extended partitions. In OpenBSD, partitions are generally created as subdivisions of one of the primary partitions using something called a BSD disklabel.

The term 'partition' and 'slice' comes up when dealing with storage in BSD. To be clear, they refer to the following:

  • A partition refers to the primary MBR partitions
  • A slice refers to the subdivisions of a primary MBR

In OpenBSD, we create a primary partition of type 0xA6 (the ID for the OpenBSD disklabel) and then partition this primary partition out using the disklabel utility into individual partitions that are visible on the system. Partitions in OpenBSD are named with letters (such as wd0a, wd0b) rather than with numbers (sda1, sda2) as on Linux. Up to 15 partitions can be created. For the disk containing the operating system, the first partition (a) must be the root partition from which the system is bootstrapped from and the second partition (b) should be used for swap. The third partition (c) overlaps the entire disk

Creating disk partitions and disk labels

Primary partitions can be created using OpenBSD's version of fdisk. fdisk supports both MBR and GPT disks, but the example below is for a MBR disk. Running fdisk on a MBR disk will list all four primary partitions as shown below. To be able to use BSD disk labels, you will have to create a primary partition using OpenBSD's disk label type (0xA6). For more info, refer to OpenBSD's FAQ.

A blank MBR disk looks like the following:

# fdisk wd1
Disk: wd1       geometry: 1305/255/63 [20971520 Sectors]
Offset: 0       Signature: 0x0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 3: 00      0   0   0 -      0   0   0 [           0:           0 ] unused

To create a new primary partition, edit one of the entries using the edit command and specify a start and end size. Specify the type as 0xA6. The start and end values can be specified in other units such as 1G for 1 gigabyte. You will typically want to make this partition span the entire disk and then partition it out further with a disk label.

Each disk can only have one primary partition of the OpenBSD partition type. If you specify more than one, you'll get a warning from fdisk when you try to write. If you do continue, the first OpenBSD partition will be used by disklabel.

## Create a new primary partition
# fdisk -e wd1
wd1*: 1> edit 3
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 3: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
Partition id ('0' to disable) [01 - FF]: [00] (? for help) A6
Do you wish to edit in CHS mode? [n]
Partition offset [0 - 20971519]: [0]
Partition size [1 - 20971520]: [1] 1G
wd1*: 1> print
Disk: wd1       geometry: 1305/255/63 [20971520 Sectors]
Offset: 0       Signature: 0x0
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 3: A6      0   0   1 -    130 138   8 [           0:     2097152 ] OpenBSD

With the OpenBSD partition created, you can then partition out the space with the disklabel utility. Recall that the first partition (a) must be the root partition from which the system is bootstrapped from and the second partition (b) should be used for swap. The third partition (c) always exists and should overlap the entire disk. Leave the 'c' partition alone. Take special care that your partitions do not overlap with each other because nothing will stop you from doing so.

## Create a new secondary partition
# disklabel -e wd1

## In the editor, add a new entry after 'c:'
16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  c:         20971520                0  unused
  d:           102400                0  4.2BSD   2048 16384 12960

With wd1d defined now, we can then go ahead and create a new filesystem on wd1d using newfs.

# newfs wd1d
/dev/rwd1d: 50.0MB in 102400 sectors of 512 bytes
4 cylinder groups of 12.50MB, 800 blocks, 1600 inodes each
super-block backups (for fsck -b #) at:
 160, 25760, 51360, 76960,

We can then mount.

# mount /dev/wd1d /mnt
# mount
/dev/wd1d on /mnt type ffs (local)

Tasks

System update

To update a OpenBSD system, run:

# syspatch
# pkg_add -Uu
# sysmerge -d

Finding all available disks

There is no utility that does this similar to lsblk. Rather, you can find all disks using sysctl | grep disk.

# sysctl -a | grep -i disk
hw.disknames=wd0:94a4943e88c9a60f,wd1:,cd0:,fd0:
hw.diskcount=4
machdep.bios.diskinfo.128=bootdev = 0xa0000200, cylinders = 1023, heads = 255, sectors = 63
machdep.bios.diskinfo.129=bootdev = 0xa0010200, cylinders = 1023, heads = 255, sectors = 63

Disks are named either wd* (IDE, SATA, flash devices) or sd* (SCSI devices, USB drives via the ahci interface, or disks via a RAID controller).

Disabling library ASLR

rcctl disable library_aslr

Boot into system rescue

Enter the boot shell and run: boot bsd.rd. When given a prompt, select (S)hell.

Integrating with FreeIPA

There is no sssd available. You might need to set up OpenLDAP and Kerberos authentication manually...