From d91712ee894e3bcaabc51269d292cbe77ed89530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 1 Sep 2013 23:13:56 +0200 Subject: [PATCH] gnu: linux-initrd: Factorize device node creation. * guix/build/linux-initrd.scm (make-essential-device-nodes): New procedure. * gnu/packages/linux-initrd.scm (qemu-initrd): Use it. --- gnu/packages/linux-initrd.scm | 9 +++------ guix/build/linux-initrd.scm | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/gnu/packages/linux-initrd.scm b/gnu/packages/linux-initrd.scm index 17f42652e8..4a4e437635 100644 --- a/gnu/packages/linux-initrd.scm +++ b/gnu/packages/linux-initrd.scm @@ -270,10 +270,8 @@ (define-public qemu-initrd (unless (configure-qemu-networking) (display "network interface is DOWN\n")) - ;; Make the device nodes for QEMU's hard disk and partitions. - (mknod "/dev/vda" 'block-special #o644 (device-number 8 0)) - (mknod "/dev/vda1" 'block-special #o644 (device-number 8 1)) - (mknod "/dev/vda2" 'block-special #o644 (device-number 8 2)) + ;; Make /dev nodes. + (make-essential-device-nodes) ;; Prepare the real root file system under /root. (unless (file-exists? "/root") @@ -287,8 +285,7 @@ (define-public qemu-initrd (mkdir-p "/root/nix/store") (mkdir "/root/dev") - (mknod "/root/dev/null" 'char-special #o666 (device-number 1 3)) - (mknod "/root/dev/zero" 'char-special #o666 (device-number 1 5)) + (make-essential-device-nodes #:root "/root/dev") ;; Mount the host's store and exchange directory. (mount-qemu-smb-share "/store" "/root/nix/store") diff --git a/guix/build/linux-initrd.scm b/guix/build/linux-initrd.scm index 81f9e46cfb..208ad711ef 100644 --- a/guix/build/linux-initrd.scm +++ b/guix/build/linux-initrd.scm @@ -21,6 +21,7 @@ (define-module (guix build linux-initrd) #:use-module (system foreign) #:export (mount-essential-file-systems linux-command-line + make-essential-device-nodes configure-qemu-networking mount-qemu-smb-share bind-mount @@ -59,6 +60,37 @@ (define (linux-command-line) (call-with-input-file "/proc/cmdline" get-string-all))) +(define* (make-essential-device-nodes #:key (root "/")) + "Make essential device nodes under ROOT/dev." + ;; The hand-made udev! + + (define (scope dir) + (string-append root + (if (string-suffix? "/" root) + "" + "/") + dir)) + + (unless (file-exists? (scope "dev")) + (mkdir (scope "dev"))) + + ;; Make the device nodes for QEMU's hard disk and partitions. + (mknod (scope "dev/vda") 'block-special #o644 (device-number 8 0)) + (mknod (scope "dev/vda1") 'block-special #o644 (device-number 8 1)) + (mknod (scope "dev/vda2") 'block-special #o644 (device-number 8 2)) + + ;; TTYs. + (let loop ((n 0)) + (and (< n 50) + (let ((name (format #f "dev/tty~a" n))) + (mknod (scope name) 'block-special #o644 + (device-number 4 n)) + (loop (+ 1 n))))) + + ;; Other useful nodes. + (mknod (scope "dev/null") 'char-special #o666 (device-number 1 3)) + (mknod (scope "dev/zero") 'char-special #o666 (device-number 1 5))) + (define %host-qemu-ipv4-address (inet-pton AF_INET "10.0.2.10"))