OpenBSD: Difference between revisions

From Leo's Notes
This page was last edited on 27 April 2022, at 00:43.
No edit summary
No edit summary
Line 57: Line 57:


=== Finding all available disks ===
=== Finding all available disks ===
There is no lsblk. Rather, you can find all disks using <code>sysctl | grep disk</code>.
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
{{Highlight
| code = # sysctl -a {{!}} grep -i disk
| code = # sysctl -a {{!}} grep -i disk
Line 87: Line 87:
| lang = terminal
| lang = terminal
}}
}}
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 <code>0xA6</code> so that you can use <code>disklabel</code> to partition out the space out further.
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.
 
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.
{{Highlight
{{Highlight
| code = ## Create a new primary partition
| code = ## Create a new primary partition
Line 112: Line 114:
| lang = terminal
| lang = terminal
}}
}}
With a partition created, you can then partition out the space with <code>disklabel</code>.
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).
{{Highlight
{{Highlight
| code = ## Create a new secondary partition
| code = ## Create a new secondary partition
Line 124: Line 126:
| lang = terminal
| lang = terminal
}}
}}
Then, create a new filesystem on <code>wd1d</code>
With wd1d defined now, we can then go ahead and create a new filesystem on <code>wd1d</code> using <code>newfs</code>.
{{Highlight
{{Highlight
| code = # newfs wd1d
| code = # newfs wd1d
Line 131: Line 133:
super-block backups (for fsck -b #) at:
super-block backups (for fsck -b #) at:
  160, 25760, 51360, 76960,
  160, 25760, 51360, 76960,
| lang = terminal
}}We can then mount.
{{Highlight
| code = # mount /dev/wd1d /mnt
# mount
/dev/wd1d on /mnt type ffs (local)
| lang = terminal
| lang = terminal
}}
}}
Line 136: Line 144:
=== Disabling library ASLR ===
=== Disabling library ASLR ===
<code>rcctl disable library_aslr</code>
<code>rcctl disable library_aslr</code>
== Questions ==
# Why is the 'c' disk label always the entire disk and left unused?
#

Revision as of 00:43, 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

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).

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

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.

## 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. 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 a, b, d, ..., p. Just be aware that you need to make sure the partition ranges do not overlap (because it lets you).

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

Disabling library ASLR

rcctl disable library_aslr

Questions

  1. Why is the 'c' disk label always the entire disk and left unused?