File 0001-Add-save-initramfs-to-save-the-actual-generated-init.patch of Package virtme

From d2438fe1ba0c379a50bcd01bd310c7a310242ca6 Mon Sep 17 00:00:00 2001
From: Andy Lutomirski <luto@kernel.org>
Date: Wed, 16 Oct 2019 10:39:18 -0700
Subject: [PATCH 1/9] Add --save-initramfs to save the actual generated
 initramfs

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 virtme/commands/run.py | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/virtme/commands/run.py b/virtme/commands/run.py
index 78782ca..7526dea 100644
--- a/virtme/commands/run.py
+++ b/virtme/commands/run.py
@@ -106,6 +106,8 @@ def make_parser() -> argparse.ArgumentParser:
                    help="Initialize everything but don't run the guest")
     g.add_argument('--show-command', action='store_true',
                    help='Show the VM command line')
+    g.add_argument('--save-initramfs', action='store',
+                   help='Save the generated initramfs to the specified path')
     g.add_argument('--show-boot-console', action='store_true',
                    help='Show the boot console when running scripts')
 
@@ -518,14 +520,23 @@ def do_it() -> int:
             config.access = 'rw'
 
         # Set up the initramfs (warning: hack ahead)
-        tmpfd,tmpname = tempfile.mkstemp('irfs')
-        os.unlink(tmpname)
-        tmpfile = os.fdopen(tmpfd, 'r+b')
-        mkinitramfs.mkinitramfs(tmpfile, config)
-        tmpfile.flush()
-        fcntl.fcntl(tmpfd, fcntl.F_SETFD, 0)
-        initrdpath = '/proc/self/fd/%d' % tmpfile.fileno()
+        if args.save_initramfs is not None:
+            initramfsfile = open(args.save_initramfs, 'xb')
+            initramfsfd = initramfsfile.fileno()
+        else:
+            initramfsfd,tmpname = tempfile.mkstemp('irfs')
+            os.unlink(tmpname)
+            initramfsfile = os.fdopen(initramfsfd, 'r+b')
+        mkinitramfs.mkinitramfs(initramfsfile, config)
+        initramfsfile.flush()
+        fcntl.fcntl(initramfsfd, fcntl.F_SETFD, 0)
+        initrdpath = '/proc/self/fd/%d' % initramfsfd
     else:
+        if args.save_initramfs is not None:
+            print('--save_initramfs specified but initramfs is not used',
+                  file=sys.stderr)
+            return 1
+
         # No initramfs!  Warning: this is slower than using an initramfs
         # because the kernel will wait for device probing to finish.
         # Sigh.
-- 
2.26.2

openSUSE Build Service is sponsored by