Device Files

These files are an actual representation of all your hardware devices according to how your drivers see them. Please do not modify or delete these files unless you know what you are doing.

Device files are special files that exist as an interface for your system to interact with hardware. They are located in the /dev directory, which is a temporary virtual filesystem that is created by Linux on boot.

Block Devices

Block devices are devices that store buffered data as blocks.

These files are essentially the low-level interface to your storage devices. They are usually to be mounted to a directory in order to be used, similarly to how Windows automatically assigns drive letters to storage devices.

Newer Windows versions also support mounting devices as directories, but they are not commonly used.

There are various types of block devices, but the most common ones are:

  • SATA, PATA/IDE, SAS, SCSI or USB disks (/dev/sd*)
  • NVMe Drives (/dev/nvme*)
  • Device mappers (/dev/mapper/*) - A special feature of the Linux kernel that allows you to create virtual block devices from other block devices.
  • Loop devices (/dev/loop*) - Virtual loopback devices that allow you to mount files as block devices.
  • MMC devices (/dev/mmcblk*) - Memory cards that use the MultiMediaCard standard, such as SD cards.

Pseudo-devices

Pseudo-devices are devices that do not actually exist but are used by the kernel to provide an interface for various features.

The most common pseudo-devices are:

  • /dev/null - A special empty file that discards all data written to it.
  • /dev/zero - A special file that returns an infinite stream of null bytes when read.
  • /dev/random, /dev/urandom - Special files that return an infinite stream of random data.
  • /dev/full - A special empty file that always returns a “disk full” error when written to.
  • /dev/ptmx - A pseudo-terminal master used to create virtual terminals.
  • /dev/tty* - A virtual terminal that is used to interact with the system. Back in the day, there were also actual physical terminals that were connected to the system via a serial port. Nowadays, these files are used to represent virtual terminals, as computer terminals were replaced by actual computers running remote desktop software such as SSH, VNC or RDP.
  • /dev/pts/* - A virtual terminal slave used to create virtual terminals.
  • /dev/shm/* - A shared memory segment used by the kernel to share data between processes.
  • /dev/stdin, /dev/stdout, /dev/stderr - Standard input, output and error streams. Used to redirect input and output from and to other files, similar to how programs output data directly to the terminal. Can be redirected using pipelines.

Interacting with Devices

You can interact with device files like you would with any other file, but there are also special tools that are used to interact with them.

The cat command can be used to read data from a file and output it to /dev/stdout (standard output), which is usually the terminal.

cat /dev/urandom

This will output an infinite stream of random garbage to the terminal, which will make it unusable until you press Ctrl+C to stop the command. You might also need to restart your terminal emulator if it happens to output a specific combination of characters that breaks it.

Block Devices

To list all block devices, you can use lsblk to list them in a tree-like format:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 931.5G  0 disk
├─sda1        8:1    0   600M  0 part /boot/efi
├─sda2        8:2    0     1G  0 part /boot
└─sda3        8:3    0 929.9G  0 part
zram0       252:0    0     8G  0 disk [SWAP]
nvme0n1     259:0    0 119.2G  0 disk
└─nvme0n1p1 259:1    0 119.2G  0 part /var/lib/docker/btrfs
                                      /home
                                      /var
                                      /

Explaining the Output:

sda* is the main disk of the system, which is a 1TB SATA SSD. It has 3 partitions, sda1, sda2 and sda3. sda1 is the EFI partition, sda2 is the boot partition and sda3 is the root partition.

In this specific case, it is configured in a Btrfs spanned (JBOD) volume, which in this case combines both sda3 and nvme0n1p1 into a single volume.

Ultramarine Linux’s installer, Anaconda will automatically configure your disks in a Btrfs spanned volume by default when multiple disks are selected.

nvme0n1 is a 128GB NVMe SSD that is used as a cache for the Btrfs volume. It has a single partition, nvme0n1p1, which is mounted to /var/lib/docker/btrfs, /home, /var and /.

zram0 is a special ramdisk that is used as a pagefile (swap) for the system. It makes uses of the zram kernel module to create a compressed RAM disk.

The mountpoints at /boot is used for storing Linux kernel images, and /boot/efi is used for storing EFI bootloaders.

/var stores extra variable data, /home is a dedicated partition for storing user data and / is the root partition, which can be compared to the C:\ drive on Windows.

/var/lib/docker/btrfs is the directory where Docker stores its data. Docker is a containerization software that allows you to run applications in isolated environments. Since we are using Btrfs, Docker will use Btrfs subvolumes to store its data. For other filesystems, Docker will use other methods to store its data.

Manipulating Block Devices

You can use fdisk to do various operations on block devices, such as creating partitions, formatting them and more.

fdisk /dev/sda

NEVER run the following commands on any actual systems! These commands ANNIHILATE your system WITHOUT CONFIRMATION, causing IRREVERSIBLE DAMAGES to your system!

If you want to test out these commands for whatever reason, please make sure (and double check) you are ONLY doing this in a virtual environment.

As an example, you can use the following command to do a zero-filled format of a disk called /dev/sda by simply using a pipe:

cat /dev/zero > /dev/sda

…Or shred the entire disk with random data:

cat /dev/urandom > /dev/sda

All of these commands will do destructive operations on your disk, so please be careful when using them.

You can also use the dd tool to read and write data to block devices, create disk images and even clone disks directly.

For example, you can create a backup image (ghost image) of your disk by using the following command:

dd if=/dev/sda of=/path/to/backup.img

…Or clone your disk to another disk:

dd if=/dev/sda of=/dev/sdb

You can find more information about dd here.

← Back To: The Filesystem

Next Up: Permissions →