unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Jan Nieuwenhuizen <janneke@gnu.org>
To: Mathieu Othacehe <othacehe@gnu.org>
Cc: "Ludovic Courtès" <ludo@gnu.org>, 41350@debbugs.gnu.org
Subject: [bug#41350] [PATCH 0/3] Use native qemu to build vm-image.
Date: Wed, 20 May 2020 17:09:07 +0200	[thread overview]
Message-ID: <87lflm4p9o.fsf@gnu.org> (raw)
In-Reply-To: <87blmivh36.fsf@gnu.org> (Mathieu Othacehe's message of "Wed, 20 May 2020 16:03:41 +0200")

[-- Attachment #1: Type: text/plain, Size: 2783 bytes --]

Mathieu Othacehe writes:

Hello Mathieu!

>> The conclusion here is that, I think that we very few adaptations to
>> your branch, we should be able to produce Hurd ISO images or Hurd EFI
>> compatible disk-images. Maybe it would be a first step.
>>
>> Then, we could find a way to create "MBR compatible" Hurd and Linux
>> disk-images in (gnu system image).
>
> Ok, I made further progress. Turns out the Hurd EFI solution was a
> dead-end, because I have a "no console will be available to os" message
> in Qemu, instead of Hurd console output. I don't feel like debugging
> this.

Ah, well that's the only result that I also came up with and wanted to
share.  Maybe Ludo has an idea how to fix that; I could not find
anything helpful yet.

> So, back to the MBR solution. I had another look to what OpenWrt is
> doing. They found a really nice work-around! As I stated, we cannot use
> "grub-install", but this command is in reality a wrapper around
> "grub-mkimage" and "grub-bios-setup".

Ah!  That's good to know.

> #######################################
> #     #            #                  #
> # MBR # MBR-GAP    # FIRST PARTITION  #
> #     #            #                  #
> #######################################
>
>
> grub-mkimage generates a Grub image, small enough so that it can fit in
> the MBR-GAP (the space between the MBR and the first partition).

Okay...

> It cannot contain all Grub modules, but that's not an issue, because
> Grub will be able to find missing modules from the first partition when
> started.

aha...

> They also patched grub-bios-setup[1] so that it can work on a raw
> disk-image, and install the previously generated "grub.img".

So, this is one aspect of what we're avoiding by running grub-install
in a qemu vm, right?  Any idea on the upstream status of this patch?
(I don't think it matters all that much for us, let's use it :-)

> So with the following commands:
>
> grub-mkimage -O i386-pc -o core.img  biosdisk part_msdos ext2
> echo "(hd0) /tmp/my-disk-image" > device.map
> grub-bios-setup -m device.map -r "hd0,msdos1" -d tmp /tmp/qemu-image2
>
> I'm able to make a Guix system image bootable, without root
> permissions. It then starts the Hurd kernel and crashes, but that's
> another story :p

Thats *great*, no really!

> So, if it's ok for you, I can integrate this stuff cleanly, and we won't
> need the vm-image stuff anymore.
>
> WDYT?

That seems a very good idea, I'm cc'ing Ludo to ping him about this.

I'm attaching some hacky work that I did on the patch that you paste'd
to me via IRC, adding som Hurd'y things.  Maybe the pointers are
helpful, but it's all pretty obvious.

Greetings,
Janneke

> [1]:
> https://github.com/openwrt/openwrt/blob/master/package/boot/grub2/patches/100-grub_setup_root.patch


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP-disk-image.patch --]
[-- Type: text/x-patch, Size: 5931 bytes --]

From 9bd218f4d91f79b26ad32cc6c4c1f479febd28de Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Tue, 19 May 2020 16:01:42 +0200
Subject: [PATCH] WIP: disk-image

qemu-system-i386 -enable-kvm
            -bios $(guix build ovmf)/share/firmware/ovmf_ia32.bin -hda
            /tmp/qemu-image -m 1024

<mothacehe>  janneke: With this patch on top of your branch:
            https://paste.debian.net/1147629/, I'm able to generate an EFI
            disk-image.  [15:54]
<mothacehe> That I start with this command:  qemu-system-i386 -enable-kvm
            -bios $(guix build ovmf)/share/firmware/ovmf_ia32.bin -hda
            /tmp/qemu-image -m 1024
<mothacehe> janneke: Sadly, just after Grub, the virtual machine restarts,
            nothing is printed.  [15:55]
---
 gnu/build/bootloader.scm           |  2 +-
 gnu/build/image.scm                | 18 ++++++++++--------
 gnu/system/examples/bare-hurd.tmpl |  2 +-
 gnu/system/image.scm               | 10 ++++++----
 4 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm
index 498022f6db..68b68c4b47 100644
--- a/gnu/build/bootloader.scm
+++ b/gnu/build/bootloader.scm
@@ -56,7 +56,7 @@
          (efi-directory (string-append esp "/EFI/BOOT"))
          ;; Map grub target names to boot file names.
          (efi-targets (cond ((string-prefix? "x86_64" system)
-                             '("x86_64-efi" . "BOOTX64.EFI"))
+                             '("i386-efi" . "BOOTIA32.EFI"))
                             ((string-prefix? "i686" system)
                              '("i386-efi" . "BOOTIA32.EFI"))
                             ((string-prefix? "armhf" system)
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index fe8e11aa1b..23fc56571f 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -63,16 +63,18 @@
 take the partition metadata size into account, take a 25% margin."
   (* 1.25 (file-size root)))
 
-(define* (make-ext4-image partition target root
-                          #:key
-                          (owner-uid 0)
-                          (owner-gid 0))
-  "Handle the creation of EXT4 partition images. See 'make-partition-image'."
+(define* (make-ext-image partition target root
+                         #:key
+                         (owner-uid 0)
+                         (owner-gid 0))
+  "Handle the creation of EXT2/3/4 partition images. See
+'make-partition-image'."
   (let ((size (partition-size partition))
+        (fs (partition-file-system partition))
         (label (partition-label partition))
         (uuid (partition-uuid partition))
         (options "lazy_itable_init=1,lazy_journal_init=1"))
-    (invoke "mke2fs" "-t" "ext4" "-d" root
+    (invoke "mke2fs" "-t" fs "-d" root
             "-L" label "-U" (uuid->string uuid)
             "-E" (format #f "root_owner=~a:~a,~a"
                          owner-uid owner-gid options)
@@ -105,8 +107,8 @@ ROOT directory to populate the image."
   (let* ((partition (sexp->partition partition-sexp))
          (type (partition-file-system partition)))
     (cond
-     ((string=? type "ext4")
-      (make-ext4-image partition target root))
+     ((string-prefix? "ext" type)
+      (make-ext-image partition target root))
      ((string=? type "vfat")
       (make-vfat-image partition target root))
      (else
diff --git a/gnu/system/examples/bare-hurd.tmpl b/gnu/system/examples/bare-hurd.tmpl
index d4c40e6841..c3adf03a7f 100644
--- a/gnu/system/examples/bare-hurd.tmpl
+++ b/gnu/system/examples/bare-hurd.tmpl
@@ -11,7 +11,7 @@
   (operating-system
     (inherit %hurd-default-operating-system)
     (bootloader (bootloader-configuration
-                 (bootloader grub-minimal-bootloader)
+                 (bootloader grub-efi-bootloader)
                  (target "/dev/sdX")))
     (file-systems (cons (file-system
                           (device (file-system-label "my-root"))
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index 571b7af5f3..888099dae5 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -79,7 +79,7 @@
   (partition
    (size 'guess)
    (label "Guix_image")
-   (file-system "ext4")
+   (file-system "ext2")
    (flags '(boot))
    (initializer (gexp initialize-root-partition))))
 
@@ -222,7 +222,9 @@ used in the image."
                               #:deduplicate? #f
                               #:system-directory #$os
                               #:bootloader-package
-                              #$(bootloader-package bootloader)
+                              #+(with-parameters
+                                    ((%current-system "i686-linux"))
+                                  (bootloader-package bootloader))
                               #:bootcfg #$bootcfg
                               #:bootcfg-location
                               #$(bootloader-configuration-file bootloader)))))
@@ -232,7 +234,7 @@ used in the image."
              (type (partition-file-system partition))
              (image-builder
               (with-imported-modules*
-               (let ((inputs '#$(list e2fsprogs dosfstools mtools)))
+               (let ((inputs '#+(list e2fsprogs dosfstools mtools)))
                  (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
                  (make-partition-image #$(partition->gexp partition)
                                        #$output
@@ -269,7 +271,7 @@ image ~a {
   (let* ((substitutable? (image-substitutable? image))
          (builder
           (with-imported-modules*
-           (let ((inputs '#$(list genimage coreutils findutils)))
+           (let ((inputs '#+(list genimage coreutils findutils)))
              (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
              (genimage #$(image->genimage-cfg image) #$output))))
          (image-dir (computed-file "image-dir" builder)))
-- 
2.26.2


[-- Attachment #3: Type: text/plain, Size: 152 bytes --]


-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com

  reply	other threads:[~2020-05-20 15:10 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 10:01 [bug#41350] [PATCH 0/3] Use native qemu to build vm-image Jan Nieuwenhuizen
2020-05-17 10:03 ` [bug#41350] [PATCH 1/3] utils: Move 'reset-timestamps' out of database Jan (janneke) Nieuwenhuizen
2020-05-17 10:03   ` [bug#41350] [PATCH 2/3] system: vm: Do not register-closures when cross-building Jan (janneke) Nieuwenhuizen
2020-05-17 10:03   ` [bug#41350] [PATCH 3/3] system: vm: Build vm-image using native qemu Jan (janneke) Nieuwenhuizen
2020-05-18  9:10 ` [bug#41350] [PATCH 0/3] Use native qemu to build vm-image Mathieu Othacehe
2020-05-19  7:22   ` Jan Nieuwenhuizen
2020-05-19 10:02     ` Mathieu Othacehe
2020-05-20 14:03       ` Mathieu Othacehe
2020-05-20 15:09         ` Jan Nieuwenhuizen [this message]
2020-05-19  7:23 ` [bug#41350] [PATCH v2 1/3] utils: Move 'reset-timestamps' out of database Jan (janneke) Nieuwenhuizen
2020-05-19  7:23   ` [bug#41350] [PATCH v2 2/3] system: vm: Do not register-closures when cross-building to the Hurd Jan (janneke) Nieuwenhuizen
2020-05-19  7:23   ` [bug#41350] [PATCH v2 3/3] system: vm: Build vm-image using native qemu, for " Jan (janneke) Nieuwenhuizen
2020-05-19  9:14     ` Mathieu Othacehe
2020-05-20 21:49       ` Ludovic Courtès
2020-05-23  9:28       ` Jan Nieuwenhuizen
2020-05-23 17:45         ` Mathieu Othacehe
2020-05-23 19:07           ` Jan Nieuwenhuizen
2020-05-24  9:18             ` Mathieu Othacehe
2020-05-27  9:30               ` Ludovic Courtès
2020-05-28  7:00                 ` Mathieu Othacehe
2020-05-24 11:19             ` Jan Nieuwenhuizen
2020-05-24 12:07               ` Mathieu Othacehe
2020-05-24 14:20                 ` Jan Nieuwenhuizen
2020-05-24 16:36             ` Ludovic Courtès
2020-05-20 21:58     ` Ludovic Courtès
2020-05-22 19:24 ` Mathieu Othacehe
2020-05-27 22:54   ` Ludovic Courtès
2020-05-28  6:36     ` Mathieu Othacehe
2020-05-28 12:29       ` Jan Nieuwenhuizen
2020-05-28 15:39         ` Ludovic Courtès
2020-05-28 17:07           ` Jan Nieuwenhuizen
2020-05-28 17:10           ` Mathieu Othacehe
2020-05-28 18:19             ` Jan Nieuwenhuizen
2020-05-29  8:18             ` Ludovic Courtès
2020-05-29  9:06               ` Jan Nieuwenhuizen
2020-05-30 10:08                 ` Jan Nieuwenhuizen
2020-05-30 13:54                   ` Ludovic Courtès
2022-09-28 20:18                     ` [bug#41350] [PATCH 0/3] Use native qemu to build vm-image Maxim Cournoyer
2022-09-29 14:17                       ` bug#41350: " Mathieu Othacehe
2020-05-23  9:30 ` [bug#41350] [PATCH v3 1/3] utils: Move 'reset-timestamps' out of database Jan (janneke) Nieuwenhuizen
2020-05-23  9:30   ` [bug#41350] [PATCH v3 2/3] system: vm: Do not register-closures when cross-building to the Hurd Jan (janneke) Nieuwenhuizen
2020-05-27  8:45     ` Ludovic Courtès
2020-05-27  9:13       ` Jan Nieuwenhuizen
2020-05-23  9:30   ` [bug#41350] [PATCH v3 3/3] system: vm: Build vm-image using native qemu, for " Jan (janneke) Nieuwenhuizen
2020-05-27  8:43   ` [bug#41350] [PATCH v3 1/3] utils: Move 'reset-timestamps' out of database Ludovic Courtès
2020-05-27  8:59     ` Ludovic Courtès
2020-05-27  9:10     ` Jan Nieuwenhuizen
2020-05-24 18:11 ` [bug#41350] [PATCH v2 3/3] system: vm: Build vm-image using native qemu, for the Hurd Mathieu Othacehe
2020-05-24 18:40   ` Jan Nieuwenhuizen
2020-05-25 15:46     ` Jan Nieuwenhuizen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lflm4p9o.fsf@gnu.org \
    --to=janneke@gnu.org \
    --cc=41350@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=othacehe@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).