NVRAM, or Non-Volatile Random Access Memory, is a small piece of memory that macOS uses to store small pieces of data that should be preserved between reboots such as the brightness level of the display. Many generic PC's, however, do not have NVRAM, which causes minor annoyances such the display being max brightness after every reboot and other settings not persisting. This guide will show you a way to circumvent the issue of not having an NVRAM chip by storing the data in a file.
DISCLAIMER: there is a "proper" way to do this using clover. This is not it; this is the horrible bodge that works for some reason. Following this guide will make the boot and shutdown process slightly slower, as well as pose a major security risk. I am not responsible for the consequences of your actions, even if they are literally following my instructions.
How to test if your NVRAM works
MacOS provides a pretty good way to interface with the NVRAM: the nvram command. Open a terminal and type 'nvram -p'. This should show you the current NVRAM. You can manually set a variable like so: nvram foo=bar' (you might need to sudo that). You can then usenvram -p | grep -i "foo"to see if you were successful. Reboot, and trynvram -p | grep -i "foo"` again, and if you get anything back your NVRAM works. If you don't you can follow this guide, although you still probably shouldn't because it's an enormous hack.
Prerequisites
- A working macOS system. Does not even have to be a hackintosh; this will also fix actual macs that just happen to have broken NVRAM. Version requirement is anything that uses the LaunchDeamon system, so anything made in the last 10 years.
- A rudimentary understanding of UNIX and Bash; I will be using bash scripts and the terminal quite a bit for this guide. I also don't recommend you install bodges like this unless you have some idea of what you are doing.
- A willingness to bodge; you must have given up on doing things "properly" to use this guide.
- Any other fixes for this, such as Clovers
EmuVariableUefi-64.efi, are not required.
Step 1: store the NVRAM on shutdown.
using nvram -xp, you can get the contents of the NVRAM in XML format, which is somewhat better for file storage. So the command you want to use to store the NVRAM to disk would be nvram -xp > /nvram.plist. This will take the nvram, and store it in a nice and convenient file at the root directory.
Unfortunately, there are some things in the NVRAM which you can't simply set with user commands for some reason, so we'll want to get those out of the file first. For me, they are the key csr-active-config and some of the fakesmc keys. They can be removed with sed. This makes the final command: nvram -xp | sed -n '/<key>csr-active-config<\/key>/,/<\/data>/d;p' | sed -n '/<key>fakesmc-key-.*<\/key>/,/<\/data>/d;p' > /nvram.plist.
Finally, we want to store this on shutdown; To do this, we can use the native LaunchDeamons. Unfortunately, they do not like it when we use such a long command, so we want to make a bash script instead. I put mine in /usr/boot-shutdown.sh. For the record, my file is as follows:
#!/bin/sh nvram -xp | sed -n '/<key>csr-active-config<\/key>/,/<\/data>/d;p' | sed -n '/<key>fakesmc-key-.*<\/key>/,/<\/data>/d;p' > /nvram.plist echo NVRAM Saved!
Make sure the file is executable by running chmod +x <filename> on it.
Now that we have a bash script that will store our info on shutdown, we only need to make sure it runs on shutdown. To do so, make a file called com.apple.delta.nvram.put.plist (or something like it) in /Library/LaunchDeamons with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key><string>boot.shutdown.script.name</string> <key>ProgramArguments</key> <array> <string>/usr/boot-shutdown.sh</string> </array> <key>RunAtLoad</key> <true/> <key>StandardOutPath</key> <string>LOG_PATH/boot-shutdown.log</string> <key>StandardErrorPath</key> <string>LOG_PATH/boot-shutdown.err</string> </dict> </plist>
Make sure the file has the right permission by running chown 0:0 <filename>" on it. If you did not put your bash script in/usr/boot-shutdown.sh`, make sure to change that as well.
To test whether or not it works, reboot and check the contents of /nvram.plist. If you see a populated plist, it works (probably)! Make sure that these settings can actually be loaded by running sudo nvram -xf /nvram.plist; if that still gives you permission errors regarding certain keys, you can use more sed commands in the bash script to remove those keys as well.
Step 2: Loading the NVRAM from disk
Now that we have a file, all that we need is to load it during the boot process. Fortunately, we can also use the LaunchDeamons for this, and we don't even need to use a bash script for it! Make another file in /Library/LaunchDeamons, named com.apple.delta.nvram.set.plist (or whatever you like) with the following contents:
<?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”> <plist version=”1.0″> <dict> <key>Label</key> <string>com.delta.nvram.set</string> <key>ProgramArguments</key> <array> <string>nvram</string> <string>-xf</string> <string>/nvram.plist</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Again, make sure that this file has the right permissions.
This will cause a script to run at boot which loads the contents of /nvram.plist into the virtual NVRAM. You can use the regular NVRAM test to see if it was successful.
Congratulations! You should now have a few less minor annoyances.
tl;dr
Make a LaunchDeamon that puts the contents of nvram -xp into a file on shutdown; pipe it through sed to remove keys you can't set. Use another LaunchDeamon that loads it back on boot.
[link] [comments]
Post a Comment