From 0ccd6448d62b93c07ab2bdea4246bc0285b67500 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Aug 2021 11:15:31 -0400 Subject: [PATCH 1/5] NixOS AWS AMI: Set the console to 115200n8 See: * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking-os.html * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/grub.html --- nixos/modules/virtualisation/amazon-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index 26297a7d0f1f..ad105b96332e 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -49,7 +49,7 @@ in ]; boot.initrd.kernelModules = [ "xen-blkfront" "xen-netfront" ]; boot.initrd.availableKernelModules = [ "ixgbevf" "ena" "nvme" ]; - boot.kernelParams = mkIf cfg.hvm [ "console=ttyS0" "random.trust_cpu=on" ]; + boot.kernelParams = mkIf cfg.hvm [ "console=ttyS0,115200n8" "random.trust_cpu=on" ]; # Prevent the nouveau kernel module from being loaded, as it # interferes with the nvidia/nvidia-uvm modules needed for CUDA. From bfd2f800ee353a9f59360f56d647818eaef9f6b4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Aug 2021 11:20:30 -0400 Subject: [PATCH 2/5] NixOS AMI: Give grub a 1s timeout now that AWS has emergency console access. See: * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking-os.html * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/grub.html --- nixos/modules/virtualisation/amazon-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index ad105b96332e..6bdc661d9964 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -63,7 +63,7 @@ in boot.loader.grub.extraPerEntryConfig = mkIf (!cfg.hvm) "root (hd0)"; boot.loader.grub.efiSupport = cfg.efi; boot.loader.grub.efiInstallAsRemovable = cfg.efi; - boot.loader.timeout = 0; + boot.loader.timeout = 1; boot.initrd.network.enable = true; From 54aa35d40e8514ab26a1334bc71ac1bf03528e7f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Aug 2021 11:22:07 -0400 Subject: [PATCH 3/5] NixOS AWS AMI: Configure Grub's serial console See: * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking-os.html * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/grub.html --- nixos/modules/virtualisation/amazon-image.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index 6bdc661d9964..1f3b4c3709aa 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -64,6 +64,11 @@ in boot.loader.grub.efiSupport = cfg.efi; boot.loader.grub.efiInstallAsRemovable = cfg.efi; boot.loader.timeout = 1; + boot.loader.grub.extraConfig = '' + serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 + terminal_output console serial + terminal_input console serial + ''; boot.initrd.network.enable = true; From 1b791763105fb69277d1021826bf0ea3721ca9f2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Aug 2021 12:36:54 -0400 Subject: [PATCH 4/5] NixOS AWS AMI: enable the serial console on ttyS0 --- nixos/modules/profiles/headless.nix | 2 +- nixos/modules/virtualisation/amazon-image.nix | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nixos/modules/profiles/headless.nix b/nixos/modules/profiles/headless.nix index 46a9b6a7d8d5..c17cb287b72b 100644 --- a/nixos/modules/profiles/headless.nix +++ b/nixos/modules/profiles/headless.nix @@ -9,7 +9,7 @@ with lib; boot.vesa = false; # Don't start a tty on the serial consoles. - systemd.services."serial-getty@ttyS0".enable = false; + systemd.services."serial-getty@ttyS0".enable = lib.mkDefault false; systemd.services."serial-getty@hvc0".enable = false; systemd.services."getty@tty1".enable = false; systemd.services."autovt@".enable = false; diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index 1f3b4c3709aa..7ee5c096af98 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -18,7 +18,15 @@ let in { - imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-init.nix ]; + imports = [ + ../profiles/headless.nix + # Note: While we do use the headless profile, we also explicitly + # turn on the serial console on ttyS0 below. This is because + # AWS does support accessing the serial console: + # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configure-access-to-serial-console.html + ./ec2-data.nix + ./amazon-init.nix + ]; config = { @@ -141,6 +149,9 @@ in services.openssh.enable = true; services.openssh.permitRootLogin = "prohibit-password"; + # Enable the serial console on ttyS0 + systemd.services."serial-getty@ttyS0".enable = true; + # Creates symlinks for block device names. services.udev.packages = [ pkgs.ec2-utils ]; From c042c1a1f8bf2e8970a2ca038109fd23eaeb341c Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Aug 2021 12:42:18 -0400 Subject: [PATCH 5/5] NixOS AWS AMI: Create boot entries for each system generation --- nixos/modules/virtualisation/amazon-image.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index 7ee5c096af98..bf5c04543a70 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -140,10 +140,6 @@ in copy_bin_and_libs ${pkgs.util-linux}/sbin/swapon ''; - # Don't put old configurations in the GRUB menu. The user has no - # way to select them anyway. - boot.loader.grub.configurationLimit = 0; - # Allow root logins only using the SSH key that the user specified # at instance creation time. services.openssh.enable = true;