Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move /old-root/nixos to / #37

Closed
jakubpawlowicz opened this issue Aug 19, 2017 · 9 comments
Closed

Move /old-root/nixos to / #37

jakubpawlowicz opened this issue Aug 19, 2017 · 9 comments

Comments

@jakubpawlowicz
Copy link

Hey @jeaye!

First of all thanks for this project! It's the only way I've been able to bootstrap NixOS on my 11 year old laptop.

Now I have NixOS up and running I wonder if there's a way to move the install to root folder from /old-root/nixos. I don't need it badly but it would be nice to have it. Any ideas?

Thanks!

@jeaye
Copy link
Owner

jeaye commented Aug 19, 2017

Hey @jakubpawlowicz, it's great to hear that nixos-in-place has worked for you. What you're looking to do is both certainly possible and not officially supported by this project. With that said, I'll give you some info so on how nixos-in-place works so you can decide whether or not you want to go further.

On your old laptop, with NixOS now, you'll find that there is a file here /etc/nixos/nixos-in-place.nix that contains the automagically-generated config from your installation. Here's a snippet from mine, where my drive is /dev/vda1.

{
  boot.loader.grub.device = "/dev/vda";
  boot.loader.grub.storePath = "/nixos/nix/store";
  boot.initrd.supportedFilesystems = [ "ext4" ];
  boot.initrd.postDeviceCommands = ''
    mkdir -p /mnt-root/old-root ;
    mount -t ext4 /dev/vda1 /mnt-root/old-root ;
  '';
  fileSystems = {
    "/" = {
      device = "/old-root/nixos";
      fsType = "none";
      "options" = [ "bind" ];
    };
    "/old-root" = {
      device = "/dev/vda1";
      fsType = "ext4";
    };
  };
}

On some systems like with DigitalOcean, we need old-root to keep existing. In your case, it seems like you can likely do without. To give it a shot, I'd recommend using a live ISO of some GNU/Linux distro to boot up your machine. From there, mount your drive (on ./mnt, for example) and delete everything except for ./mnt/nixos. After that, move everything from within ./mnt/nixos/* to ./mnt and delete the empty ./mnt/nixos directory.

You should then be able to remove nixos-in-place.nix and make your config look much more like a normal NixOS setup. From there, you'd need to make sure GRUB is updated, so your kernel will be found on your next boot, since it's moved from /nixos/... to /....

This isn't the most thorough outline, since I haven't yet attempted this, but, if you follow through successfully, it'd be great to get your notes. I could then turn it into a wiki page.

Let me know if you have any other questions and best of luck. :) Closing this ticket, but feel free to keep discussing.

@jeaye jeaye closed this as completed Aug 19, 2017
@jakubpawlowicz
Copy link
Author

jakubpawlowicz commented Aug 20, 2017

Thanks @jeaye for more details. I've just did it and it seems to work fine, here's a step by step guide:

  1. Install NixOS via nixos-in-place and reboot into NixOS
  2. Change nixos-in-place.nix to use the following (you can also move what's left to other config files):
{
  boot.loader.grub.device = "/dev/vda";
  fileSystems = {
    "/" = {
      device = "/dev/vda";
      fsType = "ext4";
    };
  };
}
  1. Run nixos-rebuild boot so new paths are used
  2. Reboot
  3. Boot system from a live CD (I used CentOS 7)
  4. Run following commands via console
mkdir /mnt/root
mount /dev/vda1 /mnt/root
mv /mnt/root/nixos/* /mnt/root
rmdir /mnt/root/nixos
rmdir /mnt/root/old-root
  1. Reboot
  2. GRUB will complain that it can't find /nixos/boot/grub path, so in GRUB rescue mode type
ls
set prefix=(hd0,1)/boot/grub # use whatever disk you have your /boot/grub folder on
insmod normal
normal
  1. Select NixOS default and boot
  2. Login as root and run
grub-install /dev/vda

At this point I rebooted and everything runs fine.

Some questions:

  1. How to avoid steps 8-10?
  2. Can I run grub-install after step 3 to avoid 8-10?

@jeaye
Copy link
Owner

jeaye commented Aug 20, 2017

Awesome work and thanks for the update! I don't think you can run grub-install after step 3, but I think it should work fine after step 6. I'm thinking the new step 7 can be to chroot into mnt and run your grub-install. Then reboot.

Are you able to try that out?

@jakubpawlowicz
Copy link
Author

I tried chrooting with sth like chroot . nix/store/*-nixos-system*/init but I got the following message "Trying to run as user instance, but the system has not been booted with systemd." and backed out.

@jeaye
Copy link
Owner

jeaye commented Aug 20, 2017

Hm, I wonder if you can chroot in (into /nix/store/*-bash-4.3-*/bin/bash), skip the init, and run grub-install directly like /nix/store/*-grub-2.x-*/bin/grub-install.

@jakubpawlowicz
Copy link
Author

Hmmm, that's a good idea. I'll try it tomorrow.

@jakubpawlowicz
Copy link
Author

I've only had a chance to do it again now, but I can confirm that running the following commands after step 6 did the trick:

mount -t proc /proc /mnt/root/proc
mount -o bind /dev /mnt/root/dev
chroot /mnt/root nix/store/*-bash-*/bin/bash
/nix/store/*-grub-*/bin/grub-install /dev/vda

@jeaye
Copy link
Owner

jeaye commented Dec 21, 2017

Nice work! Thanks for the update.

@nh2
Copy link

nh2 commented Apr 16, 2018

@jakubpawlowicz Possibly also interesting for you: #41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants