4

I have Arch, Ubuntu, and GRUB2 installed on a BTRFS filesystem. I'm aware that GRUB cannot write to BTRFS for a variety of good reasons, and therefore cannot save environment variables to /boot/grub/grubenv.

I have un-used space at the start and at the end of my disk (due to alignment), and I'm led to believe that the BTRFS file system has some kind of "arbitrary storage" area too.

Is there some way I can configure GRUB to use any of these areas to store persisntent environment variables, instead of it trying (and failing) to use the /boot/grub/grubenv file?

1

save_env and load_env take a parameter --file optionally.

If you search 00_header in /etc/grub.d, you can set a variable at the top like:

GRUBENV="(hd0,msdos1)/grubenv"

and below in the first echo stanza:

grubenv="$GRUBENV"

Then you can find the one load_env and make it

load_env --file "\${grubenv}"

And search for all save_env's and change them to

save_env --file "\${grubenv}"

... Copy grubenv from /boot/grub/grubenv to /mnt/myfatpart (whereever you mount (hd0,0) in the above example)

update-grub

Example:

...

# You should have received a copy of the GNU General Public License
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.

# Akua - grubenv doesn't survive on ZFS
GRUBENV="(hd0,msdos1)/grubenv"

...

if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then 
GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi

cat << EOF
# Akua - grubenv doesn't survive on ZFS
grubenv="$GRUBENV"

# Akua
if [ -s "\${grubenv}" ]; then
  set have_grubenv=true
  # Akua
  load_env --file "\${grubenv}"
fi

...

 akua@blackbird:~ 09:08 / 
 $ grep grubenv /etc/grub.d/00_header
# Akua - grubenv doesn't survive on ZFS
GRUBENV="(hd0,msdos1)/grubenv"
# Akua - grubenv doesn't survive on ZFS
grubenv="$GRUBENV"
if [ -s "\${grubenv}" ]; then
  set have_grubenv=true
  load_env --file "\${grubenv}"
   save_env --file "\${grubenv}" prev_entry
   save_env --file "\${grubenv}" next_entry
   save_env --file "\${grubenv}" next_entry
  save_env --file "\${grubenv}" saved_entry
  save_env --file "\${grubenv}" prev_saved_entry
save_env --file "\${grubenv}" saved_entry
    if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
      save_env --file "${grubenv}" prev_entry
  save_env --file "${grubenv}" initrdfail
  if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env --file "\${grubenv}" recordfail; fi; fi
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.