NixOs Ubuntu dual boot problem


describe changes made

I had a working Ubuntu 22.04 install on diskA and another on diskB (separate physical disks). I replaced the Ubuntu install in diskB with NixOS from a live USB. I can no longer boot into the Ubuntu on diskA.
I’m not especially knowledgeable on hardware and boot loaders. However, it sounds to me that a different boot loader (ESP not grub) is in control now.

  • diskA is nvme0n1
  • diskB is /dev/sda as best I can tell.

Looking at Bootloader - NixOS Wiki, I tried changing some settings and ran sudo nixos-rebuild --install-bootloader switch

Here are my current configuration.nix settings where I changed things:

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.efi.efiSysMountPoint = "/boot/efi";
  boot.loader.grub.efiSupport = true;
  boot.loader.grub.device = "nodev";


I ran “boot repair” and it produced the below log.

boot-repair-4ppa203                                              [20230113_1752]

============================== Boot Info Summary ===============================


nvme0n1: _______________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  Ubuntu 22.04.1 LTS
    Boot files:        /boot/grub/grub.cfg /etc/fstab /etc/default/grub

sdb: ___________________________________________________________________________

    File system:       iso9660
    Boot sector type:  Unknown
    Boot sector info: 
    Mounting failed:   mount: /mnt/BootInfo/FD/sdb: /dev/sdb already mounted or mount point busy.


================================ 0 OS detected =================================


================================ Host/Hardware =================================

CPU architecture: 64-bit
Video: GM107 [GeForce GTX 750 Ti] HD Graphics 530 from NVIDIA Corporation Intel Corporation
Live-session OS is Ubuntu 64-bit (Ubuntu 20.04.5 LTS, focal, x86_64)

===================================== UEFI =====================================

BIOS/UEFI firmware: 1.1.12(1.1) from Dell Inc.
The firmware is EFI-compatible, and is set in EFI-mode for this live-session.
SecureBoot disabled (confirmed by mokutil).
BootCurrent: 1006
Timeout: 1 seconds
BootOrder: 0002,0000,0001,0003,0004,0005
Boot0000  ubuntu    VenHw(99e275e7-75a0-4b37-a2e6-c5385e6c00cb)
Boot0001  Windows Boot Manager  VenHw(99e275e7-75a0-4b37-a2e6-c5385e6c00cb)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...d................
Boot0002* grub.efi  VenHw(99e275e7-75a0-4b37-a2e6-c5385e6c00cb)
Boot0003  Onboard NIC (IPV4)    PciRoot(0x0)/Pci(0x1c,0x3)/Pci(0x0,0x0)/MAC(f48e38d7cb84,0)/IPv4(0.0.0.00.0.0.0,0,0)..BO
Boot0004  Onboard NIC (IPV6)    PciRoot(0x0)/Pci(0x1c,0x3)/Pci(0x0,0x0)/MAC(f48e38d7cb84,0)/IPv6([::]:<->[::]:,0,0)..BO
Boot0005  Linux Boot Manager    VenHw(99e275e7-75a0-4b37-a2e6-c5385e6c00cb)


============================= Drive/Partition Info =============================

Disks info: ____________________________________________________________________

nvme0n1 : notGPT,   no-BIOSboot,    has-noESP,  not-usb,    not-mmc, no-os, no-wind,    2048 sectors * 512 bytes

Partitions info (1/3): _________________________________________________________


Partitions info (2/3): _________________________________________________________


Partitions info (3/3): _________________________________________________________


fdisk -l (filtered): ___________________________________________________________

Disk nvme0n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk sdb: 29.84 GiB, 32015679488 bytes, 62530624 sectors
Disk identifier: 0x105b854a
      Boot   Start      End  Sectors  Size Id Type
sdb1  *          0  7547231  7547232  3.6G  0 Empty
sdb2        566648   574647     8000  3.9M ef EFI (FAT-12/16/32)
sdb3       7548928 62530623 54981696 26.2G 83 Linux

parted -lm (filtered): _________________________________________________________

sdb:32.0GB:scsi:512:512:unknown:SanDisk Cruzer Fit:;
nvme0n1:500GB:nvme:512:512:loop:CT500P3SSD8:;
1:0.00B:500GB:500GB:ext4::;

blkid (filtered): ______________________________________________________________

NAME    FSTYPE   UUID                                 PARTUUID                             LABEL                    PARTLABEL
sdb     iso9660  2022-08-31-07-21-46-00                                                    Ubuntu 20.04.5 LTS amd64 
├─sdb1  iso9660  2022-08-31-07-21-46-00               105b854a-01                          Ubuntu 20.04.5 LTS amd64 
├─sdb2  vfat     54C5-9C6C                            105b854a-02                                                   
└─sdb3  ext4     e3949b82-bd59-4957-adf1-c8320d7dd2cc 105b854a-03                          writable                 
nvme0n1 ext4     3cfa2ac8-eb84-4a94-9eae-ef4957bdeeba                                                               

Mount points (filtered): _______________________________________________________

                                                               Avail Use% Mounted on
/dev/disk/by-label/writable[/install-logs-2023-01-13.0/crash]  24.3G   0% /var/crash
/dev/disk/by-label/writable[/install-logs-2023-01-13.0/log]    24.3G   0% /var/log
/dev/nvme0n1                                                  178.6G  56% /media/ubuntu/3cfa2ac8-eb84-4a94-9eae-ef4957bdeeba
/dev/sdb1                                                          0 100% /cdrom

Mount options (filtered): ______________________________________________________


==================== nvme0n1/boot/grub/grub.cfg (filtered) =====================

Ubuntu   3cfa2ac8-eb84-4a94-9eae-ef4957bdeeba
Ubuntu, with Linux 5.15.0-57-generic   3cfa2ac8-eb84-4a94-9eae-ef4957bdeeba
Ubuntu, with Linux 5.15.0-56-generic   3cfa2ac8-eb84-4a94-9eae-ef4957bdeeba
Ubuntu 22.04 LTS (22.04) (on sdc2)   6c923416-303e-4ddb-8a4a-634146d057ef
Ubuntu (on sdc2)   6c923416-303e-4ddb-8a4a-634146d057ef
Ubuntu, with Linux 5.15.0-41-generic (on sdc2)   6c923416-303e-4ddb-8a4a-634146d057ef
Ubuntu, with Linux 5.15.0-40-generic (on sdc2)   6c923416-303e-4ddb-8a4a-634146d057ef
### END /etc/grub.d/30_os-prober ###
UEFI Firmware Settings   uefi-firmware
### END /etc/grub.d/30_uefi-firmware ###

========================= nvme0n1/etc/fstab (filtered) =========================

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1 during installation
UUID=3cfa2ac8-eb84-4a94-9eae-ef4957bdeeba /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=BA32-17B7  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0

===================== nvme0n1/etc/default/grub (filtered) ======================

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

================== nvme0n1: Location of files loaded by Grub ===================

           GiB - GB             File                                 Fragment(s)
 293.740905762 = 315.401895936  boot/grub/grub.cfg                             1
 324.292003632 = 348.205887488  boot/vmlinuz                                   2
 220.424819946 = 236.679348224  boot/vmlinuz-5.15.0-56-generic                 1
 324.292003632 = 348.205887488  boot/vmlinuz-5.15.0-57-generic                 2
 220.424819946 = 236.679348224  boot/vmlinuz.old                               1
 257.949718475 = 276.971401216  boot/initrd.img                                1
 259.574714661 = 278.716227584  boot/initrd.img-5.15.0-56-generic              1
 257.949718475 = 276.971401216  boot/initrd.img-5.15.0-57-generic              1
 259.574714661 = 278.716227584  boot/initrd.img.old                            1

==================== nvme0n1: ls -l /etc/grub.d/ (filtered) ====================

-rwxr-xr-x 1 root root 18683 Apr 15  2022 10_linux
-rwxr-xr-x 1 root root 43031 Apr 15  2022 10_linux_zfs
-rwxr-xr-x 1 root root 14180 Apr 15  2022 20_linux_xen
-rwxr-xr-x 1 root root 13369 Apr 15  2022 30_os-prober
-rwxr-xr-x 1 root root  1372 Apr 15  2022 30_uefi-firmware
-rwxr-xr-x 1 root root   700 Feb 19  2022 35_fwupd
-rwxr-xr-x 1 root root   214 Apr 15  2022 40_custom
-rwxr-xr-x 1 root root   215 Apr 15  2022 41_custom

======================== Unknown MBRs/Boot Sectors/etc =========================

Unknown BootLoader on sdb




Suggested repair: ______________________________________________________________

The default repair of the Boot-Repair utility would not act on the boot.

sudo nixos-rebuild --install-bootloader switch

[klequis@nixos:~]$ sudo nixos-rebuild --install-bootloader switch
building Nix…
building the system configuration…
Copied “/nix/store/sf1qmjj1im2xnmdvcpghq2h5b06z5rz2-systemd-251.7/lib/systemd/boot/efi/systemd-bootx64.efi” to “/boot/efi/EFI/systemd/systemd-bootx64.efi”.
Copied “/nix/store/sf1qmjj1im2xnmdvcpghq2h5b06z5rz2-systemd-251.7/lib/systemd/boot/efi/systemd-bootx64.efi” to “/boot/efi/EFI/BOOT/BOOTX64.EFI”.
Random seed file /boot/efi/loader/random-seed successfully written (32 bytes).
Created EFI boot entry “Linux Boot Manager”.
activating the configuration…
setting up /etc…
reloading user units for klequis…
setting up tmpfiles

  • You enabled systemd-boot, not grub, so the grub-specific options in your config aren’t doing anything.
  • What’s actually set to be mounted on /boot/efi in your hardware-configuration.nix?
  • In case you were unaware, nixos expects, and indeed needs, full control over its bootloader. You can reasonably implement switching by using your firmware as a first-layer boot switch, given that you have 2 physical drives, but setting up something smarter than that is going to be a bit of a challenge.
1 Like

Good to know

I have tried all bios boot options, some don’t work and one boots to NixOS. I’m thinking I should try to reinstall GRUB on the disk that has Ubuntu.

Contents of hardware-configuration.nix

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sr_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/86dd7f75-da43-4f98-97df-296dc4b39336";
      fsType = "ext4";
    };

  fileSystems."/boot/efi" =
    { device = "/dev/disk/by-uuid/7948-E566";
      fsType = "vfat";
    };

  swapDevices = [ ];
 
  networking.useDHCP = lib.mkDefault true;
  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
  hardware.video.hidpi.enable = lib.mkDefault true;
}

Using the firmware to switch works and is good enough while I’m learning about NixOS.

I also see what happened now. The GRUB boot partition was on the hdd that I installed NixOS to and it got erased. The hdd with the Ubuntu install I was using daily had no boot partition. That explains why I couldn’t boot into Ubuntu after installing NixOS.