Blame SOURCES/0027-p2v-Add-usb-storage-module-and-rebuild-initrd-RHBZ-1.patch

0d20ef
From 9480da99354f873916b19b07be649f5965bfe1f2 Mon Sep 17 00:00:00 2001
0d20ef
From: "Richard W.M. Jones" <rjones@redhat.com>
0d20ef
Date: Mon, 27 Oct 2014 15:42:02 +0000
0d20ef
Subject: [PATCH] p2v: Add usb-storage module and rebuild initrd
0d20ef
 (RHBZ#1157679).
0d20ef
0d20ef
Include the usb-storage kernel module, to permit booting from USB
0d20ef
keys.
0d20ef
0d20ef
Rerun dracut to rebuild the initramfs.  This is complicated because by
0d20ef
default dracut will try to build an initramfs for the running
0d20ef
(ie. appliance) kernel, which is completely useless.  We need to find
0d20ef
the latest installed kernel and rebuild the initramfs for that
0d20ef
instead, which is hairy.
0d20ef
0d20ef
This also does a small refactoring of the distro-specific code,
0d20ef
removing the $selinux_relabel variable and replacing it with a generic
0d20ef
$extra_args variable.
0d20ef
0d20ef
I only added this to the virt-builder script, since one assumes that
0d20ef
livecd-creator/whatever should make the kickstart ISO bootable by
0d20ef
installing whatever drivers and modules are necessary.
0d20ef
0d20ef
(cherry picked from commit b09b60c987ff113bc4520ab994142da912ffa3d6)
0d20ef
---
0d20ef
 p2v/virt-p2v-make-disk.in | 30 +++++++++++++++++++++++++++---
0d20ef
 1 file changed, 27 insertions(+), 3 deletions(-)
0d20ef
0d20ef
diff --git a/p2v/virt-p2v-make-disk.in b/p2v/virt-p2v-make-disk.in
0d20ef
index c29af2c..fb02856 100644
0d20ef
--- a/p2v/virt-p2v-make-disk.in
0d20ef
+++ b/p2v/virt-p2v-make-disk.in
0d20ef
@@ -74,6 +74,14 @@ fi
0d20ef
 
0d20ef
 osversion="$1"
0d20ef
 
0d20ef
+# Create a temporary directory and clean it up when we finish.
0d20ef
+tmpdir="$(mktemp -d)"
0d20ef
+cleanup ()
0d20ef
+{
0d20ef
+    rm -rf $tmpdir
0d20ef
+}
0d20ef
+trap cleanup INT QUIT TERM EXIT ERR
0d20ef
+
0d20ef
 # The dependencies are:
0d20ef
 #
0d20ef
 #   - pcre (library only)
0d20ef
@@ -92,7 +100,21 @@ osversion="$1"
0d20ef
 case "$osversion" in
0d20ef
     centos-*|fedora-*|rhel-*|scientificlinux-*)
0d20ef
         deps=pcre,libxml2,gtk2,/usr/bin/xinit,/usr/bin/ssh,/usr/bin/qemu-nbd,/usr/bin/Xorg,xorg-x11-drivers,xorg-x11-fonts-Type1,matchbox-window-manager,@hardware-support
0d20ef
-        selinux_relabel=--selinux-relabel
0d20ef
+        cat > $tmpdir/p2v.conf <<'EOF'
0d20ef
+add_drivers+=" usb-storage "
0d20ef
+EOF
0d20ef
+        cat > $tmpdir/post-install <<'EOF'
0d20ef
+#!/bin/bash
0d20ef
+# Rebuild the initramfs.
0d20ef
+version=` rpm -q kernel | sort -rV | head -1 | sed 's/kernel-//' `
0d20ef
+dracut -f --kver $version
0d20ef
+EOF
0d20ef
+        # Double quotes because we want $tmpdir to be expanded:
0d20ef
+        extra_args="
0d20ef
+          --selinux-relabel
0d20ef
+          --upload $tmpdir/p2v.conf:/etc/dracut.conf.d/
0d20ef
+          --run $tmpdir/post-install
0d20ef
+        "
0d20ef
         ;;
0d20ef
     debian-*|ubuntu-*)
0d20ef
         deps=libpcre3,libxml2,libgtk2.0-0,openssh-client,qemu-utils,xorg,xserver-xorg-video-all,matchbox-window-manager
0d20ef
@@ -123,7 +145,6 @@ fi
0d20ef
 
0d20ef
 # Run virt-builder.  Note we controversially assume systemd here.  We
0d20ef
 # could provide a sysvinit fallback if required.
0d20ef
-exec \
0d20ef
 virt-builder "$osversion"                                       \
0d20ef
     --output "$output"                                          \
0d20ef
     --update                                                    \
0d20ef
@@ -145,4 +166,7 @@ virt-builder "$osversion"                                       \
0d20ef
     --edit '/etc/systemd/logind.conf:
0d20ef
         s/^[Login]/[Login]\nReserveVT=1\n/
0d20ef
     '                                                           \
0d20ef
-    $selinux_relabel
0d20ef
+    $extra_args
0d20ef
+
0d20ef
+# We have to do this so the cleanup() handler runs.
0d20ef
+exit $?
0d20ef
-- 
0d20ef
1.8.3.1
0d20ef