NixOS & Legacy Boot(MBR) VmwareWorkstation安装向导
目录
- NixOS & Legacy Boot(MBR) VmwareWorkstation安装向导
- 1. 下载镜像
- 2. 创建空白虚拟机
- 3. 使用命令行安装 NixOS
- 3.1 Legacy Boot(MBR)
- 3.2 格式化
- 4. configration.nix 配置文件
- 5. 部署NixOS
- 6. 部分教育站镜像源集合
- 参考资料
- ⚠️未解决的问题
1. 下载镜像
- NixOS 清华大学开源镜像站
- NixOS 官方
这里我选用GNOME版本作为安装演示ISO
2. 创建空白虚拟机
这里只演示需要修改的部分,其余不用修改的不做演示,直接下一步即可
- 新建虚拟机,选择自定义安装
- 选择稍后安装虚拟机
- 虚拟机版本选择
其他 Linux 5.x 内核
- 配置完成后,点击
编辑虚拟机设置
→ \rightarrow →使用ISO映像文件
3. 使用命令行安装 NixOS
启动虚拟机,来到安装引导界面
关闭 NixOS Installer,点击左上角的Activities,选择底部Dock栏的Console
这里由于 VmwarkStation 默认是使用BIOS 传统引导(Legacy Boot)MBR 方式启动,所以演示以 Legacy Boot(MBR) 为例子
3.1 Legacy Boot(MBR)
首先使用管理员身份登录
sudo su root
-
打开 /dev/sda 设备并进入 parted 命令行模式
parted /dev/sda
-
创建MBR分区表
(parted) mklabel msdos
-
创建一个新的主分区,从 1MB 开始,到倒数第 8GB 结束
(parted) mkpart primary 1MB -8GB
-
将第一个分区的启动标志设置为 on,表示这个分区是可引导的
(parted) set 1 boot on
-
创建一个新的主分区,类型为 linux-swap,从倒数第 8GB 开始,到最后结束
(parted) mkpart primary linux-swap -8GB 100%
-
退出
(parted) quit
3.2 格式化
-
在 /dev/sda1 上创建一个 ext4 文件系统,并将其标记为 nixos
mkfs.ext4 -L nixos /dev/sda1
-
创建一个新的交换分区,并将其标记为 swap
mkswap -L swap /dev/sda2
-
将 /dev/disk/by-label/nixos 挂载到 /mnt 目录下,使得该目录下的文件可以被访问
mount /dev/disk/by-label/nixos /mnt
-
将 /dev/sda2 上的交换分区打开
swapon /dev/sda2
-
在 /mnt 目录下生成 NixOS 的配置文件,该文件包含了 NixOS 的所有配置信息,包括系统的软件包、服务、用户等等
nixos-generate-config --root /mnt
-
编辑 /mnt/etc/nixos/configuration.nix以满足你的需要
vim /mnt/etc/nixos/configuration.nix
4. configration.nix 配置文件
configuration.nix
是 NixOS 系统的配置文件,它是一个声明式的配置文件,描述了整个系统的状态,包括应该安装哪些软件包以及各种系统设置和选项
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
# boot.loader.grub.efiSupport = true;
# boot.loader.grub.efiInstallAsRemovable = true;
# boot.loader.efi.efiSysMountPoint = "/boot/efi";
# Define on which hard drive you want to install Grub.
boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only
networking.hostName = "nixos"; # Define your hostname.
# Pick only one of the below networking options.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
# Set your time zone.
time.timeZone = "Asia/Shanghai";
# Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
# Select internationalisation properties.
i18n.defaultLocale = "en_US.UTF-8";
console = {
font = "Lat2-Terminus16";
# keyMap = "us";
useXkbConfig = true; # use xkbOptions in tty.
};
# Enable the X11 windowing system.
services.xserver.enable = true;
# Enable Vmware-Tools
virtualisation.vmware.guest.enable = true;
# Change Nix-Channel by TsingHua
nix.settings.substituters = [ "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" ];
# Enable the GNOME Desktop Environment.
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;
# Configure keymap in X11
services.xserver.layout = "us";
# services.xserver.xkbOptions = {
# "eurosign:e";
# "caps:escape" # map caps to escape.
# };
# Enable CUPS to print documents.
# services.printing.enable = true;
# Enable sound.
sound.enable = true;
# hardware.pulseaudio.enable = true;
# Enable touchpad support (enabled default in most desktopManager).
# services.xserver.libinput.enable = true;
# Define a user account. Don't forget to set a password with ‘passwd’.
# users.users.alice = {
# isNormalUser = true;
# extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
# packages = with pkgs; [
# firefox
# thunderbird
# ];
# };
# List packages installed in system profile. To search, run:
# $ nix search wget
environment.systemPackages = with pkgs; [
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
neofetch
openssh
bash-completion
rxvt-unicode
alacritty
parted
];
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
# programs.mtr.enable = true;
# programs.gnupg.agent = {
# enable = true;
# enableSSHSupport = true;
# };
# List services that you want to enable:
# Enable the OpenSSH daemon.
# services.openssh.enable = true;
# Open ports in the firewall.
# networking.firewall.allowedTCPPorts = [ ... ];
# networking.firewall.allowedUDPPorts = [ ... ];
# Or disable the firewall altogether.
networking.firewall.enable = false;
# Copy the NixOS configuration file and link it from the resulting system
# (/run/current-system/configuration.nix). This is useful in case you
# accidentally delete configuration.nix.
# system.copySystemConfiguration = true;
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. It‘s perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "22.11"; # Did you read the comment?
}
5. 部署NixOS
生成 configration.nix
配置文件后,由于网络原因
我们需要临时使用清华大学开源镜像站的Nix-channels配置
nixos-install --option substituters "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" -vv
但是有时候镜像不是很稳定,可以尝试其他的,这里以中国科学技术大学为例
nixos-install --option substituters https://mirrors.ustc.edu.cn/nix-channels/store
安装完成后,系统会提示你设置root账户的密码
setting root password...
New password: ***
Retype new password: ***
之后输入 reboot 重启 NixOS 即可
6. 部分教育站镜像源集合
- 中国科学技术大学Nix源使用帮助 | 个人觉得最稳定
- 清华大学开源镜像站 Nix Channels 镜像使用帮助 | 对一些Github的配置文件无法下载
- 上海交通大学nix-channels/store镜像源服务
参考资料
How to Install VMware Tools (Open VM Tools) in NixOS Linux 20.09
NixOS Installation Guide
从⑨开始的NixOS | 安装篇 --作者:农企中国
从⑨开始的NixOS | 安装篇 --特别补充 --作者:农企中国
⚠️未解决的问题
Vmware Tools 安装后无法根据显示器大小自适应缩放,已经在 NixOS Wiki 社区提问。Display scaling issue with VMware tools in NixOS