Jump to content











Photo
- - - - -

how to grub2 efi savedefault?


  • Please log in to reply
5 replies to this topic

#1 ndog37

ndog37

    Member

  • Members
  • 88 posts
  •  
    New Zealand

Posted 19 February 2017 - 11:40 AM

It seems grub2.efi for a boot manager is not popular on reboot.pro forums, and I'm having problems getting what should be a simple question answered. I don't have linux installed and am booting various other stuff, using grub2 efi, since it works well and boots all the stuffs.

 

With grub4dos it is easy you simply need a few files on the root partition so you can remember the last booted item and boot from it eg

grldr

menu.lst

default

 

menu.lst

timeout 3
default /default

title Boot - XP-1.vhd (7GB)
savedefault
hide (hd0,0)
hide (hd0,1)
find --set-root --ignore-floppies /XP-1.vhd
map /XP-1.vhd (hd0)
map --hook
root (hd0,0)
chainloader /ntldr

title Boot - OSX
savedefault
hide (hd0,1)
unhide (hd0,0)
parttype (hd0,0) 0xAF
rootnoverify (hd0,0)
makeactive
chainloader --force +1

title Boot - NT6
savedefault
hide (hd0,0)
unhide (hd0,1)
parttype (hd0,1) 0x07
rootnoverify (hd0,1)
makeactive
chainloader /bootmgr

Which seems fairly simple and straight forward, however with grub2 efi it seems that everyone has in their mind you have to recompile and rebuild it everytime under your linux OS, however I do not have a linux OS or desire having one, I simple want to modify the text file grub.cfg and have an option to savedefault

 

this is my current grub.cfg which is working great with only the 3 files required but I want to be able to boot the last booted option everytime

/EFI/Boot/BOOTX64.efi

/EFI/Boot/grubx64.efi

/EFI/Boot/grub.cfg

set default="0"

function load_video {
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod all_video
}

load_video
set gfxpayload=keep

insmod gzio
insmod part_gpt

set timeout=4


menuentry "Windows 7 UEFI" {
insmod chain
search --file --no-floppy --set=root /efi/Microsoft/win7/bootmgfw.efi
chainloader (${root})/efi/Microsoft/win7/bootmgfw.efi
}

menuentry "OSX Clover" {
# Clover insists that bootx64.efi sits in /efi/boot and looks for /efi/clover/cloverx64.efi
insmod chain
search --file --no-floppy --set=root /efi/Boot/BOOTX64.clover.efi
chainloader (${root})/efi/Boot/BOOTX64.clover.efi
}

# clonezilla live partition
#search --file --set=CLZDRV --no-floppy /clonezilla/live/vmlinuz
#echo $(CLZDRV) # will show hd0,gpt1 - not useful for clonezilla
# hint: cat /proc/cmdline - check clonezilla parameters
# hint: user:user pass:live

menuentry 'Clonezilla Restore' --class gnu-linux --class gnu --class os {
set CLZDRV=sda1
set CLZDIR=/clonezilla/live
set BUPDRV=sda2
set BUPDIR=/clonezilla/images
set BOPT="boot=live quiet union=overlay keyboard-layouts=NONE locales=en_US.UTF-8"
set RUN="ocs_live_run=\"ocs-live-general\" live-media-path=$CLZDIR bootfrom=/dev/$CLZDRV toram=filesystem.squashfs ocs_live_batch=yes"
set PRERUN="ocs_prerun=\"mount /dev/$BUPDRV /mnt\" ocs_prerun1=\"mount --bind /mnt/$BUPDIR /home/partimag/\""
set RUN1="ocs_live_run=\"ocs-sr --batch -scr -t -k -p reboot restoreparts ask_user ask_user\""
linuxefi /clonezilla/live/vmlinuz $BOPT $RUN $PRERUN $RUN1
initrdefi /clonezilla/live/initrd.img
}

menuentry 'Clonezilla Create' --class gnu-linux --class gnu --class os {
set CLZDRV=sda1
set CLZDIR=/clonezilla/live
set BUPDRV=sda2
set BUPDIR=/clonezilla/images
set BOPT="boot=live union=overlay keyboard-layouts=NONE locales=en_US.UTF-8"
set RUN="ocs_live_run=\"ocs-live-general\" live-media-path=$CLZDIR bootfrom=/dev/$CLZDRV toram=filesystem.squashfs ocs_live_batch=yes"
set PRERUN="ocs_prerun=\"mount /dev/$BUPDRV /mnt\" ocs_prerun1=\"mount --bind /mnt/$BUPDIR /home/partimag/\""
set RUN1="ocs_live_run=\"ocs-sr --batch -q -nogui -z2p -i 2048 -fsck -scs -senc -rm-win-swap-hib -p choose saveparts ask_user ask_user\""
linuxefi /clonezilla/live/vmlinuz $BOPT $RUN $PRERUN $RUN1
initrdefi /clonezilla/live/initrd.img
}

menuentry 'Wimboot test' {
insmod chain
search --file --set=root --no-floppy /wimboot/bootmgr
set cmdline="initrdfile=/wimboot/bootmgr,/wimboot/BCD,/wimboot/boot.sdi,/wimboot/snip/boot.wim pause"
chainloader (${root})/wimboot/wimboot $cmdline
}

### http://forum.ipxe.org/showthread.php?tid=8112
### http://forum.ipxe.org/showthread.php?tid=8193&pid=13354#pid13354
menuentry "iPXE"{
  search --no-floppy --set=root -f /clonezilla/live/ipxe.efi
  chainloader (${root})/clonezilla/live/ipxe.efi + 1
}

Anyway I have tried searching and googling, and trying a few different things, it seems all the searches involve recompiling grub in ubuntu which I obviously do not have. Hopefully someone knows a quick and easy way to make this happen. Fingers crossed.

 

Eg

which file to save where

the command under grub2 to load the default

the command under grub2 to save the default

 

and a working example would be awesome



#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 19 February 2017 - 01:28 PM

You won't probably like this answer. (provided that it classifies as an answer) :dubbio:

 

Check:
https://www.gnu.org/...vironment-block

https://www.gnu.org/...ml#load_005fenv

https://www.gnu.org/...ml#save_005fenv

https://www.gnu.org/...e-configuration

 

The file is (should be) by default /boot/grub/grubenv, it is clear that to use it you need the command:
set default="saved"

then you need in each entry a:

savedefault

command.

Or maybe save_env? :unsure:*like*:



" saved_entry=${chosen}
save_env saved_entry "

(it seems that savedefault is not among the "official" commands) :dubbio:

 

See this:

https://ubuntuforums...d.php?t=1417361

 

:duff:

Wonko


  • ndog37 likes this

#3 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 19 February 2017 - 02:36 PM

Place the 1024 byte file grubenv on \boot\grub

 

use

 

save_env fred

 

to save the current value of fred

 

use load_env to load all variables from it (e.g. at beginning of code)

 

load_env fred  will load fred

 

list_env will list all variables in the file

 

if you use

set fred=hello
unset fred
save_env fred
load_env fred

then the variable fred will exist  but be empty = ""   !!


Edited by steve6375, 19 February 2017 - 04:26 PM.

  • ndog37 likes this

#4 ndog37

ndog37

    Member

  • Members
  • 88 posts
  •  
    New Zealand

Posted 20 February 2017 - 08:34 AM

Thanks wonko and steve6375

 

got it working :)

and simply you can use $1 as the option to save

 

/EFI/Boot/grubx64.efi

/EFI/Boot/BOOTX64.EFI

/EFI/Boot/grubenv - 1024 bytes

/EFI/Boot/grub.cfg

load_env default

function load_video {
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod all_video
}

load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt

set timeout=15


menuentry "Windows" {
set default=$1
save_env default
insmod chain
set root='(hd0,gpt1)'
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}

# clonezilla live partition
#search --file --set=CLZDRV --no-floppy /clonezilla/live/vmlinuz
#echo $(CLZDRV) # will show hd0,gpt1 - not useful for clonezilla
# hint: cat /proc/cmdline - check clonezilla parameters
# hint: user:user pass:live
menuentry 'Clonezilla Restore' --class gnu-linux --class gnu --class os {
set default=$1
save_env default
set CLZDRV=sda1
set CLZDIR=/clonezilla/live
set BUPDRV=sda2
set BUPDIR=/clonezilla/images
set BOPT="boot=live quiet union=overlay keyboard-layouts=NONE locales=en_US.UTF-8"
set RUN="ocs_live_run=\"ocs-live-general\" live-media-path=$CLZDIR bootfrom=/dev/$CLZDRV toram=filesystem.squashfs ocs_live_batch=yes"
set PRERUN="ocs_prerun=\"mount /dev/$BUPDRV /mnt\" ocs_prerun1=\"mount --bind /mnt/$BUPDIR /home/partimag/\""
set RUN1="ocs_live_run=\"ocs-sr --batch -scr -t -k -p reboot restoreparts ask_user ask_user\""
linuxefi /clonezilla/live/vmlinuz $BOPT $RUN $PRERUN $RUN1
initrdefi /clonezilla/live/initrd.img
}
menuentry 'Clonezilla Create' --class gnu-linux --class gnu --class os {
set default=$1
save_env default
set CLZDRV=sda1
set CLZDIR=/clonezilla/live
set BUPDRV=sda2
set BUPDIR=/clonezilla/images
set BOPT="boot=live union=overlay keyboard-layouts=NONE locales=en_US.UTF-8"
set RUN="ocs_live_run=\"ocs-live-general\" live-media-path=$CLZDIR bootfrom=/dev/$CLZDRV toram=filesystem.squashfs ocs_live_batch=yes"
set PRERUN="ocs_prerun=\"mount /dev/$BUPDRV /mnt\" ocs_prerun1=\"mount --bind /mnt/$BUPDIR /home/partimag/\""
set RUN1="ocs_live_run=\"ocs-sr --batch -q -nogui -z2p -i 2048 -fsck -scs -senc -rm-win-swap-hib -p choose saveparts ask_user ask_user\""
linuxefi /clonezilla/live/vmlinuz $BOPT $RUN $PRERUN $RUN1
initrdefi /clonezilla/live/initrd.img
}

### http://forum.ipxe.org/showthread.php?tid=8112
### http://forum.ipxe.org/showthread.php?tid=8193&pid=13354#pid13354
menuentry "iPXE"{
set default=$1
save_env default
  search --no-floppy --set=root -f /clonezilla/live/ipxe.efi
  chainloader (${root})/clonezilla/live/ipxe.efi + 1
}

menuentry 'UBT-small.vhd' --class  ubuntu {
set default=$1
save_env default
insmod gzio
insmod part_msdos
insmod part_gpt
insmod ext2
insmod ntfs
insmod probe
set vhdfile="/ubt/UBT-small.vhd"
set root=(hd0,gpt2)
probe -u --set=uuid $root
loopback loop0 $vhdfile
linux (loop0,1)/vmlinuz root=UUID=$uuid rw kloop=$vhdfile kroot=/dev/mapper/loop0p1
initrd (loop0,1)/initrd.img
}



#5 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 20 February 2017 - 09:41 PM

If it helps, I have written up some notes and links here about grub2.


  • ndog37 likes this

#6 ndog37

ndog37

    Member

  • Members
  • 88 posts
  •  
    New Zealand

Posted 21 February 2017 - 09:03 AM

Thanks Steve

 

Its great to be able to use grub2 as a boot loader without linux installed and I still have yet to harness the full power of it. I wanted to use rEFInd instead, however there is no support for this product, and the forums are dead. at the moment I can't get clonezilla to load from it or wimboot, so I am stuck with grub2, which just works, but not as graphically fancy, or as nice installing on a macbook






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users