2

I have to Linux dist installed on two separate HDDs, currently I' m working from home so sometimes need to switch OS back and forth. I tried all these steps from this link:

Set “older” kernel as default grub entry

but nothing works for me.

Each time Debian 9 Stretch being loaded. How can I switch to Ubuntu OS ?

Here is my setup

enter image description here

Here is the disk configuration. I need to boot OS from /dev/sdb1.

enter image description here

  • You are probably going from this grub into grub on the other disk which then sends you back to this OS. What is the disk configuration look like? I wonder if you can change this grub to point to /dev/sdb2 instead of /dev/sdb1. – rtaft Jul 14 '20 at 17:38
  • @rtaft I' ve just posted disk config in the topic. – StNickolay Jul 14 '20 at 17:43
  • Can you mount /dev/sdb1 and view /boot/grub/grub.cfg to see if it is pointing back to sda? – rtaft Jul 14 '20 at 17:53
  • How can I examine /boot/grub/grub.cfg to figure out where is it pointing to ? – StNickolay Jul 14 '20 at 18:30
  • Remotely? First mount it, sudo mkdir /media/ubuntu and sudo mount /dev/sdb1 /media/ubuntu, Then view /media/ubuntu/boot/grub/grub.cfg and look at the line set default to see what it says, I think that's the setting to look at. – rtaft Jul 14 '20 at 19:36
  • currently set default is ### 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 – StNickolay Jul 14 '20 at 19:57
  • By the way , which one grub.cfg, do I need to examine? /boot/grub/grub.cfg or {mount_point_of_sdb1/boot/grub/grub.cfg ? Which one will be used during boot process? – StNickolay Jul 14 '20 at 20:02
  • Can you post both to a pastbin so we can examine both? I really don't know which one is getting executed first. – rtaft Jul 14 '20 at 20:04
  • Amazing on the HDD (dev/sdb1, {mount_point_of_sdb1/boot/grub/grub.cfg ) where is the Ubuntu installed set default point to set default="Debian GNU/Linux 9 (stretch) (on /dev/sda3)" – StNickolay Jul 14 '20 at 20:05
  • Reinstall the bootloader to both MBRs to make sure Debians Grub is used (sudo grub-install /dev/sda and sudo grub-install /dev/sdb). Set default in Debians Grub to boot Ubuntu. When booted into Ubuntu and you want to reboot into debian do the same in Ubuntu (reinstall bootloader to both MBR) and configure Ubuntus Grub to default to Debian. – mook765 Jul 15 '20 at 12:23
  • @mook765 I don't clearly understand how to do second step you suggest: Set default in Debians Grub to boot Ubuntu. Actually, currently, changing /etc/default/grub has no effect at all. i.e. always Debian(/dev/sdaX) being loaded. – StNickolay Jul 15 '20 at 15:58
  • That's why you should reinstall the bootloader to both MBR, obviously the wrong bootloader is used ( the one from Ubuntu which will not look for it's config in Debian). In /etc/default/grub set GRUB_DEFAULT=2 (that should be Ubuntu entry), run sudo update-grub, reinstall the bootloader (see previous comment), reboot. – mook765 Jul 15 '20 at 16:47
  • @mook765, Ok, currently I was able to boot proper OS. But not exactly in the way you suggested. I will post an answer below. – StNickolay Jul 16 '20 at 10:00

1 Answers1

1

Thanks to @rtaft and @mook765 for helping. I'm not very experiencing in grub internals, and actually I don't have much desire to read tons of documentation.

In my case I have to HDD:

  • /dev/sda - Debian
  • /dev/sdb - Ubuntu.

Both of these have their own copy of /boot/grub/grub.cfg. Let's say I login to Debian now, it means all commands like sudo grub-update sudo grub-set-default x

etc. will affect grub.cfg of Debian dist currently running.

Taking into account, that I don't know order of executing of these two versions of grub.cfg. I decided to change line with set default="Desired OS", in my case set default="Debian GNU/Linux 9 (stretch) (on /dev/sda3)"

for BOTH these grub.cfg.

Summary:

  1. I changed /boot/grub/grub.cfg manually and set desired default.
  2. I mount second HDD (/dev/sdb -> ~/mnt_devsdb).
  3. I changed ~/mnt_devsdb/boot/grub/grub.cfg manually and set desired default(the same as for p.1).
  4. reboot and .... voila! it works!

To boot Ubuntu I need to repeat all these steps and set proper default again.