# Installing NixOS on a new drive

**URL:** https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532
**Category:** Help
**Created:** [April 16, 2024, 7:27pm UTC](https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532 "2024-04-16T19:27:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![asheshambasta](https://discourse.nixos.org/user_avatar/discourse.nixos.org/asheshambasta/32/11267_2.png) [@asheshambasta](https://discourse.nixos.org/u/asheshambasta)
#### Post date: [April 16, 2024, 7:27pm UTC](https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532/1 "2024-04-16T19:27:24Z")

</div>

Previously, my system had two physical drives, and I had `/` and `/home` mounted on each of them.

The user profile was managed by `home-manager` (using the NixOS module).

Since my `/` was getting too full, I purchased a new drive and started moving the system to it. Install was pretty straightforward:

- Partition the new drive (GPT): create two partitions, `fat32` for boot and a filesystem of choice for `/`.
- Mount the partitions under `/mnt/new/boot` and `/mnt/new` respectively.
- Copy over `/etc/nixos` to the new drive.
- `nixos-generate-config` on the new drive.
- Add `/boot` to the `hardware-configuration.nix` on the new drive.
- `nixos-install --root /mnt/new`

All of this worked as expected, however, I now see there are some issues.

My `/home` contains symlinks like these:

```auto
lrwxrwxrwx 1 ashesh users 45 Jun 22 2019 /home/ashesh/.nix-profile -> /nix/var/nix/profiles/per-user/ashesh/profile

```

and I’m not sure how to migrate these to the new installation.  
I’ve so far found no guides on this and any suggestions will be very helpful. I thought I can just copy over `/nix/var/nix/profiles` to the new disk but I’m not even sure that’s safe.

How should I proceed?

* * *

Edit: [This post](https://lobste.rs/s/vgtgc2/migrating_primary_drive_on_nixos) even talks about copying over a few directories from `/var/lib`.

---

<div class="post-metadata">

### Author: ![rhendric](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rhendric/32/5699_2.png) [@rhendric](https://discourse.nixos.org/u/rhendric)
#### Post date: [April 16, 2024, 7:52pm UTC](https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532/2 "2024-04-16T19:52:11Z")

</div>

The .nix-profile link is managed by Nix. You don’t need to copy it over; it’ll get recreated when your user profile is activated in your new installation.

If you have other links pointing to locations under `/nix/store`, those will be recreated by Home Manager and you don’t need to worry about them either.

---

<div class="post-metadata">

### Author: ![asheshambasta](https://discourse.nixos.org/user_avatar/discourse.nixos.org/asheshambasta/32/11267_2.png) [@asheshambasta](https://discourse.nixos.org/u/asheshambasta)
#### Post date: [April 16, 2024, 8:11pm UTC](https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532/3 "2024-04-16T20:11:47Z")

</div>

That involves having `/home` mounted and doing `nixos-rebuild`, correct?

---

<div class="post-metadata">

### Author: ![rhendric](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rhendric/32/5699_2.png) [@rhendric](https://discourse.nixos.org/u/rhendric)
#### Post date: [April 16, 2024, 8:33pm UTC](https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532/4 "2024-04-16T20:33:44Z")

</div>

Depending on your configuration it might not exist until you install Home Manager, and I don’t actually know if there’s a difference here between installing Home Manager as a module versus using the standalone installation instructions. Ultimately Nix will create what it needs, and we can largely remain ignorant of the details.

---

<div class="post-metadata">

### Author: ![asheshambasta](https://discourse.nixos.org/user_avatar/discourse.nixos.org/asheshambasta/32/11267_2.png) [@asheshambasta](https://discourse.nixos.org/u/asheshambasta)
#### Post date: [April 17, 2024, 12:56pm UTC](https://discourse.nixos.org/t/installing-nixos-on-a-new-drive/43532/5 "2024-04-17T12:56:22Z")

</div>

So, in the end, this turned out to be slightly nontrivial.

I had to also generate the directory as indicated [here](https://discourse.nixos.org/t/per-user-profiles-not-created-when-home-mounted-on-nfs/5864/2) and then `chown` it as my user.

Things worked flawlessly afterward.

* * *

Steps:

1. Install new drive into the system.
2. Create a GPT partition table, with at least two partitions. A `fat32` `boot` partition (labelled `boot-new`) and a `root` partition (labelled `root-new`) with a filesystem of your choice.
3. Ensure the `boot` flag is set on the `boot` partition (without it, in my experience, `nixos-install` wasn’t installing the bootloader).
4. Create a new directory for the installation, say `/mnt/new`.
5. Mount partitions:

```auto
mount /dev/disk/by-label/root-new /mnt/new && \
mkdir /mnt/new/boot && \
mount /dev/disk/by-label/boot-new /mnt/new/boot

```

1. `mkdir /mnt/new/etc && cp -r /etc/nixos /mnt/new/etc/`
2. `cd /mnt/new`
3. `nixos-generate-config` and adjust values in `filesystems`
4. `nixos-install --root /mnt/new`

This should install NixOS on the new drive. Once done, reboot and select the new drive from the boot order in BIOS.

Once booted as `su`, do,

1. `mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/$USER` where `$USER` is your username.
2. `chown -R $USER /nix/var/nix/{profiles,gcroots}/per-user/$USER`
3. `nixos-rebuild switch`

* * *

As usual, with some software, reproducibility goes out of the window. I needed to re-instantiate `nextcloud-client` and `gnome-keyring`. Trivial, but doesn’t work out of the box.
