2

Just like in the title:

I have two HDD (/dev/sda and /dev/sdb) on my PC, each has its own EFI (flags: boot, hidden, esp) partition. How to force ubuntu to install /boot/efi on /dev/sdb2 instead of on /dev/sda1

My setup:

ubuntu@ubuntu:~$ sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
NAME                FSTYPE        SIZE MOUNTPOINT                    LABEL
sda                             119.2G                               
├─sda1              vfat          100M                               ESP
├─sda2                             16M                               
├─sda3              ntfs        118.1G                               Acer
└─sda4              ntfs            1G                               Recovery
sdb                             931.5G                               
├─sdb1              ntfs        481.5G                               Data
├─sdb2              vfat          512M                               
├─sdb3              ext4            5G                               
├─sdb4              swap           32G [SWAP]                        
└─sdb5              LVM2_member   150G                               
  └─vg_ubuntu-lv_ubuntu
                                  100G                               
sdc                               7.3G                               
└─sdc1              vfat          7.3G /cdrom                        UBUNTU 19_0
ubuntu@ubuntu:~$ 

sda is my "factory installed" windows.
sda1 is (Windows boot loader).
My "goal" is to keep sda intact/unchanged via installing linux as follows:

NAME                FSTYPE        SIZE MOUNTPOINT                    LABEL
sda                             119.2G                               
├─sda1              vfat          100M                               ESP
├─sda2                             16M                               
├─sda3              ntfs        118.1G                               Acer
└─sda4              ntfs            1G                               Recovery
sdb                             931.5G                               
├─sdb1              ntfs        481.5G                               Data
├─sdb2              vfat          512M /boot/efi                     
├─sdb3              ext4            5G /boot                         
├─sdb4              swap           32G [SWAP]                        
└─sdb5              LVM2_member   150G                               
  └─vg_ubuntu-lv_ubuntu                /

unfortunately, yesterday I messed something up, and I installed ubuntu 19 this way:

NAME                FSTYPE        SIZE MOUNTPOINT                    LABEL
sda                             119.2G                               
├─sda1              vfat          100M /boot/efi                     ESP
├─sda2                             16M                               
├─sda3              ntfs        118.1G                               Acer
└─sda4              ntfs            1G                               Recovery
sdb                             931.5G                               
├─sdb1              ntfs        481.5G                               Data
├─sdb2              vfat          512M                               
├─sdb3              ext4            5G /boot                         
├─sdb4              swap           32G [SWAP]                        
└─sdb5              LVM2_member   150G                               
  └─vg_ubuntu-lv_ubuntu                /

I plan to boot into /dev/sdb via changing the order bios' bootloader.

Any idea what can I do to "achieve" the desired effect?


EDIT:
This question was marked as a possible duplicate of:
How can I reinstall GRUB to the EFI partition?

This is not true. The link above (at least according to my understanding) explains how to move grub from one partition to another, or how to install it from "zero". With the requirement that the Linux OS is already installed.

My question was about "forcing" the grub onto the correct partition during the installation, not after.

If anything, this question is closer to being a duplicate of:
How do I install Ubuntu to a USB key? (without using Startup Disk Creator)
(just replace "USB key" with "2nd internal HDD")

PatrykB
  • 193
  • 3
  • 2
    Ubuntu's Ubiquity installer will not let you, One work around is to remount ESP during install: https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1396379 You can copy or move /EFI/ubuntu & /EFI/Boot to your second drive, update fstab with correct UUID and use efibootmgr to add new entry using correct ESP. Or just do a total reinstall of grub2 in UEFI mode which will do all of that. Or disconnect all other drives, so only the drive you want is in system during install. – oldfred Aug 03 '19 at 14:55
  • @oldfred thank you very much! the link you provided lead me to the solution (a workaround). All I had to do was to remove ESP flags (boot, hidden, efi) from the /dev/sda1 partition. The 18th comment (https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1396379/comments/18) in the bug-thread explains the solution. – PatrykB Aug 03 '19 at 20:18

1 Answers1

4

Like I already said in the comments, the info & link kindly provided by @oldfred lead me to the solution (a workaround) of my problem.

I only had to temporarily remove ESP related partition flags (boot, hidden, efi) from the /dev/sda1 partition. I mean during the installation. Once the installation was completed, I've restored them.

The "Link-o-graphy":
1) https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1396379
2) https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1396379/comments/18
3) How do I install Ubuntu to a USB key? (without using Startup Disk Creator)
(they all lead to the same answer, just read the last one)

The result:

***@***:~$ sudo lsblk -o NAME,LABEL,SIZE,FSTYPE,FSSIZE,FSUSED,FSAVAIL,MOUNTPOINT
NAME                    LABEL         SIZE FSTYPE      FSSIZE FSUSED FSAVAIL MOUNTPOINT
sda                                 119,2G                                   
├─sda1                  ESP           100M vfat                              
├─sda2                                 16M                                   
├─sda3                  Acer        118,1G ntfs                              
└─sda4                  Recovery        1G ntfs                              
sdb                                 931,5G                                   
├─sdb1                  Data        481,5G ntfs                              
├─sdb2                  ESP           512M vfat          511M   7,5M  503,5M /boot/efi
├─sdb3                  Boot            1G ext4        975,9M 118,3M  790,4M /boot
├─sdb4                  Swap           32G swap                              [SWAP]
└─sdb5                                150G LVM2_member                       
  └─ubuntu_vg-ubuntu_lv               100G ext4           98G   5,8G   87,2G /

UPDATE:

something happened and I had to reinstall Ubuntu. Unfortunately, this time I forget to restore EFI-related partition flags on /dev/sda1 and I booted into my "factory-installed" windows. During the boot, it correctly recognized /dev/sda1 as EFI (despite the lack of flags - I have no idea how), but once botted, Windows started treating /dev/sda1 like any other partition (I saw ESP labeled partition in "My Computer" in Windows' "Explorer"). I quickly booted into ubuntu, flagged /dev/sda1 as boot, hidden, efi, but it didn't solve the problem. After the reboot, partition was still there. It goes without saying, how dangerous this situation was...

Fix:

  1. Open Windows Powershell or the command line as administrator:
    Start→Right click PowershellRun as administrator

  2. Open diskpart:
    diskpart

  3. Identify the EFI partition showing up in Explorer:
    list volume

  4. Select the EFI partition (replacing the X with the correct driveletter):
    select volume X

  5. Remove the EFI partition's drive letter (replacing the X with the correct drive letter):
    remove letter=X

  6. Exit diskpart:
    exit

  7. Open regedit:
    Start→Type regedit

  8. Find the right key/folder:
    Computer\HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices

  9. If the EFI partitions drive letter is still in the registry, delete the value:
    e.g. \DosDevices\X:

  10. Close RegEdit and reboot.

Source: https://superuser.com/a/1344227


UPDATE #2:
(more like a note)

During the installation of Ubuntu, at the "partition selection" step (that's my "pseudo-name" of this step - I doubt its called that), there's an option device for boot loader installation.

I always change this option from /dev/sda(the default setting) to /dev/sdb(the target device).

It's possible to set device for boot loader installation to /dev/sdb2 (the partition, not device) instead of /dev/sdb but it has some unpleasant consequences:

Note that under “Device for boot loader installation”:

  • if you choose dev/sda, it’ll use Grub (Ubuntu’s boot loader) to load all systems on this hard drive.
  • If you choose dev/sda1 (the ext4 partition your created for Ubuntu), Ubuntu need to be manually added to drive’s boot loader after installation. (for example, you previously have Windows installed on another partition of this drive, you’ll need manually add Ubuntu into mbr)

Source: http://ubuntuhandbook.org/index.php/how-to-install-ubuntu/

PatrykB
  • 193