How to use the command devfsadm (with examples)

How to use the command devfsadm (with examples)

Devfsadm is an administration command for /dev that helps maintain the /dev namespace in the Unix operating system. It is responsible for managing the device files in the system, creating or removing device nodes, and ensuring consistent device naming conventions. The command serves as an essential tool for device management and allows for efficient scanning, cleanup, and modification of the /dev directory. In this article, we will explore three common use cases of the devfsadm command.

Use case 1: Scan for new disks

Code:

devfsadm -c disk

Motivation: The motivation to use this command is to scan the system for any newly added disks and create the corresponding device files in the /dev directory. This is useful when hot-swapping or adding disks to the system, as the operating system needs to recognize and assign proper device files to the newly added disks.

Explanation:

  • devfsadm: The command itself.
  • -c disk: The -c flag is used to specify the class of devices to configure, and in this case, we use the disk class. This argument instructs devfsadm to scan for new disks specifically.

Example output:

devfsadm[349]: devfsadm: disk has been added: disk3

Code:

devfsadm -C -v

Motivation: The motivation to use this command is to clean up any dangling or obsolete device links in the /dev directory. These dangling links may occur when devices are removed from the system without properly removing their corresponding device files. Additionally, this command can also be used to scan for new devices and create/update the appropriate device files.

Explanation:

  • devfsadm: The command itself.
  • -C: The -C flag stands for “cleanup,” instructing devfsadm to remove any dangling links and prune the /dev directory.
  • -v: The -v flag stands for “verbose,” providing more detailed output during the cleanup and scanning process.

Example output:

devfsadm: Cleaning up dangling symlinks:
/dev/fd -> ../devices/pseudo/fd@0:fd
/dev/fb -> ../devices/pseudo/fb@0:fb
devfsadm: Cleaning up '/dev/.devfsadm_dev.lock'
devfsadm: Cleaning up '/dev/.inasms_dev_lock'
devfsadm: Cleaning up '/dev/.update_drv_lock'
devfsadm: devfsadm complete
devfsadm: execvp(/usr/sbin/drvconfig,SunOS-5.10/sparc)

Use case 3: Dry-run - output what would be changed but make no modifications

Code:

devfsadm -C -v -n

Motivation: The motivation to use this command is to perform a dry-run, which allows users to see what changes would be made without actually modifying the system. This is useful for understanding the impact of running devfsadm with specific arguments before applying any modifications.

Explanation:

  • devfsadm: The command itself.
  • -C: The -C flag stands for “cleanup,” instructing devfsadm to remove any dangling links and prune the /dev directory.
  • -v: The -v flag stands for “verbose,” providing more detailed output during the cleanup and scanning process.
  • -n: The -n flag stands for “dry-run,” causing devfsadm to only output the changes that would have been made but not actually apply them.

Example output:

Cleaning up dangling symlinks:
/dev/fd -> ../devices/pseudo/fd@0:fd
/dev/fb -> ../devices/pseudo/fb@0:fb

Changes that would be made:
/dev/fd -> ../devices/pseudo/fd@0:fd
/dev/fb -> ../devices/pseudo/fb@0:fb

Conclusion:

The devfsadm command is a powerful tool for maintaining the /dev namespace in the Unix operating system. It allows users to scan for new devices, cleanup dangling links, and perform dry-runs to preview the changes. Understanding and effectively utilizing this command can greatly enhance the device management capabilities of a system, ensuring proper device file configuration and consistent device naming conventions.

Related Posts

How to use the command qm status (with examples)

How to use the command qm status (with examples)

The qm status command is used to display the status of virtual machines in Proxmox VE.

Read More
Using loginctl (with examples)

Using loginctl (with examples)

The loginctl command is a powerful tool for managing the systemd login manager.

Read More
How to use the command `docker start` (with examples)

How to use the command `docker start` (with examples)

The docker start command is used to start one or more stopped containers.

Read More