From bbebba68f7a5fab3865f8dcadb82a7b7128a3c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Sun, 11 Mar 2012 21:56:47 +0000 Subject: [PATCH] A more friendly stage1, with interactive bash, busybox plenty of tools, etc. I set it as default because users can benefit of this without having to prepare their nixos first, and I don't think it will break any nixos for the initrd size increase. It can be disabled with 'boot.initrd.withExtraTools = false'. svn path=/nixos/trunk/; revision=33000 --- modules/module-list.nix | 1 + modules/system/boot/stage-1-extratools.nix | 56 ++++++++++++++++++++++ modules/system/boot/stage-1-init.sh | 20 +++++++- modules/system/boot/stage-1.nix | 2 +- modules/system/boot/stage-2-init.sh | 3 ++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 modules/system/boot/stage-1-extratools.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 6a73cac8cb5c..668841d3da27 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -190,6 +190,7 @@ ./system/boot/luksroot.nix ./system/boot/modprobe.nix ./system/boot/stage-1.nix + ./system/boot/stage-1-extratools.nix ./system/boot/stage-2.nix ./system/etc/etc.nix ./system/upstart-events/control-alt-delete.nix diff --git a/modules/system/boot/stage-1-extratools.nix b/modules/system/boot/stage-1-extratools.nix new file mode 100644 index 000000000000..c4224bc3035d --- /dev/null +++ b/modules/system/boot/stage-1-extratools.nix @@ -0,0 +1,56 @@ +{ config, pkgs, ...}: + +with pkgs.lib; + +let + staticBusybox = pkgs.busybox.override { + enableStatic = true; + }; +in +{ + + ###### interface + + options = { + boot.initrd.withExtraTools = mkOption { + default = true; + type = with types; bool; + description = '' + Have busybox utils in initrd, and an interactive bash. + ''; + }; + }; + + config = { + boot.initrd.extraUtilsCommands = mkIf config.boot.initrd.withExtraTools '' + + set -x + cp -pv ${pkgs.ncurses}/lib/libncurses*.so.* $out/lib + cp -pv ${pkgs.readline}/lib/libreadline.so.* $out/lib + cp -pv ${pkgs.readline}/lib/libhistory.so.* $out/lib + rm $out/bin/bash + cp -pv ${pkgs.bashInteractive}/bin/bash $out/bin + + cp -pv ${staticBusybox}/bin/busybox $out/bin + shopt -s nullglob + for d in bin sbin; do + pushd ${staticBusybox}/$d + # busybox has these, but we'll put them later + GLOBIGNORE=.:..:mke2fs:ip:modprobe + for a in *; do + if [ ! -e $out/bin/$a ]; then + ln -sf busybox $out/bin/$a + fi + done + popd + done + shopt -u nullglob + unset GLOBIGNORE + ''; + + boot.initrd.extraUtilsCommandsTest = mkIf config.boot.initrd.withExtraTools '' + $out/bin/busybox + ''; + }; + +} diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index d47ce1caffd6..e1341d50bcf3 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -25,12 +25,23 @@ EOF read reply + # Get the console from the kernel cmdline + console=tty1 + for o in $(cat /proc/cmdline); do + case $o in + console=*) + set -- $(IFS==; echo $o) + console=$2 + ;; + esac + done + case $reply in f) - exec @shell@;; + exec setsid @shell@ < /dev/$console >/dev/$console 2>/dev/$console ;; i) echo "Starting interactive shell..." - @shell@ || fail + setsid @shell@ < /dev/$console >/dev/$console 2>/dev/$console || fail ;; *) echo "Continuing...";; @@ -57,6 +68,11 @@ mount -t tmpfs -o "mode=0755,size=@devSize@" none /dev mkdir -p /run mount -t tmpfs -o "mode=0755,size=@runSize@" none /run +# Some console devices, for the interactivity +mknod /dev/console c 5 1 +mknod /dev/tty1 c 4 1 +mknod /dev/ttyS0 c 4 64 +mknod /dev/ttyS1 c 4 65 # Process the kernel command line. export stage2Init=/init diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index 5a74ea84f38b..1932599193ef 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -139,7 +139,7 @@ let # Copy some utillinux stuff. cp -v ${pkgs.utillinux}/bin/mount ${pkgs.utillinux}/bin/umount \ ${pkgs.utillinux}/sbin/fsck ${pkgs.utillinux}/sbin/switch_root \ - ${pkgs.utillinux}/sbin/blkid $out/bin + ${pkgs.utillinux}/sbin/blkid ${pkgs.utillinux}/bin/setsid $out/bin cp -pdv ${pkgs.utillinux}/lib/libblkid*.so.* $out/lib cp -pdv ${pkgs.utillinux}/lib/libuuid*.so.* $out/lib diff --git a/modules/system/boot/stage-2-init.sh b/modules/system/boot/stage-2-init.sh index 7a619f1f97f7..947ba4b7f352 100644 --- a/modules/system/boot/stage-2-init.sh +++ b/modules/system/boot/stage-2-init.sh @@ -46,6 +46,9 @@ if [ ! -e /proc/1 ]; then mknod -m 0666 /dev/null c 1 3 mknod -m 0644 /dev/urandom c 1 9 # needed for passwd mknod -m 0644 /dev/console c 5 1 + mknod -m 0644 /dev/tty1 c 4 1 + mknod -m 0644 /dev/ttyS0 c 4 64 + mknod -m 0644 /dev/ttyS1 c 4 65 fi