Home / Articles

Mounting removable media on OpenBSD

2017-05-01T16:20:00Z.

On OpenBSD, removable media can be mounted using mount(8).

This article assumes you are using OpenBSD 6.1 and mounting a USB flash drive.

Check device name

First check the device name of the USB flash drive:


dmesg

At the end of the output, lines similar to the following should be shown:


umass0 at uhub0 port 7 configuration 1 interface 0 "TOSHIBA TransMemory" rev 2.00/1.00 addr 3
umass0: using SCSI over Bulk-Only
scsibus4 at umass0: 2 targets, initiator 0
sd1 at scsibus4 targ 1 lun 0: <TOSHIBA, TransMemory, 1.04> SCSI0 0/direct removable serial.0930652937611091E8DB
sd1: 489MB, 512 bytes/sector, 1001472 sectors

Here, the USB flash drive is available as sd1.

Check disk partitions

The disk partitions of the disk sd1 can be checked using disklabel(8). Run the following as root:


disklabel -h /dev/sd1c

The -h switch makes the partition sizes printed in human-readable format. Note the use of /dev/sd1c, the letter c represents the whole disk.

Output similar to the following should be shown:


# /dev/sd1c:
type: SCSI
disk: SCSI disk
label: TransMemory
duid: 0000000000000000
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 62
total sectors: 1001472 # total bytes: 489.0M
boundstart: 0
boundend: 1001472
drivedata: 0

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  c:           489.0M                0  unused
  i:           489.0M                0   MSDOS

Here, the USB flash drive as 1 partition (i) that can be mounted.

Mount disk partition to directory

Create a directory, for example:


mkdir /tmp/usb

Mount the disk partition by running the following as root:


mount /dev/sd1i /tmp/usb

The files in the USB flash drive on partition i can be accessed in /tmp/usb directory.

Umount disk partition

Before removing the USB flash drive, umount the mounted partition. Run the following as root:


umount /dev/sd1i

References