guestfs-tools/SOURCES/0001-sysprep-remove-lvm2-s-...

101 lines
3.9 KiB
Diff

From 37c002682a9e5b87d5793f1567c4ddfb8ca72d11 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Sun, 10 Apr 2022 13:38:34 +0200
Subject: [PATCH] sysprep: remove lvm2's default "system.devices" file
(Background: lvm2 commit 83fe6e720f42, "device usage based on devices
file", 2021-02-23; first released in v2_03_12.)
"lvm pvscan" may be -- and in RHEL9, will soon be -- restricted to those
block devices whose WWIDs are listed in "/etc/lvm/devices/system.devices".
This is a problem when cloning a VM, as cloning may change the WWIDs of
the domain's disk devices, and then physical volumes underlying the guest
filesystems may not be found. Example:
<https://bugzilla.redhat.com/show_bug.cgi?id=2059545#c12>.
Add the "lvm-system-devices" operation for removing this file, so that
"lvm pvscan" investigate all block devices for PVs.
(Note that this operation is independent from "lvm-uuids". The libguestfs
appliance creates a pristine LVM_SYSTEM_DIR in "appliance/init" (see
libguestfs commit dd162d2cd56a), thus, when "lvm-uuids" calls "g#pvs" and
"g#vgs", those APIs can never be affected by an
"$LVM_SYSTEM_DIR/devices/system.devices" file.)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2072493
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220410113834.6258-1-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 4fe8a03cd2d3e4570f4298245bb184ccdc4da0cd)
---
sysprep/Makefile.am | 1 +
.../sysprep_operation_lvm_system_devices.ml | 44 +++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 sysprep/sysprep_operation_lvm_system_devices.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index 0e3afc8a0..7d5e8aadf 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -46,6 +46,7 @@ operations = \
ipa_client \
kerberos_data \
kerberos_hostkeytab \
+ lvm_system_devices \
lvm_uuids \
logfiles \
machine_id \
diff --git a/sysprep/sysprep_operation_lvm_system_devices.ml b/sysprep/sysprep_operation_lvm_system_devices.ml
new file mode 100644
index 000000000..b41fa5dbc
--- /dev/null
+++ b/sysprep/sysprep_operation_lvm_system_devices.ml
@@ -0,0 +1,44 @@
+(* virt-sysprep
+ * Copyright (C) 2012-2022 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Sysprep_operation
+open Common_gettext.Gettext
+
+module G = Guestfs
+
+let system_devices_file = "/etc/lvm/devices/system.devices"
+
+let rec lvm_system_devices_perform g root side_effects =
+ let typ = g#inspect_get_type root in
+ if typ = "linux" then g#rm_f system_devices_file
+
+let op = {
+ defaults with
+ name = "lvm-system-devices";
+ enabled_by_default = true;
+ heading = s_"Remove LVM2 system.devices file";
+ pod_description =
+ Some (s_"On Linux guests, LVM2's scanning for physical volumes (PVs) may \
+ be restricted to those block devices whose WWIDs are listed in \
+ C<" ^ system_devices_file ^ ">. When cloning VMs, WWIDs may \
+ change, breaking C<lvm pvscan>. Remove \
+ C<" ^ system_devices_file ^ ">.");
+ perform_on_filesystems = Some lvm_system_devices_perform;
+}
+
+let () = register_operation op
--
2.31.1