summary refs log tree commit diff
path: root/modules/system/boot
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2010-06-01 15:53:24 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2010-06-01 15:53:24 +0000
commitdc49a0ce3f79587e61ea2017be37fca21bf3c0d8 (patch)
treeb8529596f16553b177f1840aebc3109717ae06b8 /modules/system/boot
parenteb4c33eecabf30b9e5dd298e396d3046daa60001 (diff)
downloadnixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.tar
nixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.tar.gz
nixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.tar.bz2
nixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.tar.lz
nixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.tar.xz
nixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.tar.zst
nixpkgs-dc49a0ce3f79587e61ea2017be37fca21bf3c0d8.zip
* Don't use klibc in the initrd. It's simpler (and slightly smaller)
  to use the standard (coreutils) tools.
* Use util-linux's `switch_root' to switch over to the target root
  FS.  It automatically moves over the /dev, /proc and /sys from stage
  1, so stage 2 doesn't need to set them up again.

svn path=/nixos/trunk/; revision=22085
Diffstat (limited to 'modules/system/boot')
-rw-r--r--modules/system/boot/stage-1-init.sh27
-rw-r--r--modules/system/boot/stage-1.nix10
-rw-r--r--modules/system/boot/stage-2-init.sh20
-rw-r--r--modules/system/boot/stage-2.nix2
4 files changed, 22 insertions, 37 deletions
diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh
index 32121ca1169..c6a09d1e9a3 100644
--- a/modules/system/boot/stage-1-init.sh
+++ b/modules/system/boot/stage-1-init.sh
@@ -3,7 +3,7 @@
 targetRoot=/mnt-root
 
 export LD_LIBRARY_PATH=@extraUtils@/lib
-export PATH=@extraUtils@/bin:@klibc@/bin
+export PATH=@extraUtils@/bin
 
 
 fail() {
@@ -53,6 +53,7 @@ mkdir -p /proc
 mount -t proc none /proc
 mkdir -p /sys
 mount -t sysfs none /sys
+mount -t tmpfs -o "mode=0755,size=@devSize@" none /dev
 
 
 # Process the kernel command line.
@@ -144,7 +145,7 @@ checkFS() {
     # Only check block devices.
     if ! test -b "$device"; then return 0; fi
 
-    eval $(fstype "$device")
+    FSTYPE=$(blkid -o value -s TYPE "$device" || true)
 
     # Don't check ROM filesystems.
     if test "$FSTYPE" = iso9660 -o "$FSTYPE" = udf; then return 0; fi
@@ -276,33 +277,27 @@ done
 
 
 # Stop udevd.
-kill $(minips -C udevd -o pid=) 2> /dev/null
+kill -- -1
 
 
 if test -n "$debug1mounts"; then fail; fi
 
 
-# `run-init' needs a /dev/console on the target FS.
-if ! test -e $targetRoot/dev/console; then
-    mkdir -p $targetRoot/dev
-    mknod $targetRoot/dev/console c 5 1
-fi
-
-
 # Restore /proc/sys/kernel/modprobe to its original value.
 echo /sbin/modprobe > /proc/sys/kernel/modprobe
 
 
-# Start stage 2.  `run-init' deletes all files in the ramfs on the
-# current /.  Note that $stage2Init might be an absolute symlink, in
-# which case "-e" won't work because we're not in the chroot yet.
+# Start stage 2.  `switch_root' deletes all files in the ramfs on the
+# current root.  It also moves the /proc, /sys and /dev mounts over to
+# the new root.  Note that $stage2Init might be an absolute symlink,
+# in which case "-e" won't work because we're not in the chroot yet.
 if ! test -e "$targetRoot/$stage2Init" -o -L "$targetRoot/$stage2Init"; then
     echo "stage 2 init script not found"
     fail
 fi
 
-umount /sys
-umount /proc
-exec run-init "$targetRoot" "$stage2Init"
+mkdir -m 0755 -p $targetRoot/proc $targetRoot/sys $targetRoot/dev
+
+exec switch_root "$targetRoot" "$stage2Init"
 
 fail # should never be reached
diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix
index 013872aa2a7..c822c848b30 100644
--- a/modules/system/boot/stage-1.nix
+++ b/modules/system/boot/stage-1.nix
@@ -114,13 +114,17 @@ let
 
       # Copy some utillinux stuff.
       cp -v ${pkgs.utillinux}/bin/mount ${pkgs.utillinux}/bin/umount \
-         ${pkgs.utillinux}/sbin/fsck ${pkgs.utillinux}/sbin/pivot_root \
+         ${pkgs.utillinux}/sbin/fsck ${pkgs.utillinux}/sbin/switch_root \
          ${pkgs.utillinux}/sbin/blkid $out/bin
       cp -pdv ${pkgs.utillinux}/lib/libblkid*.so.* $out/lib
       cp -pdv ${pkgs.utillinux}/lib/libuuid*.so.* $out/lib
 
       # Copy some coreutils.
       cp -v ${pkgs.coreutils}/bin/basename $out/bin
+      cp -v ${pkgs.coreutils}/bin/mkdir $out/bin
+      cp -v ${pkgs.coreutils}/bin/mknod $out/bin
+      cp -v ${pkgs.coreutils}/bin/cat $out/bin
+      cp -v ${pkgs.coreutils}/bin/chroot $out/bin
 
       # Copy e2fsck and friends.      
       cp -v ${pkgs.e2fsprogs}/sbin/e2fsck $out/bin
@@ -256,11 +260,9 @@ let
 
     isExecutable = true;
 
-    klibc = pkgs.klibcShrunk;
-
     inherit udevConf extraUtils;
 
-    inherit (config.boot) resumeDevice;
+    inherit (config.boot) resumeDevice devSize;
 
     inherit (config.boot.initrd) checkJournalingFS
       postDeviceCommands postMountCommands kernelModules;
diff --git a/modules/system/boot/stage-2-init.sh b/modules/system/boot/stage-2-init.sh
index 6035f43d3ad..609bf0a95a4 100644
--- a/modules/system/boot/stage-2-init.sh
+++ b/modules/system/boot/stage-2-init.sh
@@ -36,13 +36,12 @@ setPath "@path@"
 mount -n -o remount,rw none /
 
 
-# Mount special file systems.
+# Mount special file systems.  Note that /dev, /proc and /sys are
+# already mounted by `switch_root' in the initrd.
 mkdir -m 0755 -p /etc
 test -e /etc/fstab || touch /etc/fstab # to shut up mount
 test -s /etc/mtab && rm /etc/mtab # while installing a symlink is created (see man mount), if it's still there for whateever reason remove it
 rm -f /etc/mtab* # not that we care about stale locks
-mkdir -m 0755 -p /proc
-mount -n -t proc none /proc
 
 rm -f /etc/mtab
 cat /proc/mounts > /etc/mtab
@@ -79,15 +78,11 @@ done
 
 
 # More special file systems, initialise required directories.
-mkdir -m 0755 -p /sys 
-mount -t sysfs none /sys
-mkdir -m 0755 -p /dev
-mount -t tmpfs -o "mode=0755,size=@devSize@" none /dev
 mkdir -m 0777 /dev/shm
 mount -t tmpfs -o "rw,nosuid,nodev,size=@devShmSize@" tmpfs /dev/shm
 mkdir -m 0755 -p /dev/pts
 mount -t devpts -o mode=0600,gid=@ttyGid@ none /dev/pts 
-[ -e /proc/bus/usb ] && mount -t usbfs none /proc/bus/usb # uml doesn't have usb by default
+[ -e /proc/bus/usb ] && mount -t usbfs none /proc/bus/usb # UML doesn't have USB by default
 mkdir -m 01777 -p /tmp 
 mkdir -m 0755 -p /var
 mkdir -m 0755 -p /nix/var
@@ -113,22 +108,15 @@ rm -rf /var/lock
 rm -rf /nix/var/nix/chroots # recreated in activate-configuration.sh
 
 
-# Create the minimal device nodes needed for the activation scripts
-# and Upstart.
-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
-
-
 # Clear the resume device.
 if test -n "$resumeDevice"; then
     mkswap "$resumeDevice" || echo 'Failed to clear saved image.'
 fi
 
-echo "running activation script..."
 
 # Run the script that performs all configuration activation that does
 # not have to be done at boot time.
+echo "running activation script..."
 @activateConfiguration@ "$systemConfig"
 
 
diff --git a/modules/system/boot/stage-2.nix b/modules/system/boot/stage-2.nix
index fc510dcbaea..279f454c5db 100644
--- a/modules/system/boot/stage-2.nix
+++ b/modules/system/boot/stage-2.nix
@@ -44,7 +44,7 @@ let
     src = ./stage-2-init.sh;
     isExecutable = true;
     inherit kernel activateConfiguration;
-    inherit (config.boot) devSize devShmSize;
+    inherit (config.boot) devShmSize;
     ttyGid = config.ids.gids.tty;
     upstart = config.system.build.upstart;
     path =