≡ Menu

OpenBSD Mount And Use a USB Flash Drive

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:

hw.disknames=wd0:3af96a8b7d621ab2,cd0:,sd0:

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
flags:
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

Share this tutorial on:
{ 5 comments… add one }
  • Allan June 30, 2009, 4:51 pm

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

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

  • nixCraft June 30, 2009, 7:34 pm

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

  • 100 June 7, 2010, 12:59 am

    How did you know the ‘i’ in sd0i? Dmesg only shows ‘sd0’ with no ending.

    • 100 August 7, 2010, 12:44 pm

      Answering my own question:

      $ disklabel sd0

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

  • dean October 3, 2010, 3:37 pm

    another way
    # sysctl hw.disknames

    will show (example)
    $ sysctl hw.disknames
    hw.disknames=wd0,wd1,cd0

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , , ,