NixOS Installation Guide/zh: Difference between revisions
No edit summary Tags: Mobile edit Mobile web edit |
No edit summary |
||
| (31 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
<languages/> | |||
本指南是官方手册 [https://nixos.org/nixos/manual/index.html#ch-installation] 的配套指南。它描述了如何将 [[Special:MyLanguage/NixOS|NixOS]] 安装为完整的操作系统。有关在现有操作系统中安装 [[Special:MyLanguage/Nix|Nix]] 的说明,请参阅 [[Special:MyLanguage/Nix Installation Guide|Nix 安装指南]]。 | |||
除了 | 除了涵盖官方手册中的步骤外,它还提供了针对常见用例的已知有效操作。当官方手册与本指南之间存在差异时,支持用例以手册中描述的为准。 | ||
<span id="Installation_target"></span> | <span id="Installation_target"></span> | ||
| Line 45: | Line 44: | ||
==== 在macOS上 ==== | ==== 在macOS上 ==== | ||
# 使用<code>diskutil list</code>找到正确的设备, 比如说<code><i>diskX</i></code>. | |||
# | # 使用<code>diskutil unmountDisk <i>diskX</i></code>取消挂载. | ||
# | # 使用<code>sudo dd if=<b>path_to_nixos.iso</b> of=/dev/<i>diskX</i></code>进行刻录 | ||
# | |||
{{tip|使用<code>rdiskX</code>而不是<code>diskX</code>可以大幅改变速度. 你可以在另一个终端里使用<code>iostat 2</code>检查写入速度.}} | |||
{{tip| | |||
<span id="From_Windows"></span> | <span id="From_Windows"></span> | ||
==== 在Windows上==== | ==== 在Windows上==== | ||
# 下载USBwriter. | |||
# | # 启动USBwriter. | ||
# | # 选择下载的ISO文件作为'Source' | ||
# | # 选择USB驱动器作为'Target' | ||
# | # 点击'Write' | ||
# | # 当USBWriter完成写入操作后, 安全拔出USB驱动器 | ||
# | |||
<span id="Alternative_installation_media_instructions"></span> | <span id="Alternative_installation_media_instructions"></span> | ||
| Line 74: | Line 67: | ||
这些方式也同样有记录, 它们可以使用USB驱动器启动多个发行版. 这种方式不被支持, 结果可能因人而异. | 这些方式也同样有记录, 它们可以使用USB驱动器启动多个发行版. 这种方式不被支持, 结果可能因人而异. | ||
* [[NixOS_Installation_Guide/Unetbootin|使用 Unetbootin]] | |||
* [[NixOS_Installation_Guide/Unetbootin| | * [[NixOS_Installation_Guide/Manual USB Creation|手动 USB 创建]] | ||
* [[NixOS_Installation_Guide/Manual USB Creation| | |||
* [[NixOS_Installation_Guide/multibootusb|multibootusb]] | * [[NixOS_Installation_Guide/multibootusb|multibootusb]] | ||
== 启动(Boot)安装媒介 == | == 启动(Boot)安装媒介 == | ||
{{expansion|Troubleshooting steps, and details are lacking.}} | {{expansion|Troubleshooting steps, and details are lacking.}} | ||
由于安装镜像为混合镜像,因此可在传统 BIOS 模式或 [[Special:MyLanguage/UEFI|UEFI]] 模式下启动。 | |||
无论使用哪种方式启动安装媒介, 你可能需要修改主板或者电脑的配置, 以允许从光盘驱动器(对于CD/DVD)或者从一个外部的USB驱动器启动. | 无论使用哪种方式启动安装媒介, 你可能需要修改主板或者电脑的配置, 以允许从光盘驱动器(对于CD/DVD)或者从一个外部的USB驱动器启动. | ||
| Line 108: | Line 99: | ||
<span id="Tethered_(Internet_Sharing)"></span> | <span id="Tethered_(Internet_Sharing)"></span> | ||
== | ==有线连接(网络共享)== | ||
如果你无法通过网线或者wifi连接到网络, 你可以使用智能手机的网络共享能力. 依赖于你的手机的能力, 只需要内核自带的驱动就可以提供有效的网络连接. | 如果你无法通过网线或者wifi连接到网络, 你可以使用智能手机的网络共享能力. 依赖于你的手机的能力, 只需要内核自带的驱动就可以提供有效的网络连接. | ||
| Line 115: | Line 106: | ||
=== 无线网络 === | === 无线网络 === | ||
[[Special:MyLanguage/NetworkManager|NetworkManager]] 安装在图形化 ISO 镜像上,这意味着可以在命令行上使用 <code>nmtui</code> 命令连接到网络。 | |||
使用左上方的"Applications(应用)"标签页或者在底部的启动栏, 打开一个终端应用, 在那里启动 <code>nmtui</code>. 这可以让你'activate(激活)'一个(无线)连接 - 你应该可以在列表里看到你那里的SSID(无线网络名称), 除此之外你还可以添加一个新的连接. 当无线连接处于活动状态, 并且你已经测试过了时, 一开始就启动的安装程序很可能还没有检测到新的连接. 关掉安装程序, 再重新从屏幕底部的启动栏打开它. 这时它应该会检测到新的网络连接而继续. | 使用左上方的"Applications(应用)"标签页或者在底部的启动栏, 打开一个终端应用, 在那里启动 <code>nmtui</code>. 这可以让你'activate(激活)'一个(无线)连接 - 你应该可以在列表里看到你那里的SSID(无线网络名称), 除此之外你还可以添加一个新的连接. 当无线连接处于活动状态, 并且你已经测试过了时, 一开始就启动的安装程序很可能还没有检测到新的连接. 关掉安装程序, 再重新从屏幕底部的启动栏打开它. 这时它应该会检测到新的网络连接而继续. | ||
在最小化 | 在最小化 ISO 镜像上,或者您更熟悉 [[Special:MyLanguage/wpa_supplicant|wpa_supplicant]],那么您也可以运行 <code>wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf</code> 命令,然后输入您的密码并执行 <code>systemctl restart wpa_supplicant</code> 命令。 | ||
<span id="Partitioning"></span> | <span id="Partitioning"></span> | ||
== Partitioning(分区操作) == | == Partitioning(分区操作) == | ||
要对持久存储进行分区,请运行 <code>sudo fdisk /dev/diskX</code> 并按照 MBR 或 (U)EFI 的说明进行操作。要确定您使用的启动模式,请运行: | |||
= | <syntaxhighlight lang="console"> | ||
$ [ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy" | |||
</syntaxhighlight> | |||
< | 这里给出了一个非常简单的示例设置。 | ||
* o (dos | |||
<span id="Legacy_Boot_(MBR)"></span> | |||
=== 传统启动(Legacy Boot, MBR)=== | |||
* o (dos硬盘标签) | |||
* n new | * n new | ||
* p primary (4 primary in total) | * p primary (4 primary in total) | ||
* 1 ( | * 1 (分区编号[1/4]) | ||
* 2048 first sector (alignment for performance) | * 2048 first sector (alignment for performance) | ||
* +500M last sector ( | * +500M last sector (引导扇区的大小) | ||
* rm signature (Y), if ex. => warning of overwriting existing system, could use wipefs | * rm signature (Y), if ex. => warning of overwriting existing system, could use wipefs | ||
* n | * n | ||
* p | * p | ||
* 2 | * 2 | ||
* default ( | * default (填满分区) | ||
* default ( | * default (填满分区) | ||
* w ( | * w (写入) | ||
=== UEFI === | === UEFI === | ||
| Line 160: | Line 155: | ||
* w (写入) | * w (写入) | ||
<span id=" | <span id="Format_partitions"></span> | ||
== | === 格式化分区 === | ||
这对于有多个分区设置的情况很有用, 使分区更容易处理<syntaxhighlight lang="console"> | 以下示例使用 [[Special:MyLanguage/ext4|ext4]] 文件系统格式。如果您希望使用其他文件系统格式,例如 [[Special:MyLanguage/Btrfs|Btrfs]] 或 [[Special:MyLanguage/ZFS|ZFS]]: | ||
$ lsblk | |||
* [[Special:MyLanguage/Bcachefs#NixOS installation on bcachefs|在 bcachefs 上安装 NixOS]] | |||
* [[Special:MyLanguage/Btrfs#Installation of NixOS on btrfs|在 btrfs 上安装 NixOS]] | |||
* [[Special:MyLanguage/LVM#Basic Setup|LVM 基础设置]] | |||
* [[Special:MyLanguage/ZFS#Simple NixOS ZFS on root installation|Simple NixOS ZFS on root installation]] | |||
这对于有多个分区设置的情况很有用, 使分区更容易处理 | |||
<syntaxhighlight lang="console"> | |||
$ lsblk # lists current system block devices | |||
# mkfs.fat -F 32 -n boot /dev/sdX1 | |||
# mkfs.ext4 /dev/sdX2 -L nixos | |||
# mount /dev/disk/by-label/nixos /mnt | |||
# mkdir -p /mnt/boot | |||
# mount /dev/disk/by-label/boot /mnt/boot | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== | <span id="NixOS_configuration"></span> | ||
== NixOS 配置 == | |||
NixOS 通过 [[Special:MyLanguage/Overview of the NixOS Linux distribution#Declarative Configuration|声明式配置]] 文件进行配置。要生成默认配置文件,请运行 [[Special:MyLanguage/nixos-generate-config]]: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# nixos-generate-config --root /mnt | |||
# nano /mnt/etc/nixos/configuration.nix | |||
</syntaxhighlight> | </syntaxhighlight> | ||
有关使用系统配置的信息,请参阅 [[Special:MyLanguage/NixOS system configuration|NixOS 系统配置]]。有关特定于桌面的配置,请参阅 [[Special:MyLanguage/NixOS as a desktop|桌面设备上的 NixOS]]。 | |||
最重要的变化: | |||
* | * 键盘布局(keyboard layout), 也就是 <code>[[Keyboard Layout Customization|services.xserver.xkb.layout]]</code> | ||
* [[networking|网络]] (wifi), 若出现问题, 请参阅下方的修复方法 | |||
* [[networking]] (wifi), | * 安装 [[:Category:Text Editor|编辑器]] 来编辑配置 | ||
* 安装编辑器来编辑配置 | |||
具有自我说明性的NixOS选项可以在[https://search.nixos.org/options NixOS选项搜索]上搜索到. | 具有自我说明性的NixOS选项可以在[https://search.nixos.org/options NixOS选项搜索]上搜索到. | ||
== NixOS安装 == | <span id="Swap_file"></span> | ||
== 交换文件 == | |||
有关配置交换空间的更多方法,请参阅 [[Swap]]。以下示例演示了如何创建和启用一个 [[Swap#Swap file|交换文件]]: | |||
{{file|/mnt/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
swapDevices = [{ | |||
device = "/var/lib/swapfile"; | |||
size = 16*1024; # 16 GB | |||
}]; | |||
</nowiki> | |||
}} | |||
<span id="Bootloader"></span> | |||
=== 引导加载程序 === | |||
NixOS 支持多种 [[Bootloader|引导加载程序]],例如 [[GNU GRUB]] 和 [[Systemd/boot]]。 | |||
Systemd-boot 是推荐的引导加载程序。以下示例演示了如何在配置中启用 systemd-boot: | |||
{{file|/mnt/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
boot.loader.systemd-boot.enable = true; | |||
</nowiki> | |||
}} | |||
您可能还希望配置 [[Secure Boot|安全启动]]。 | |||
<span id="Users"></span> | |||
=== 用户 === | |||
有关创建和管理用户的信息,请参阅 [[User management|用户管理]] 和 {{NixOS Manual|name=NixOS Manual: Chapter - Package Management|anchor=#sec-user-management}}。请参阅以下示例: | |||
{{file|/mnt/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
users.users.alice = { | |||
isNormalUser = true; | |||
initialPassword = "pw123"; | |||
}; | |||
</nowiki> | |||
}} | |||
<span id="NixOS_installation"></span> | |||
== 安装 NixOS == | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# cd /mnt | |||
# nixos-install | |||
</syntaxhighlight>安装 | </syntaxhighlight> | ||
安装后:运行<code>passwd</code>更改用户密码。 | |||
如果网络出现问题, 请尝试下面的一种方法: | |||
<syntaxhighlight lang="console"> | |||
# nixos-rebuild switch --option substitute false # no downloads | |||
# nixos-rebuild switch --option binary-caches "" # no downloads | |||
</syntaxhighlight> | </syntaxhighlight> | ||
* 设 | |||
* 设置 wpa_supplicant 标志来连接到 wifi | |||
<hr /> | <hr /> | ||
| Line 216: | Line 265: | ||
这些是有关特定硬件问题的收集到的说明或链接. | 这些是有关特定硬件问题的收集到的说明或链接. | ||
* 博客文章:如何在 [http://grahamc.com/blog/nixos-on-dell-9560 Dell 9560] 上安装 NixOS | |||
* | * 品牌服务器可能需要在 initrd 中包含额外的内核模块(在 configuration.nix 中配置 <code>boot.initrd.extraKernelModules</code>)。例如,HP Proliant 需要“hpsa”模块才能访问磁盘驱动器。 | ||
* | |||
[[Category:Guide|分类:指南]] | |||
[[Category:Guide]][[Category:Deployment]] | [[Category:Deployment|分类:开发]] | ||
[[Category:NixOS|分类:NixOS]] | |||