0

I need to write below commands on every pc restart:

grubrescue>set boot=(hd0,msdos7)
grubrescue>set prefix=(hd0,msdos7)/boot/grub
grubrescue>insmod normal
grubrescue>normal

How to set boot device permanently in grub?


My /boot/grub/grub.cfg file:

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_msdos
insmod ext2
set root='hd2,msdos7'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
else
  search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=pl_PL
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=10
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 10 ; then
    set timeout=0
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30,0; then
  clear
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=1
    else
        set vt_handoff=
    fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-35919a5d-0315-40fc-87d3-d4d75e6d118a' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_msdos
    insmod ext2
    set root='hd2,msdos7'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
    else
      search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
    fi
        linux   /boot/vmlinuz-4.18.0-21-generic root=UUID=35919a5d-0315-40fc-87d3-d4d75e6d118a ro  quiet splash $vt_handoff
    initrd  /boot/initrd.img-4.18.0-21-generic
}
submenu 'Opcje zaawansowane dla systemu Ubuntu' $menuentry_id_option 'gnulinux-advanced-35919a5d-0315-40fc-87d3-d4d75e6d118a' {
    menuentry 'Ubuntu, za pomocą systemu Linux 4.18.0-21-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-21-generic-advanced-35919a5d-0315-40fc-87d3-d4d75e6d118a' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd2,msdos7'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
        else
          search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
        fi
        echo    'Wczytywanie systemu Linux 4.18.0-21-generic...'
            linux   /boot/vmlinuz-4.18.0-21-generic root=UUID=35919a5d-0315-40fc-87d3-d4d75e6d118a ro  quiet splash $vt_handoff
        echo    'Wczytywanie początkowego dysku RAM...'
        initrd  /boot/initrd.img-4.18.0-21-generic
    }
    menuentry 'Ubuntu, with Linux 4.18.0-21-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-21-generic-recovery-35919a5d-0315-40fc-87d3-d4d75e6d118a' {
        recordfail
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd2,msdos7'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
        else
          search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
        fi
        echo    'Wczytywanie systemu Linux 4.18.0-21-generic...'
            linux   /boot/vmlinuz-4.18.0-21-generic root=UUID=35919a5d-0315-40fc-87d3-d4d75e6d118a ro recovery nomodeset 
        echo    'Wczytywanie początkowego dysku RAM...'
        initrd  /boot/initrd.img-4.18.0-21-generic
    }
    menuentry 'Ubuntu, za pomocą systemu Linux 4.18.0-20-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-20-generic-advanced-35919a5d-0315-40fc-87d3-d4d75e6d118a' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd2,msdos7'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
        else
          search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
        fi
        echo    'Wczytywanie systemu Linux 4.18.0-20-generic...'
            linux   /boot/vmlinuz-4.18.0-20-generic root=UUID=35919a5d-0315-40fc-87d3-d4d75e6d118a ro  quiet splash $vt_handoff
        echo    'Wczytywanie początkowego dysku RAM...'
        initrd  /boot/initrd.img-4.18.0-20-generic
    }
    menuentry 'Ubuntu, with Linux 4.18.0-20-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-20-generic-recovery-35919a5d-0315-40fc-87d3-d4d75e6d118a' {
        recordfail
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd2,msdos7'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
        else
          search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
        fi
        echo    'Wczytywanie systemu Linux 4.18.0-20-generic...'
            linux   /boot/vmlinuz-4.18.0-20-generic root=UUID=35919a5d-0315-40fc-87d3-d4d75e6d118a ro recovery nomodeset 
        echo    'Wczytywanie początkowego dysku RAM...'
        initrd  /boot/initrd.img-4.18.0-20-generic
    }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry 'Memory test (memtest86+)' {
    insmod part_msdos
    insmod ext2
    set root='hd2,msdos7'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
    else
      search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
    fi
    knetbsd /boot/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
    insmod part_msdos
    insmod ext2
    set root='hd2,msdos7'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos7 --hint-efi=hd2,msdos7 --hint-baremetal=ahci2,msdos7  35919a5d-0315-40fc-87d3-d4d75e6d118a
    else
      search --no-floppy --fs-uuid --set=root 35919a5d-0315-40fc-87d3-d4d75e6d118a
    fi
    linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows 7 (na /dev/sdc1)' --class windows --class os $menuentry_id_option 'osprober-chain-2E824FB1824F7BF9' {
    insmod part_msdos
    insmod ntfs
    set root='hd2,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos1 --hint-efi=hd2,msdos1 --hint-baremetal=ahci2,msdos1  2E824FB1824F7BF9
    else
      search --no-floppy --fs-uuid --set=root 2E824FB1824F7BF9
    fi
    parttool ${root} hidden-
    chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
1
  • 1
    Use grub-mkconfig to add the configuration file.
    – Biswapriyo
    Commented Jun 2, 2019 at 6:45

1 Answer 1

1

This looks to be similar to GRUB Rescue - setting boot and prefix again and again and/or How can I manually define the grub prefix variable?, the TLDR version of which is...

## Is GRUB updated?
sudo update-grub
## Some systems may instead want...
# sudo grub-mkconfig -o /boot/grub/grub.cfg

## Is GRUB installed?
# sudo grub-install /dev/sd<some-letter>

... I say this because generally one only needs the commands you're using when in rescue mode.

The other thing that may be of interest while digging around GRUB options is...

info -f grub -n 'Multi-boot manual config'

... among other informative documentation that may be found via the info command.

Updates

Based off the updated question, I'll advise that ya copy the /etc/grub.d/30_os-prober block to somewhere like /etc/grub.d/29_ms7 and edit the 29_ms7 copy...

menuentry 'Grub Tests - Windows 7 (na /dev/sdc1)' --class windows --class os $menuentry_id_option 'osprober-chain-<Unique-ID-Stuff>' {
    insmod part_msdos
    insmod ntfs
    set root='hd2,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos1 --hint-efi=hd2,msdos1 --hint-baremetal=ahci2,msdos1  <Unique-ID-Stuff>
    else
      search --no-floppy --fs-uuid --set=root <Unique-ID-Stuff>
    fi
    parttool ${root} hidden-
    chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi

Side note, do not copy/paste above without editing things and reading up on the suggested info documentation, it's just pulled from your configs to highlight the important bits with minimal sanitation.

... after running sudo update-grub and rebooting there should be an additional Grub menu option. This new option and the copied config file are correlated because of updating Grub.

Edit the custom Grub menu file (if following along that'd be the /etc/grub.d/29_ms7 file), update Grub, reboot the device, and repeat until ya no longer need the rescue mode.

Hint, some of those --hint-* options might instead work better where some 2s turned to 0s and/or 1s transmuted into 7s.

I'm not quite sure what got messed up between what Grub automatically generated and how the MS OS is installed, but my guess is that there's some kind of re-partitioning/partition-resizing that took place in an advance menu during installation of Linux... did you by chance try to install Linux and Windows on the same hard-drive?

Windiws and Ubuntu are on same hard drive. Also this Ubuntu 18 is installed in place of Ubuntu 16 that I had couple of years with some grub config

That's super helpful to know!.

In the future it's a good idea to install different Operating Systems on separate storage media (I know that doesn't help in the present nor does), and when forced to share space it's a good idea to keep all the MS stuff at the start of the storage media's addressing scheme.

Focusing in on what can be done in the present, if ya check your grub.cfg file it makes use of msdos7 within the...

### BEGIN /etc/grub.d/20_memtest86+ ###
# ...
### END /etc/grub.d/20_memtest86+ ###

... block, however, for some reason Grub is looking at hd2 instead of hd0 and within the 30_os-prober it's looking for msdos1 in addition to looking for hd2. In short something got confused as to how Operating Systems are to be found. So it is clear as to what kinds of edit's I'm suggesting...

menuentry 'Windows 7 -- Tests' --class windows --class os $menuentry_id_option 'osprober-chain-<Unique-ID-Stuff>' {
    insmod part_msdos
    insmod ntfs
    set root='hd0,msdos7'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos7 --hint-efi=hd0,msdos7 --hint-baremetal=ahci2,msdos7  <Unique-ID-Stuff>
    else
      search --no-floppy --fs-uuid --set=root <Unique-ID-Stuff>
    fi
    parttool ${root} hidden-
    chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi

Though, again, do not copy/past without consideration of available information and modifications.

... while I may be wrong on some of the above edits, it's mainly to show where I'm suggesting edits take place within your own custom config file. It'll take a little fiddling to get things booting happily again, but with what's above and referencing the informative documentation I've faith ya can get things sorted soon.

5
  • Tried every of these and this not permanently set it :(. Ubuntu 18.4
    – Sruj
    Commented Jun 6, 2019 at 9:09
  • Dang... can ya post your /boot/grub/grub.cfg file within your question then? Well minus anything ya thing is sensitive as far as strings. You are running Grub2 right? I hope so, though that might be where you're running into issues... what file are you editing to add your OS boot?... hint if you're on Grub2 it likely should be a custom file (one you've added or perhaps the installer has added), under the /etc/grub.d/ directory.
    – S0AndS0
    Commented Jun 6, 2019 at 9:34
  • 1
    Just updated main question with config file, and my grub version is (GRUB) 2.02-2
    – Sruj
    Commented Jun 8, 2019 at 6:32
  • didn't tried your solution yet but yes Windiws and Ubuntu are on same hard drive. Also this Ubuntu 18 is installed in place of Ubuntu 16 that I had couple of years with some grub config
    – Sruj
    Commented Jun 8, 2019 at 18:28
  • Thanks for all the updates @Sruj! I've updated my answer to provide a few more examples on building a custom Grub entry, if ya do a more /etc/grub.d/30_os-prober it'll show that there's a shell script that is building that menu option on each update to Grub. That'll one day in the future may be helpful, if ya ever want to get fancy with Grub. For now though I'll still suggest testing a custom menu entry, put lots of comments (# prefixed lines) as ya learn... given latest info I'll further guess that the upgrade to Ubuntu 18 succeeded but with errors; Linux boots from Grub?
    – S0AndS0
    Commented Jun 8, 2019 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .