How to use the command devfsadm (with examples)
- Sunos
- December 25, 2023
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 thedisk
class. This argument instructsdevfsadm
to scan for new disks specifically.
Example output:
devfsadm[349]: devfsadm: disk has been added: disk3
Use case 2: Cleanup any dangling /dev links and scan for new devices
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,” instructingdevfsadm
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,” instructingdevfsadm
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,” causingdevfsadm
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.