Archive

Posts Tagged ‘GRUB2’

Adding custom boot target to GRUB2

October 1st, 2012 No comments

In GRUB2 one doesn’t alter the main configuration file /boot/grub2/grub.cfg manually any more. Boot menu entries are automatically determined by the grub2-mkconfig script.

To add a custom menu entry, edit /etc/grub.d/40_custom

[...]
menuentry 'Custom Entry' {
  set root='hd0,msdos2'
  echo    'Loading Linux'  
  linux   /vmlinuz
  echo    'Loading initial ramdisk ...'
  initrd  /initramfs.img
}

Note that GRUB2 partition numbering starts with 1 (not 0 like GRUB) but disk numbering starts with 0, e.g. if your kernel and inital ramdisk are located on /dev/sda2, this translates to hd0,2.

On MS-DOS type partitions (which currently is the majority of partitions out there) hd0,2 and hd0,msdos2 are interchangeable.

To recreated grub.cfg with the added boot menu entry, invoke

grub2-mkconfig -o /boot/grub2/grub.cfg

Resources:
http://home.roadrunner.com/~computertaijutsu/grub2.html

Categories: Uncategorized Tags:

Change GRUB2 default boot target

September 19th, 2012 No comments

In GRUB, the default boot menu entry was determined by the order of entries in /boot/grub/menu.lst, the default one being the n-th specified by the default=n parameter.

In GRUB2 the main configuration file /boot/grub2/grub.cfg isn’t usually altered manually any more but automatically generated by invoking grub2-mkconfig. You can change the default boot target by changing the GRUB_DEFAULT paramater in /etc/default/grub. It takes three different values:

GRUB_DEFAULT=n specifies the n-th entry in /boot/grub2/grub.cfg. The first entry is selected with GRUB_DEFAULT=0, just like in GRUB.

GRUB_DEFAULT="String" chooses an entry by name (e.g. “Fedora (3.5.3-1.fc17.x86_64)”)

GRUB_DEFAULT=saved chooses the boot target specified in /boot/grub/grubenv regardless whether the order of entries has changed (e.g. due to a kernel update).

To manipulate /boot/grub/grubenv, you can list all possible entries

grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2

and specify the desired one with

grub2-set-default <menu entry title>

To verify the default menu entry, use

grub2-editenv list

Note that you have to run

grub2-mkconfig -o /boot/grub2/grub.cfg

if you make any changes to /etc/default/grub (e.g. change the GRUB_DEFAULT parameter). You don’t have to invoke it, if you just change the default target with grub2-set-default since this just alters grubenv but doesn’t make any changes to grub.cfg.

Resources:
http://fedoraproject.org/wiki/GRUB_2
http://www.linuxreaders.com/2011/11/fedora-16-how-to-change-boot-sequence-grub2.html

Categories: Uncategorized Tags: ,