mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0095-resize-Preserve-GPT-GUID-so-we-don-t-break-EFI-bootl.patch

ffd6ed
From 2149aa86bc0b0484e2144c9c441926eab52bd102 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Thu, 5 Feb 2015 08:13:05 +0000
ffd6ed
Subject: [PATCH] resize: Preserve GPT GUID so we don't break EFI bootloaders
ffd6ed
 (RHBZ#1189284).
ffd6ed
ffd6ed
When copying disks that use EFI, we created a new partition table,
ffd6ed
randomizing the GPT GUID of the first partition.  Since EFI may store
ffd6ed
the GUID in its NVRAM variables, this could make the guest unbootable.
ffd6ed
ffd6ed
(cherry picked from commit f630677c14c7d5528e1ab39e4f805e0957b2ee3e)
ffd6ed
---
ffd6ed
 resize/resize.ml | 22 ++++++++++++++++++++--
ffd6ed
 1 file changed, 20 insertions(+), 2 deletions(-)
ffd6ed
ffd6ed
diff --git a/resize/resize.ml b/resize/resize.ml
ffd6ed
index 2090675..b581b39 100644
ffd6ed
--- a/resize/resize.ml
ffd6ed
+++ b/resize/resize.ml
ffd6ed
@@ -50,6 +50,7 @@ type partition = {
ffd6ed
   p_id : partition_id;           (* Partition (MBR/GPT) ID. *)
ffd6ed
   p_type : partition_content;    (* Content type and content size. *)
ffd6ed
   p_label : string option;       (* Label/name. *)
ffd6ed
+  p_guid : string option;        (* Partition GUID (GPT only). *)
ffd6ed
 
ffd6ed
   (* What we're going to do: *)
ffd6ed
   mutable p_operation : partition_operation;
ffd6ed
@@ -93,6 +94,11 @@ let rec debug_partition p =
ffd6ed
     (match p.p_label with
ffd6ed
     | Some label -> label
ffd6ed
     | None -> "(none)"
ffd6ed
+    );
ffd6ed
+  printf "\tGUID: %s\n"
ffd6ed
+    (match p.p_guid with
ffd6ed
+    | Some guid -> guid
ffd6ed
+    | None -> "(none)"
ffd6ed
     )
ffd6ed
 and string_of_partition_content = function
ffd6ed
   | ContentUnknown -> "unknown data"
ffd6ed
@@ -478,10 +484,16 @@ read the man page virt-resize(1).
ffd6ed
           let label =
ffd6ed
             try Some (g#part_get_name "/dev/sda" part_num)
ffd6ed
             with G.Error _ -> None in
ffd6ed
+          let guid =
ffd6ed
+            match parttype with
ffd6ed
+            | MBR -> None
ffd6ed
+            | GPT ->
ffd6ed
+              try Some (g#part_get_gpt_guid "/dev/sda" part_num)
ffd6ed
+              with G.Error _ -> None in
ffd6ed
 
ffd6ed
           { p_name = name; p_part = part;
ffd6ed
             p_bootable = bootable; p_id = id; p_type = typ;
ffd6ed
-            p_label = label;
ffd6ed
+            p_label = label; p_guid = guid;
ffd6ed
             p_operation = OpCopy; p_target_partnum = 0;
ffd6ed
             p_target_start = 0L; p_target_end = 0L }
ffd6ed
       ) parts in
ffd6ed
@@ -1068,7 +1080,7 @@ read the man page virt-resize(1).
ffd6ed
           p_part = { G.part_num = 0l; part_start = 0L; part_end = 0L;
ffd6ed
                      part_size = 0L };
ffd6ed
           p_bootable = false; p_id = No_ID; p_type = ContentUnknown;
ffd6ed
-          p_label = None;
ffd6ed
+          p_label = None; p_guid = None;
ffd6ed
 
ffd6ed
           (* Target information is meaningful. *)
ffd6ed
           p_operation = OpIgnore;
ffd6ed
@@ -1162,6 +1174,12 @@ read the man page virt-resize(1).
ffd6ed
       | None -> ()
ffd6ed
       );
ffd6ed
 
ffd6ed
+      (match p.p_guid with
ffd6ed
+      | Some guid ->
ffd6ed
+        g#part_set_gpt_guid "/dev/sdb" p.p_target_partnum guid;
ffd6ed
+      | None -> ()
ffd6ed
+      );
ffd6ed
+
ffd6ed
       match parttype, p.p_id with
ffd6ed
       | GPT, GPT_Type gpt_type ->
ffd6ed
         g#part_set_gpt_type "/dev/sdb" p.p_target_partnum gpt_type
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed