9

How do I list all connected (including unmounted) devices on OpenBSD?

I'm looking for something similar to lsblk for Linux or camcontrol devlist for FreeBSD:

# List devices on FreeBSD

$ camcontrol devlist
<VBOX HARDDISK 1.0>   at scbus0 target 0 lun 0 (ada0,pass0)
<VBOX CD-ROM 1.0>     at scbus1 target 0 lun 0 (pass1,cd0)

# List devices on Linux
$ lsblk

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
/dev/sda      8:0    0 465.8G  0 disk 
├─/dev/sda1   8:1    0  1007K  0 part 
├─/dev/sda2   8:2    0   256M  0 part /boot
├─/dev/sda3   8:3    0   9.8G  0 part [SWAP]
├─/dev/sda4   8:4    0  29.3G  0 part /
├─/dev/sda5   8:5    0  29.3G  0 part /var
├─/dev/sda6   8:6    0 297.6G  0 part /home
└─/dev/sda9   8:9    0  16.3G  0 part 
/dev/sr0     11:0    1  1024M  0 rom  

None of these commands seem to exist or be available in the (default) repos for OpenBSD.
Not even pciinfo, kldstat, or geom are available.

6 Answers 6

8

The sysctl command can list devices attached to the system. sysctl gets or sets kernel state.

To list how many disks you have:

sysctl hw.diskcount

To list disk names:

sysctl hw.disknames

Or sysctl -a | grep -i disk

7
  • While this does show what devices should be available, it doesn't however tell me the /dev interface for said devices. For example, it lists cd0, however mount /dev/cd0 /mnt/cd0 fails complaining that either /dev/cd0 or /mnt/cd0 don't exist. Nov 22, 2017 at 1:35
  • did you create a /mnt/cd0 directory? In a default OpenBSD install the /mnt/ directory has no subdirectories. So I have created a /mnt/cd directory and added the following entry /dev/cd0a /mnt/cd cd9660 rw,noauto,nodev,nosuid 0 0 to the /etc/fstab file, now to mount a cd I only have to do mount /mnt/cd hth
    – fcbsd
    Nov 22, 2017 at 11:27
  • Yeah /mnt/cd0 existed: I'm guessing that cd0 doesn't actually point to a device and that I'd need to mount one of the cd0<LETTER> devices? Nov 22, 2017 at 15:04
  • 1
    @AlexejMagura - I think that cd0a and cd0c should both be there be default as well as the raw devices rcd0a and rcd0c the letter after the node number is usually the partition - the c parition is always the whole disk - and as CD's are usually a single disk you tend to have an a partition that usually matches the whole disk on CD's as well so either would normally be okay for CD's.
    – fcbsd
    Nov 22, 2017 at 15:23
  • 2
    disklabel(8) explains the 15 configurable partitions that any disk can have.
    – fcbsd
    Nov 22, 2017 at 15:27
5
dmesg | egrep '^(cd|wd|sd|fd). at '
3
  • I was wondering if you could shorten it even more - I managed dmesg|egrep '^([cswf]d). '
    – fcbsd
    Nov 21, 2017 at 22:24
  • dmesg shows ALL devices that have been attached, so if you plug in a flash drive, remove it, this command will show it as present. That's why dmesg is a really bad data source, it's static data, not dynamic, that is, it's a history of all events until the present.
    – Lizardx
    Mar 27, 2021 at 23:39
  • What's nice about this option is that your ISP storage names or IDs may be listed here, making it a lot easier to figure out which device is which storage.
    – Paul
    May 27, 2022 at 22:15
3

lsblk is a nice tool but not available on OpenBSD. There are other ways of achieving similar:

1. To show the names of disks available on the system:

sysctl hw.disknames

This produces a list of disks on one line, separated by commas:

hw.disknames=sd0:1e212bdb8b279f47,sd1:33634e7b41dbbafb,sd3:569e3efaf6b08310

Disk identifiers are highlighted above in bold (for use in the next step).

2. Use the disklabel utility to show more about each disk (needs to be run as root):

doas disklabel -h <disk identifier>

This gives you more info about the disk in -h human readable format - i.e. megabytes, gigabytes etc.

3. See info (including size and free space) about already mounted filesystems

(I know this may not strictly answer the question but I've included it for completeness)

If you have already mounted the filesystem, your disk will be included in the information displayed by: df -h

4. Review system messages if still unsure:

dmesg outputs messages from the kernel as hardware is detected. Use this with grep if you still can't find your disk:

dmesg | grep -i 'scsi'

1

OpenBSD doesn't have a similar tool. You can see the disks in the dmesg or running sysctl hw.disknames. Also, disklabel and fdisk can show info about the partitions.

0

You might want to install smartmontools. smartctl -i can give you detailed information about the disks reported by sysctl hw.disknames, e.g.

{root@marvin:~ (local) 515} sysctl hw.disknames
hw.disknames=sd0:cb4856da548e0d52,sd1:cc3b031d5ae03c66,sd2:
{root@marvin:~ (local) 516} smartctl -i /dev/sd0c
smartctl 7.3 2022-02-28 r5338 [OpenBSD 7.3 amd64] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Marvell based SanDisk SSDs
Device Model:     SanDisk SSD PLUS 480GB
Serial Number:    221005453309
LU WWN Device Id: 5 001b44 4a54ccec2
Firmware Version: UG4004RL
User Capacity:    480,103,981,056 bytes [480 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Form Factor:      2.5 inches
TRIM Command:     Available, deterministic
Device is:        In smartctl database 7.3/5319
ATA Version is:   ACS-3, ACS-2 T13/2015-D revision 3
SATA Version is:  SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Fri Oct 20 08:27:47 2023 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

Next fdisk can show you the MBR or GPT disk layout:

{root@marvin:~ (local) 517} fdisk sd0    
Disk: sd0       geometry: 58369/255/63 [937703088 Sectors]
Offset: 0       Signature: 0xAA55
            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   1   2 -  58368 254  63 [          64:   937697921 ] OpenBSD

Last but not least you can see the OpenBSD partions using disklabel:

{root@marvin:~ (local) 518} disklabel sd0
# /dev/rsd0c:
type: SCSI
disk: SCSI disk
label: USB 3.0 TOSATA  
duid: cb4856da548e0d52
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 58369
total sectors: 937703088
boundstart: 64
boundend: 937697985

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:        100646912            16384  4.2BSD   2048 16384 12960 # /
  b:         33554432        100663296    swap                    # none
  c:        937703088                0  unused                    
  e:        671088640        134217728  4.2BSD   4096 32768 26062 # /export
-2

Type in a terminal mountenter. It lists all mounted slices (a.k.a. partitions).

Unmounted can be found with:

dmesg | grep sd     <-- if using an SSD
dmesg | grep wd     <-- for an HDD

In O-BSD dmesg WILL register when you plug in a USB, just give it a second or two.

For all drivers loaded @ startup: dmesg | grep dev

<-- this is good for checking if the alphabet soup boys have gifted your system a piece of software.

1
  • 1
    Welcome to U&L. Please note: SE sites are not discussion groups, but question/answer sites. The idea is that the answers are helpful for also others down the line. Colloquialisms are a bit questionable, as they aren't universal - e.g. I've never heard abt alphabet soup boys. I'd suggest either deleting this part or re-phrasing it to open also to non-in-crowd. Here's advice how to write a useful answer. Checking the Asking- and Answering -parts in the Help gives you an idea how these sites work. Feb 17, 2023 at 10:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .