tested on openbsd 6.4
make sure you are using the device name and partition you need, before your
destroy all your data run any destructive commands like dd(1).
you can address disk/partitions...
| by disklabel UID | |
|---|---|
xxxxxxxxxxxxxxxx |
raw device |
xxxxxxxxxxxxxxxx.c |
entire disk |
xxxxxxxxxxxxxxxx.a |
partition a |
| or by full path | |
/dev/rsd1c |
entire disk raw device sd1 |
/dev/rsd1a |
a partition |
/dev/sd1c |
entire disk same, but as a block device |
/dev/sd1a |
a partition |
a raw device (or character device) is accessed directly, bypassing the operating system's caches and buffers.
when to use block devices then?
there are programs like disklabel(8),
they accept all kinds of names (/dev/sd0c, or /dev/sd0, or even sd0) and
parse them into full path /dev/rsd0c.
# disklabel sd1
# /dev/rsd1c:
...
#
some programs, like fdisk(8), accept some
abbreviations, like sd1 or sd1c, but refuse to work with block devices.
# fdisk /dev/sd1c
fdisk: /dev/sd1c is not a character device
#
other programs, for example, dd(1), just do what you told them to do.
don't repeat at home:
# dd if=/dev/zero of=/dev/sd3 bs=1m
/: write failed, file system is full
dd: /dev/sd3: No space left on device
919+0 records in
918+0 records out
962592768 bytes transferred in 2.466 secs (390316750 bytes/sec)
#
this dd creates the file /dev/sd3 and fills up your root partition.
$ sysctl hw.disknames
hw.disknames=sd0:yyyyyyyyyyyyyyyy,sd1:zzzzzzzzzzzzzzzz
$
sd0 is the device connected first, its duid is yyyyyyyyyyyyyyyy
sd1 is
the second and duid is zzzzzzzzzzzzzzzz.
these numbers (sd0 and sd1) may change after reboot or pluging/unpluging usb
devices, but duids are persitent until you rewrite it with disklabel.
if you are looking for a just connected usb drive, then grep(1) word removable
in the output of dmesg(1).
$ dmesg | grep removable | tail -1
sd1 at scsibus5 ... SCSI3 0/direct removable ...
$
sd1 is what you are looking for.
Run disklabel(1) with a disk name or DUID.
# disklabel sd1
# /dev/rsd1c:
type: SCSI
disk: SCSI disk
label: llllllllll
duid: zzzzzzzzzzzzzzzz
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 1945
total sectors: 31260672
boundstart: 0
boundend: 31260672
drivedata: 0
16 partitions:
# size offset fstype [fsize bsize cpg]
a: 31260672 0 4.2BSD 2048 16384 1
c: 31260672 0 unused
#
if you are looking for openbsd partition (4.2BSD) it's the partition a.
the entire disk is represented as the partition c (marked as unused, because
you can't create a file system on this partition).