# Install NixOS from existing Linux

**URL:** https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856
**Category:** Help
**Created:** [April 24, 2020, 10:44am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856 "2020-04-24T10:44:42Z")
**Posts on this page:** 11
**Page:** 2

<div class="post-metadata">

### Author: ![akiross](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akiross/32/2292_2.png) [@akiross](https://discourse.nixos.org/u/akiross)
#### Post date: [May 15, 2020, 10:52pm UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/22 "2020-05-15T22:52:41Z")

</div>

Hi,  
thanks for the tips, but I still have some doubts.

I tried installing NixOS from liveusb but failed, so I’m trying to install it to another partition side-to-side with my current installation (Fedora 31).

My major problem is that I’m not sure how to mount the boot partitions (EFI system, GPT). In the current Fedora installation, the situation is this:

- /dev/sda1 mounted in /boot/efi
- /dev/sda2 mounted in /boot
- /dev/sda3 is a LVM physical volume with 3 logical volumes:
- /dev/VolumeGroup/swap
- /dev/VolumeGroup/root mounted to / in fedora
- /dev/VolumeGroup/nixos that should be mounted as / in nixos

The objective is to have nixos and fedora side-to-side, selectable in GRUB.

I prepared the /dev/VolumeGroup/nixos partition, but I’m not sure if I should mount the boot partitions as fedora is doing or not. Before installing, should I run

```
# mount /dev/VolumeGroup/nixos /mnt
# mount /dev/sda2 /mnt/boot
# mount /dev/sda1 /mnt/boot/efi

```

or should I run

```
# mount /dev/VolumeGroup/nixos /mnt
# mount /dev/sda1 /mnt/boot

```

Which one? I don’t know what the installer would do, so I can’t chose and I would like to get it right and not break the current system.

Also, I am not sure about the GRUB configuration. My current setup is:

```
  boot.loader.grub.useOSProber = true;

```

but I’m unsure if this is enough or I should have explicitly

```
 boot.loader.grub.extraEntries = ''
   menuentry "Fedora" {
     search --set=fedora --fs-uid dm-name-VolumeGroup-root
     configfile "($fedora)/boot/grub/grub.cfg"
   }
 '';

```

How should I proceed?  
Thank you very much

---

<div class="post-metadata">

### Author: ![mjlbach](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mjlbach/32/2063_2.png) [@mjlbach](https://discourse.nixos.org/u/mjlbach)
#### Post date: [May 16, 2020, 12:07am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/23 "2020-05-16T00:07:28Z")

</div>

@akiross I have (almost) the exact same setup (on lvm). This is the pertinent component of my configuration.nix:

```auto
{ config, pkgs, ... }:
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = false;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.efi.efiSysMountPoint = "/boot/efi"; #This is the most important line
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "nodev";
  boot.loader.grub.efiSupport = true;
  boot.loader.grub.useOSProber = false;
  boot.supportedFilesystems = ["ntfs"];
  boot.loader.grub.extraEntries = ''
	menuentry "Windows Boot Manager (on /dev/nvme0n1p2)" --class windows --class os {
		insmod part_gpt
		insmod fat
		search --no-floppy --fs-uuid --set=root 40E2-A3BF
		chainloader /EFI/Microsoft/Boot/bootmgfw.efi
	}

	menuentry "Fedora" --class fedora --class os {
		insmod part_gpt
		insmod ext2
		insmod fat
		search --no-floppy --fs-uuid --set=root 40E2-A3BF
		chainloader /EFI/fedora/grubx64.efi
	}
'';

}

```

And my hardware-configuration.nix:

```auto
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, ... }:

{
  imports =
    [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
    ];

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

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/3244183c-5adf-47c9-8b20-6be2d3f45502";
      fsType = "ext4";
    };

  fileSystems."/home" =
    { device = "/dev/disk/by-uuid/b792912b-943e-48d4-a2ff-c716ef4123fc";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/d391084d-b279-4b51-a8ab-7ee9883d6b7d";
      fsType = "ext4";
    };

  fileSystems."/boot/efi" =
    { device = "/dev/disk/by-uuid/40E2-A3BF";
      fsType = "vfat";
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/daddec15-1691-4efc-b783-9d683b44a05c"; }
    ];

  nix.maxJobs = lib.mkDefault 8;
  powerManagement.cpuFreqGovernor = lib.mkDefault "performance";
}

```

The confusing part is Fedora on UEFI has two partitions mounted under boot, one for the EFI images that should be mounted at /boot/efi (where Fedora’ grub is contained in /boot/efi/EFI/fedora/grubx64.cfg) and one partition for /boot which contains the kernel. T

The above should allow the system to boot. Change your uuid’s of course (include --root in the grub override). Note, this chainload’s Fedora’s grub, so you’ll be forwarded from the nix grub into fedora grub. I find this is more robust (although if anyone’s gotten auto-updating fedora kernels in nix grub please let me know.

See also: [NixOS managed grub not detecting another distribution (Fedora)](https://discourse.nixos.org/t/nixos-managed-grub-not-detecting-another-distribution-fedora/5777)

---

<div class="post-metadata">

### Author: ![akiross](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akiross/32/2292_2.png) [@akiross](https://discourse.nixos.org/u/akiross)
#### Post date: [May 18, 2020, 7:49am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/24 "2020-05-18T07:49:03Z")

</div>

Hello @mjlbach and thanks for your help!

Your configuration has been useful, but I did something wrong because I am unable to use GRUB to start the Fedora system.

The current status is:

1. power on
2. grub showing
3. fedora entries won’t work
4. nixos entry work

NixOS is the default UEFI boot entry, so it will start, leading to grub, but I can still start Fedora via the UEFI boot menu - not grub.

I tried these configurations:

```auto
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  boot.loader.systemd-boot.enable = false;
  boot.loader.efi.canTouchEfiVariables = true; 
  boot.loader.efi.efiSysMountPoint = "/boot/efi";
  boot.loader.grub.device = "nodev"; # do not install grub, just add entries
  boot.loader.grub.efiSupport = true; # build grub with efi support, default false
  boot.loader.grub.useOSProber = false;
  boot.loader.grub.extraEntries = ''
    menuentry "Fedora ONE" {
        search --set=boot --fs-uid 8FBB-25E7
        configfile "($boot)/EFI/fedora/grub.cfg"
    }

    menuentry "Fedora TWO" --class fedora --class os {
        insmod part_gpt
        insmod ext2
        insmod fat
        search --no-floppy --fs-uuid --set=root 65176797-2614-4b29-be42-a529e26013b0
        search --no-floppy --fs-uuid --set=boot 8FBB-25E7
        chainloader ($boot)/EFI/fedora/grubx64.efi
    }
  '';

```

```auto
{ config, lib, pkgs, ... }:
 
{
  imports =
    [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
    ];
 
  boot.initrd.availableKernelModules = ["ahci" "nvme" "rtsx_pci_sdmmc"];
  boot.initrd.kernelModules = ["dm-snapshot"];
  boot.kernelModules = ["kvm-intel"];
  boot.extraModulePackages = [];
 
  fileSystems."/" =
    { device = "/dev/disk/by-uuid/517592fb-a3a5-4338-9bd3-e1fcbc005c1e";
      fsType = "ext4";
    };
 
  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/65176797-2614-4b29-be42-a529e26013b0";
      fsType = "ext4";
    };
 
  fileSystems."/boot/efi" =
    { device = "/dev/disk/by-uuid/8FBB-25E7";
      fsType = "vfat";
    };
 
  swapDevices =
    [ { device = "/dev/disk/by-uuid/3db6a809-03c2-4d96-b870-51d6924581aa"; }
    ];
 
  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  # High-DPI console
  console.font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-u28n.psf.gz";
}

```

I added 2 entries just to see the various results.

In the first case, “Fedora ONE” (configfile), the system just reboots,  
while in the second case “Fedora TWO” (chainloader), I get a `grub> ` prompt, but I couldn’t manage to use it.

Not sure how to fix this, even if I _can_ boot, so it’s not really a problem.

---

<div class="post-metadata">

### Author: ![mjlbach](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mjlbach/32/2063_2.png) [@mjlbach](https://discourse.nixos.org/u/mjlbach)
#### Post date: [May 18, 2020, 7:55am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/25 "2020-05-18T07:55:44Z")

</div>

Did you try in your first config this:

```auto
	menuentry "Fedora" --class fedora --class os {
		insmod part_gpt
		insmod ext2
		insmod fat
		search --no-floppy --fs-uuid --set=root 8FBB-25E7
		chainloader /EFI/fedora/grubx64.efi
	}

```

Also can you confirm that grubx64.efi is located at /EFI/fedora/grubx64.efi when 8FBB-25E7 is mounted?

---

<div class="post-metadata">

### Author: ![mjlbach](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mjlbach/32/2063_2.png) [@mjlbach](https://discourse.nixos.org/u/mjlbach)
#### Post date: [May 18, 2020, 7:56am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/26 "2020-05-18T07:56:25Z")

</div>

> [@akiross](#):
>
> `boot.loader.grub.device = "nodev"; `

You may need to not set boot.loader.grub.device = “nodev”;

Before I got it working, I also had the issue where selecting fedora would trigger a restart.

---

<div class="post-metadata">

### Author: ![akiross](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akiross/32/2292_2.png) [@akiross](https://discourse.nixos.org/u/akiross)
#### Post date: [May 18, 2020, 8:37am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/27 "2020-05-18T08:37:08Z")

</div>

Yes, I also tried that, but without prefixing `($root)` to the chainload path I get a not found error.

Regarding the nodev: what’s the point of it? I get that `nodev` will change grub config, without installing grub. From my understanding, grub is already there due to fedora installation, so nix is updating the config but the grub I see is the one from fedora, so I don’t really need to unset `nodev`.  
This being said, unsetting it will probably reinstall it over the existing one, which is not really a problem.

Is that correct?

Now, I thought I might try with no grub altogether, so I’ll just use the UEFI boot menu instead 🙂  
Not really a fix, but still good for me.

---

<div class="post-metadata">

### Author: ![nrbray](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nrbray/32/8264_2.png) [@nrbray](https://discourse.nixos.org/u/nrbray)
#### Post date: [January 8, 2023, 9:53pm UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/28 "2023-01-08T21:53:39Z")

</div>

@wmertens May I ask if you could help me? I’d like to try your technique but I’ve not worked out how to get the install scripts…

Background is that the NixOS .iso’s using dd will not boot on my Thinkpad X1 Tablet 2nd gen. Ubuntu ones and others do… and I’ve done it 100s of times before so that’s odd.

---

<div class="post-metadata">

### Author: ![Mic92](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mic92/32/5265_2.png) [@Mic92](https://discourse.nixos.org/u/Mic92)
#### Post date: [January 9, 2023, 1:15pm UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/29 "2023-01-09T13:15:16Z")

</div>

Our approach is currently to just use kexec to boot into a proper nixos using this [tool](https://github.com/numtide/nixos-remote/)

---

<div class="post-metadata">

### Author: ![wmertens](https://discourse.nixos.org/user_avatar/discourse.nixos.org/wmertens/32/53_2.png) [@wmertens](https://discourse.nixos.org/u/wmertens)
#### Post date: [February 9, 2023, 10:36am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/30 "2023-02-09T10:36:57Z")

</div>

Sorry for missing this! If the ISO doesn’t work that’s definitely an issue that should be tracked. In any case, the kexec approach works well. It’s reasonably straightforward, you first pass it the command line arguments and then you tell it to switch, at which point it instantly loads the kernel and it’s as if you booted regularly.

---

<div class="post-metadata">

### Author: ![nrbray](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nrbray/32/8264_2.png) [@nrbray](https://discourse.nixos.org/u/nrbray)
#### Post date: [January 19, 2024, 11:58am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/31 "2024-01-19T11:58:17Z")

</div>

This thread was a great help to me. I think nixos-remote and [Colmena](https://github.com/zhaofengli/colmena) are on my list to learn more, what I have done to get me going on bare metal is this:

> **[GitHub - nrbray/nixos-configuration](https://github.com/nrbray/nixos-configuration)**
>
> Contribute to nrbray/nixos-configuration development by creating an account on GitHub.

However, for someone new to Nix but familiar with an existing distribution and happy their hardware-configuration might like to start installing their known linux and install NixOS from there.

---

<div class="post-metadata">

### Author: ![primeid](https://discourse.nixos.org/user_avatar/discourse.nixos.org/primeid/32/11202_2.png) [@primeid](https://discourse.nixos.org/u/primeid)
#### Post date: [January 21, 2024, 8:05am UTC](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856/32 "2024-01-21T08:05:47Z")

</div>

Has someone had success using [nixos-infect](https://github.com/elitak/nixos-infect/tree/master) script or fork of it to install Nixos from a Asahi Apple Silicon install?

[Previous page](https://discourse.nixos.org/t/install-nixos-from-existing-linux/6856.md?page=1)
