OpenBSD

From Leo's Notes
Revision as of 00:28, 27 April 2022 by Leo (talk | contribs)
This page was last edited on 27 April 2022, at 00:28.

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

Tasks

System update

To update a OpenBSD system, run:

# syspatch
# pkg_add -Uu
# sysmerge -d

Finding all available disks

There is no 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).

Partitioning and formatting disks

Disk partitioning can be done using OpenBSD's version of fdisk. 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 disklabel. 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 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 and specify a start and end size. You can enter '1G' to specify 1GB. Set the type to 0xA6 so that you can use disklabel to partition out the space out further.

## 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 a partition created, you can then partition out the space with disklabel.

## 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

Then, create a new filesystem on wd1d

# 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,

Disabling library ASLR

rcctl disable library_aslr