How to use the command 'nvram' (with examples)
- Osx
- December 25, 2023
The ’nvram’ command is used to manipulate firmware variables on macOS. Firmware variables store system information related to the hardware and software configuration. This command allows users to view, modify, and delete these variables.
Use case 1: Print all the variables stored in the NVRAM
Code:
nvram -p
Motivation: This use case is useful for viewing all the variables stored in the NVRAM. It can provide valuable information about the system’s firmware configuration.
Explanation:
nvram
: The command itself.-p
: A command-line option that instructs the command to print all the variables stored in the NVRAM.
Example output:
boot-args -v
bootercfg bootercfg=macpro
prev-lang:kbd en:0
Use case 2: Print all the variables stored in the NVRAM using XML format
Code:
nvram -xp
Motivation: This use case is similar to the first one, but it prints the variables in XML format. XML files are structured and can be easily parsed by other applications.
Explanation:
nvram
: The command itself.-x
: A command-line option that instructs the command to print the variables in XML format.-p
: A command-line option that instructs the command to print all the variables.
Example output:
<nvram>
<key>boot-args</key>
<data>2D76</data>
<key>bootercfg</key>
<string>macpro</string>
<key>prev-lang:kbd</key>
<string>en:0</string>
</nvram>
Use case 3: Modify the value of a firmware variable
Code:
sudo nvram name="value"
Motivation: This use case allows users to modify the value of a specific firmware variable. It can be handy when making system configurations or troubleshooting issues related to firmware settings.
Explanation:
sudo
: A command that allows the ’nvram’ command to run with administrative privileges.nvram
: The command itself.name="value"
: The name of the firmware variable and its new value. Replace ’name’ with the actual variable name, and ‘value’ with the desired value.
Example output: (No output is displayed)
Use case 4: Delete a firmware variable
Code:
sudo nvram -d name
Motivation: Sometimes it may be necessary to remove a firmware variable, especially when troubleshooting issues caused by incorrect or unnecessary variables.
Explanation:
sudo
: A command that allows the ’nvram’ command to run with administrative privileges.nvram
: The command itself.-d
: A command-line option that instructs the command to delete a firmware variable.name
: The name of the firmware variable to be deleted.
Example output: (No output is displayed)
Use case 5: Clear all the firmware variables
Code:
sudo nvram -c
Motivation: Clearing all the firmware variables can be useful when restoring the system’s default firmware configuration or resolving issues caused by conflicting or corrupt variables.
Explanation:
sudo
: A command that allows the ’nvram’ command to run with administrative privileges.nvram
: The command itself.-c
: A command-line option that instructs the command to clear all the firmware variables.
Example output: (No output is displayed)
Use case 6: Set a firmware variable from a specific XML file
Code:
sudo nvram -xf path/to/file.xml
Motivation: This use case allows users to set firmware variables by providing an XML file. It can be useful when deploying consistent configurations on multiple systems or restoring specific settings from a backup.
Explanation:
sudo
: A command that allows the ’nvram’ command to run with administrative privileges.nvram
: The command itself.-x
: A command-line option that instructs the command to interpret the XML file.-f
: A command-line option that specifies the path to the XML file.path/to/file.xml
: The path to the XML file containing the firmware variable values.
Example output: (No output is displayed)
Conclusion:
The ’nvram’ command is a powerful tool for managing firmware variables on macOS. It provides various options to view, modify, and delete these variables, allowing users to customize and troubleshoot their system’s firmware configuration.