OpenBSD Mount And Use a USB Flash Drive

last updated in Categories , , ,

How do I mount and use a USB pen or hard disk under OpenBSD operating systems using ksh/bash/sh shell prompt?

OpenBSD does supports USB storage devices such as pen and hard disk via emulated SCSI drives. You need to login as root user to mount USB pen/disk.

Finding out your USB device name on an OpenBSD based system

First, insert your your USB flash drive in USB socket. Type the following command to list device names:

# sysctl hw.disknames
Sample outputs:


To get more info about sd0 (my usb pen), type:
# dmesg | grep sd0
Sample outputs:

sd0 at scsibus1 targ 1 lun 0:  SCSI2 0/direct removable
sd0: 1956MB, 512 bytes/sector, 4005888 sectors
sd0 detached
sd0 at scsibus1 targ 1 lun 0:  SCSI2 0/direct removable
sd0: 1956MB, 512 bytes/sector, 4005888 sectors

The following command shows more information about sd0
# disklabel sd0
Sample outputs:

# /dev/rsd0c:
type: vnd
disk: vnd device
label: fictitious
duid: 97d41b01a9d85387
bytes/sector: 512
sectors/track: 100
tracks/cylinder: 1
sectors/cylinder: 100
cylinders: 5120
total sectors: 4005888
boundstart: 0
boundend: 512000
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize  cpg]
  a:           512000                0  4.2BSD   2048 16384    1 
  c:          4005888                0  unused                   

Mounting USB Pen/Hard Disk on an OpenBSD

Type the following command to create a directory (mount point), enter:
# mkdir /mnt/pen

Mount the flash drive using mount command at /mnt/pen, enter:
# mount /dev/sd0i /mnt/pen
You may need to replace /dev/sd0i with actual device name. Now, you can access the files at /mnt/pen:
# cd /mnt/pen
# ls -l
# cp filename /path/to/dir

Finally, unmount the flash filesystem using the following command:
# umount /mnt/pen

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

9 comment

  1. “You may need to replace /dev/sd0i with actual device name.”

    For people new to OpenBSD, how do you find the actual device name?

  2. Use dmesg. The device shows up in dmesg output after plugging it in. You can also use usbdevs.

    1. Answering my own question:

      $ disklabel sd0

      At the end, you will see the partitions. The i-label denotes a partition.

      1. What if you want a non-root program to be able to write (save) dirctly to the directory?
        i can’t seem to figure this out.

    Have a question? Post it on our forum!