2023-06-04 14:45:48 +00:00
|
|
|
|
# disko - Declarative disk partitioning
|
|
|
|
|
|
2023-06-05 08:23:08 +00:00
|
|
|
|
<img src="./logo.jpeg" title="" alt="Project logo" width="247">
|
2023-06-04 14:45:48 +00:00
|
|
|
|
|
|
|
|
|
[Documentation Index](./INDEX.md)
|
|
|
|
|
|
|
|
|
|
## Quickstart Guide
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
This tutorial describes how to install NixOS on a single disk system using
|
|
|
|
|
`disko`. You will also need to refer to the NixOS manual, which is available
|
|
|
|
|
[here.](https://nixos.org/manual/nixos/stable/index.html#ex-config)
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
Please note that `disko` will reformat the entire disk and overwrite any
|
|
|
|
|
existing partitions. Dual booting with other operating systems is not supported.
|
2023-02-03 12:27:21 +00:00
|
|
|
|
|
2023-06-04 14:45:48 +00:00
|
|
|
|
### Step 1: Choose a Disk Configuration
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
Configurations for the most common disk layouts are provided in the
|
|
|
|
|
[examples directory](https://github.com/nix-community/disko/tree/master/example)
|
|
|
|
|
of the `disko` repository. Decide which of these layouts best suits your
|
|
|
|
|
requirements. If you're not sure which layout to pick, use the
|
|
|
|
|
[hybrid](https://github.com/nix-community/disko/blob/master/example/hybrid.nix)
|
|
|
|
|
configuration. This layout is compatible with both BIOS and EFI systems.
|
2023-02-03 12:27:21 +00:00
|
|
|
|
|
2023-09-18 11:05:43 +00:00
|
|
|
|
Refer to the [reference manual](./reference.md) for more information about the
|
2023-09-15 05:56:40 +00:00
|
|
|
|
sample layouts and how to build your own configuration.
|
2023-06-04 14:29:45 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
Once you've chosen your layout, you'll need to make a note of the URL to the raw
|
|
|
|
|
file. To do this, open the file in Github. Immediately below the list of
|
|
|
|
|
contributors, you will see a button labelled 'RAW' near the right hand side.
|
|
|
|
|
Click this. The URL of the raw file will appear in the search bar of your
|
|
|
|
|
browser. It will look something like this:
|
2023-06-04 14:29:45 +00:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
https://raw.githubusercontent.com/nix-community/disko/master/example/hybrid.nix
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-04 14:45:48 +00:00
|
|
|
|
### Step 2: Boot the installer
|
2023-06-04 14:29:45 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
Download the NixOS ISO image from the NixOS
|
|
|
|
|
[download page](https://nixos.org/download.html#nixos-iso), and create a
|
|
|
|
|
bootable USB drive following the instructions
|
|
|
|
|
in [Section 2.4.1 "Booting from a USB flash drive"](https://nixos.org/manual/nixos/stable/index.html#sec-booting-from-usb) of
|
|
|
|
|
the NixOS manual. Boot the machine from this USB drive.
|
2023-06-04 14:29:45 +00:00
|
|
|
|
|
2023-06-04 14:45:48 +00:00
|
|
|
|
### Step 3: Retrieve the disk name
|
2023-06-04 14:29:45 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
Identify the name of your system disk by using the `lsblk` command as follows:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-12-21 15:50:48 +00:00
|
|
|
|
lsblk
|
2023-06-04 14:29:45 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The output from this command will look something like this:
|
|
|
|
|
|
|
|
|
|
```
|
2023-02-02 14:15:39 +00:00
|
|
|
|
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
|
|
|
|
|
nvme0n1 259:0 0 1,8T 0 disk
|
|
|
|
|
```
|
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
In this example, an empty NVME SSD with 2TB space is shown with the disk name
|
|
|
|
|
"nvme0n1". Make a note of the disk name as you will need it later.
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-06-04 14:45:48 +00:00
|
|
|
|
### Step 4: Copy the disk configuration to your machine
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
In Step 1, you chose a disk layout configuration from the
|
|
|
|
|
[examples directory](https://github.com/nix-community/disko/tree/master/example),
|
|
|
|
|
and made a note of its URL.
|
2023-02-03 12:27:21 +00:00
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
Your configuration needs to be saved on the new machine for example
|
2023-09-15 05:56:40 +00:00
|
|
|
|
as /tmp/disko-config.nix. You can do this using the `curl` command to download
|
|
|
|
|
from the url you noted above, using the `-o` option to save the file as
|
|
|
|
|
disko-config.nix. Your commands would look like this if you had chosen the
|
|
|
|
|
hybrid layout:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-06-04 14:29:45 +00:00
|
|
|
|
cd /tmp
|
2023-12-21 15:50:48 +00:00
|
|
|
|
curl https://raw.githubusercontent.com/nix-community/disko/master/example/hybrid.nix -o /tmp/disko-config.nix
|
2023-06-04 14:29:45 +00:00
|
|
|
|
```
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
### Step 5: Adjust the device in the disk configuration
|
2023-02-03 12:27:21 +00:00
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
Inside the disko-config.nix the device needs to point to the correct disk name.
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
Open the configuration in your favorite editor i.e.:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-10-27 10:17:09 +00:00
|
|
|
|
nano /tmp/disko-config.nix
|
2023-02-02 14:15:39 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
Replace `<disk-name>` with the name of your disk obtained in Step 1.
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-21 15:50:48 +00:00
|
|
|
|
```nix
|
|
|
|
|
# ...
|
|
|
|
|
main = {
|
|
|
|
|
type = "disk";
|
|
|
|
|
device = "<disk-name>";
|
|
|
|
|
content = {
|
|
|
|
|
type = "gpt";
|
|
|
|
|
# ...
|
2023-02-02 14:15:39 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
### Step 6: Run disko to partition, format and mount your disks
|
|
|
|
|
|
|
|
|
|
The following step will partition and format your disk, and mount it to `/mnt`.
|
|
|
|
|
|
|
|
|
|
**Please note: This will erase any existing data on your disk.**
|
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-12-21 15:50:48 +00:00
|
|
|
|
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disko-config.nix
|
2023-10-27 10:17:09 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
After the command has run, your file system should have been formatted and
|
|
|
|
|
mounted. You can verify this by running the following command:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-12-21 15:50:48 +00:00
|
|
|
|
mount | grep /mnt
|
2023-06-04 14:29:45 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The output should look like this if your disk name is `nvme0n1`.
|
|
|
|
|
|
|
|
|
|
```
|
2023-02-02 14:15:39 +00:00
|
|
|
|
/dev/nvme0n1p1 on /mnt type ext4 (rw,relatime,stripe=2)
|
|
|
|
|
/dev/nvme0n1p2 on /mnt/boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
|
|
|
|
|
```
|
|
|
|
|
|
2023-10-27 10:17:09 +00:00
|
|
|
|
### Step 7: Complete the NixOS installation.
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
Your disks have now been formatted and mounted, and you are ready to complete
|
|
|
|
|
the NixOS installation as described in the
|
|
|
|
|
[NixOS manual](https://nixos.org/manual/nixos/stable/index.html#sec-installation) -
|
|
|
|
|
see the section headed "**Installing**", Steps 3 onwards. However, you will need
|
|
|
|
|
to include the partitioning and formatting configurations that you copied into
|
|
|
|
|
`/tmp/disko-config.nix` in your configuration, rather than allowing NixOS to
|
|
|
|
|
generate information about your file systems. When you are configuring the
|
|
|
|
|
system as per Step 4 of the manual, you should:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
a) Include the `no-filesystems` switch when using the `nixos-generate-config`
|
|
|
|
|
command to generate an initial `configuration.nix`. You will be supplying the
|
|
|
|
|
file system configuration details from `disko-config.nix`. Your CLI command to
|
|
|
|
|
generate the configuration will be:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-12-21 15:50:48 +00:00
|
|
|
|
nixos-generate-config --no-filesystems --root /mnt
|
2023-02-02 14:15:39 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-06-04 14:29:45 +00:00
|
|
|
|
This will create the file `configuration.nix` in `/mnt/etc/nixos`.
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-06-04 14:29:45 +00:00
|
|
|
|
b) Move the `disko` configuration to /etc/nixos
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-12-21 15:50:48 +00:00
|
|
|
|
mv /tmp/disko-config.nix /mnt/etc/nixos
|
2023-02-02 14:15:39 +00:00
|
|
|
|
```
|
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
c) You can now edit `configuration.nix` as per your requirements. This is
|
|
|
|
|
described in Step 4 of the manual. For more information about configuring your
|
|
|
|
|
system, refer to the NixOS manual.
|
|
|
|
|
[Chapter 6, Configuration Syntax](https://nixos.org/manual/nixos/stable/index.html#sec-configuration-syntax)
|
|
|
|
|
describes the NixOS configuration syntax, and
|
|
|
|
|
[Appendix A, Configuration Options](https://nixos.org/manual/nixos/stable/options.html)
|
|
|
|
|
gives a list of available options. You can find also find a minimal example of a
|
|
|
|
|
NixOS configuration in the manual:
|
|
|
|
|
[Example: NixOS Configuration](https://nixos.org/manual/nixos/stable/index.html#ex-config).
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
d) When editing `configuration.nix`, you will need to add the `disko` NixOS
|
|
|
|
|
module and `disko-config.nix` to the imports section. This section will already
|
|
|
|
|
include the file `./hardware-configuration.nix`, and you can add the new entries
|
|
|
|
|
just below this. This section will now include:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-21 15:50:48 +00:00
|
|
|
|
```nix
|
2023-02-02 14:15:39 +00:00
|
|
|
|
imports =
|
|
|
|
|
[ # Include the results of the hardware scan.
|
|
|
|
|
./hardware-configuration.nix
|
|
|
|
|
"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix"
|
2023-10-27 10:17:09 +00:00
|
|
|
|
./disko-config.nix
|
2023-02-02 14:15:39 +00:00
|
|
|
|
];
|
|
|
|
|
```
|
|
|
|
|
|
2023-09-15 05:56:40 +00:00
|
|
|
|
e) If you chose the hybrid-partition scheme, then choose `grub` as a bootloader,
|
|
|
|
|
otherwise follow the recommendations in Step 4 of the **Installation** section
|
|
|
|
|
of the NixOS manual. The following configuration for `grub` works for both EFI
|
|
|
|
|
and BIOS systems. Add this to your configuration.nix, commenting out the
|
|
|
|
|
existing lines that configure `systemd-boot`. The entries will look like this:
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-10-19 09:42:20 +00:00
|
|
|
|
**Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko will
|
|
|
|
|
take care of that automatically.
|
|
|
|
|
|
2023-12-21 15:50:48 +00:00
|
|
|
|
```nix
|
2023-02-02 14:15:39 +00:00
|
|
|
|
# ...
|
|
|
|
|
#boot.loader.systemd-boot.enable = true;
|
|
|
|
|
#boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
|
boot.loader.grub.enable = true;
|
|
|
|
|
boot.loader.grub.efiSupport = true;
|
|
|
|
|
boot.loader.grub.efiInstallAsRemovable = true;
|
|
|
|
|
# ...
|
|
|
|
|
```
|
|
|
|
|
|
2023-06-04 14:29:45 +00:00
|
|
|
|
f) Finish the installation and reboot your machine,
|
2023-02-02 14:15:39 +00:00
|
|
|
|
|
2023-12-23 00:23:16 +00:00
|
|
|
|
```bash
|
2023-12-21 15:50:48 +00:00
|
|
|
|
nixos-install
|
|
|
|
|
reboot
|
2023-02-02 14:15:39 +00:00
|
|
|
|
```
|