Devices and Device NodesA device is a term used mostly for hardware-related activities in a system, including disks,
printers, graphics cards, and keyboards. When MidnightBSD boots, the majority of the boot
messages refer to devices being detected. A copy of the boot messages is saved to
/var/run/dmesg.boot.
Each device has a device name and number. For example, ada0 is the first SATA
hard drive, while kbd0 represents the keyboard. The number suffix starts at zero
and increments for each additional device of the same type found in the system.
Most devices in MidnightBSD must be accessed through special files called device nodes,
which are located in /dev. Device nodes are not regular files — they are
interfaces into the kernel that let programs communicate with hardware. They are created
and managed automatically by devfs, the device file system.
/dev is a special in-memory file system mounted by the kernel at boot. Its
contents are populated dynamically as devices are detected or attached. When you plug in
a USB drive, a new device node such as /dev/da0 appears automatically. When
you remove it, the node disappears.
You can list the device nodes currently present on your system:
ls /dev
Device nodes have a type, owner, group, and permissions just like regular files. The type
is shown by ls -l as either c (character device) or b
(block device). Disk devices are character devices on MidnightBSD, as is common on BSD
systems. Permissions control which users and programs may read from or write to a device.
To see the type and permissions of disk device nodes:
ls -l /dev/ada0 /dev/da0
The kernel records messages about every device it detects during boot. These messages are
saved to /var/run/dmesg.boot and can be read at any time:
cat /var/run/dmesg.boot
The dmesg command shows the current kernel message buffer, which includes the
boot messages and any messages added since boot, such as devices attached after startup:
dmesg
To filter dmesg output for a specific device type, pipe it through grep:
dmesg | grep ada
dmesg | grep usb
The pciconf command lists all PCI and PCI Express devices in the system,
whether or not a driver has attached to them:
pciconf -lv
To list USB devices:
usbconfig list
MidnightBSD uses different device name prefixes depending on the type of storage controller and connection interface.
SATA hard drives and SSDs connected through the ATA driver appear as ada
devices. The first drive is ada0, the second is ada1, and so on.
PATA (IDE) drives also use the ada prefix on modern MidnightBSD.
/dev/ada0 — first SATA disk/dev/ada1 — second SATA diskSCSI hard drives, SAS drives, and USB mass storage devices appear as da
(Direct Access) devices. USB thumb drives and external hard drives attached via USB will
appear as da0, da1, etc., alongside any SCSI or SAS disks.
/dev/da0 — first SCSI, SAS, or USB storage device/dev/da1 — second such deviceNVMe solid state drives are exposed through two sets of nodes. The nvme node
represents the controller itself, while nvd (or nda on newer
MidnightBSD) represents the namespace (the disk you read and write to).
/dev/nvme0 — first NVMe controller/dev/nvd0 — first NVMe disk namespace/dev/nda0 — NVMe disk via the CAM layer (newer releases)CD-ROM, DVD, and Blu-ray drives appear as cd devices.
/dev/cd0 — first optical driveTo mount a CD:
mount -t cd9660 /dev/cd0 /mnt
Memory disks are virtual disk devices backed by RAM or a file. They are useful for creating RAM disks, mounting disk images, or setting up temporary file systems.
/dev/md0 — first memory diskCreate a 64MB memory disk backed by RAM:
mdconfig -a -t malloc -s 64m -u 0
Attach a disk image file as a memory disk:
mdconfig -a -t vnode -f diskimage.img
Detach a memory disk:
mdconfig -d -u 0
The GEOM framework exposes stable disk labels that do not change when disks are
reordered. GPT partition labels appear under /dev/gpt/ and disk labels
created with glabel appear under /dev/label/. Using labels
in /etc/fstab is more reliable than using raw device names.
/dev/gpt/rootfs — GPT partition labeled "rootfs"/dev/label/home — disk labeled "home" via glabelMidnightBSD supports both GPT (GUID Partition Table) and MBR (Master Boot Record) partitioning. The partition naming scheme differs between the two.
On a GPT disk, partitions are named with a p suffix followed by the
partition number:
/dev/ada0p1 — first GPT partition on ada0/dev/ada0p2 — second GPT partition on ada0/dev/nvd0p1 — first GPT partition on nvd0On an MBR disk, the top level is divided into slices (named with s) which
contain BSD partitions (named with a letter). This two-level scheme is the traditional
BSD disk layout:
/dev/ada0s1 — first MBR slice on ada0/dev/ada0s1a — the a (root) partition within slice 1/dev/ada0s1b — the b (swap) partition within slice 1/dev/ada0s1e — the e (/var) partition within slice 1/dev/ada0s1f — the f (/usr) partition within slice 1The traditional BSD partition letters and their conventional mount points are:
a — root (/)b — swapc — the entire disk (raw slice, not normally mounted)d — historically reserved; now available for general usee — /varf — /usrg — /home or additional spaceNetwork interfaces do not have device nodes in /dev. They are managed directly
through the kernel's networking stack using commands such as ifconfig. However,
they follow the same naming convention of a driver prefix and a unit number.
Common network interface names:
em0 — Intel PRO/1000 Gigabit Ethernet (em driver)igb0 — Intel server Gigabit Ethernet (igb driver)ix0 — Intel 10 Gigabit Ethernet (ix driver)bge0 — Broadcom BCM57xx Gigabit Ethernetre0 — Realtek 8139/8169 Ethernetvtnet0 — VirtIO network interface (virtual machines)vmx0 — VMware VMXNET3 network interfacelo0 — loopback interfacewlan0 — 802.11 wireless (created from a physical device such as ath0)To list all network interfaces and their current configuration:
ifconfig
To show dmesg output for a specific network driver:
dmesg | grep em0
MidnightBSD provides several virtual consoles accessible from the physical keyboard and
display. They appear as ttyv devices and can be switched between with
Alt+F1 through Alt+F8 (or as configured in /etc/ttys).
/dev/ttyv0 — first virtual console (Alt+F1)/dev/ttyv1 — second virtual console (Alt+F2)/dev/ttyv7 — eighth virtual console, often used by X11Physical serial ports and USB-to-serial adapters appear as ttyu and
cuau devices. The ttyu name is used for incoming connections
(dial-in), while cuau is used for outgoing connections (dial-out) such as
connecting to a console server or modem.
/dev/ttyu0 — first serial port (incoming / login)/dev/cuau0 — first serial port (outgoing / dial-out)/dev/ttyu1 — second serial portUSB-to-serial adapters (such as FTDI or Prolific chips) appear as ttyU
(capital U) devices:
/dev/ttyU0 — first USB serial adapterTo connect to a serial device at 9600 baud using cu:
cu -l /dev/cuau0 -s 9600
Pseudo-terminals are pairs of virtual devices used by SSH, terminal emulators, and
other programs that need a terminal interface. They appear as /dev/pts/
entries and are created on demand.
/dev/pts/0 — first pseudo-terminal slaveKeyboard devices are represented by kbd nodes. The console keyboard
is typically kbd0. USB keyboards may appear as additional units.
/dev/kbd0 — first keyboardPS/2 mice are accessed through the psm device.
/dev/psm0 — PS/2 mouseUSB mice appear as ums devices. Generic USB HID (Human Interface Device)
devices that do not match a more specific driver appear as uhid.
/dev/ums0 — first USB mouse/dev/uhid0 — first generic USB HID deviceOn systems using the evdev input layer, input devices such as touchpads, keyboards, and
mice may also appear as numbered nodes under /dev/input/.
/dev/input/event0 — first evdev input devicePseudo-devices are special device nodes that do not correspond to any physical hardware. They provide useful kernel-level interfaces for general programming and system use.
Reading from /dev/null always returns end-of-file immediately. Writing to it
discards all data silently. It is commonly used to suppress unwanted output:
command > /dev/null 2>&1
Reading from /dev/zero produces an endless stream of zero bytes. It is used
to create blank files of a specific size or to zero out memory regions:
dd if=/dev/zero of=blankfile bs=1m count=100
/dev/random provides cryptographically secure random bytes from the kernel's
entropy pool. /dev/urandom also provides random bytes and will not block
even when the entropy pool is low (it uses a CSPRNG seeded from the pool instead).
Both are suitable for generating keys, tokens, and other security-sensitive values.
dd if=/dev/random bs=32 count=1 | hexdump -C
/dev/full always returns a "disk full" error when written to. It is useful
for testing how a program behaves when it cannot write to a file.
These nodes are symbolic references to the standard input, output, and error streams of the current process. They allow programs that expect a file path to read from or write to the terminal or a pipe.
cat /dev/stdin
The /dev/fd/ directory provides nodes for each open file descriptor of
the current process. /dev/fd/0, /dev/fd/1, and
/dev/fd/2 correspond to stdin, stdout, and stderr respectively.
/dev/mem provides access to physical memory and /dev/kmem
provides access to kernel virtual memory. Access is restricted to root. These devices
are used by low-level diagnostic tools.
MidnightBSD provides several tools for inspecting and managing devices.
Displays the kernel message buffer, including device detection messages from boot and any messages generated since:
dmesg | less
devinfo prints the device tree as the kernel sees it, showing parent/child
relationships between buses and devices:
devinfo -r
Lists all PCI and PCIe devices with their driver bindings and hardware identifiers.
Useful for identifying hardware that has no driver attached (shown with a
none driver):
pciconf -lv
Lists connected USB devices and their configuration:
usbconfig list
usbconfig dump_info
camcontrol manages devices attached through the CAM (Common Access Method)
storage layer, including SCSI, SAS, SATA, and NVMe disks. To list all CAM devices:
camcontrol devlist
To see detailed information about a specific disk, including its model and serial number:
camcontrol inquiry da0
camcontrol identify ada0
diskinfo reports the geometry and size of a disk device:
diskinfo -v ada0