diff --git a/.gitignore b/.gitignore index 27c51f8..8dda6b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +*~ /guestfs-tools-*.tar.gz /guestfs-tools-*.tar.gz.sig diff --git a/0001-Move-the-repository-to-https-github.com-libguestfs-g.patch b/0001-Move-the-repository-to-https-github.com-libguestfs-g.patch deleted file mode 100644 index 6cef80b..0000000 --- a/0001-Move-the-repository-to-https-github.com-libguestfs-g.patch +++ /dev/null @@ -1,44 +0,0 @@ -From f1f68bd19ef6cc1b295ca452eb4ba877db70df1c Mon Sep 17 00:00:00 2001 -From: "Richard W.M. Jones" -Date: Mon, 15 Jan 2024 09:56:31 +0000 -Subject: [PATCH 1/2] Move the repository to - https://github.com/libguestfs/guestfs-tools - ---- - README | 6 +++++- - drivers/virt-drivers.pod | 2 +- - 2 files changed, 6 insertions(+), 2 deletions(-) - -diff --git a/README b/README -index 2148f9067f5..988c5f910bc 100644 ---- a/README -+++ b/README -@@ -7,7 +7,11 @@ For discussion, development, patches, etc. please use the mailing list: - - https://lists.libguestfs.org - --Copyright (C) 2009-2023 Red Hat Inc. -+Upstream git repository: -+ -+ https://github.com/libguestfs/guestfs-tools -+ -+Copyright (C) 2009-2024 Red Hat Inc. - - The programs are distributed under the GPLv2+. Some parts are LGPLv2+ - licensed. See individual files for license details, and COPYING and -diff --git a/drivers/virt-drivers.pod b/drivers/virt-drivers.pod -index 266dd68eebb..600815d3cda 100644 ---- a/drivers/virt-drivers.pod -+++ b/drivers/virt-drivers.pod -@@ -83,7 +83,7 @@ kernels are provided. For example: - Many more fields are usually available for Linux guests, including a - complete list of kernel modules and information about support for - virtio. For a complete example see: --L -+L - - =head2 EdriversE - --- -2.43.0 - diff --git a/0001-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch b/0001-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch new file mode 100644 index 0000000..801f617 --- /dev/null +++ b/0001-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch @@ -0,0 +1,24 @@ +From e827be5bb317f3d50086e2987ee88cd931e1f1b1 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 7 Jul 2015 09:28:03 -0400 +Subject: [PATCH] RHEL: Reject use of libguestfs-winsupport features except for + virt-* tools (RHBZ#1240276). + +Fix the tests: it doesn't let us use guestfish for arbitrary Windows +edits. +--- + test-data/phony-guests/make-windows-img.sh | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/test-data/phony-guests/make-windows-img.sh b/test-data/phony-guests/make-windows-img.sh +index 16debd129..1c13ddac3 100755 +--- a/test-data/phony-guests/make-windows-img.sh ++++ b/test-data/phony-guests/make-windows-img.sh +@@ -37,6 +37,7 @@ fi + + # Create a disk image. + guestfish < +Date: Mon, 21 Nov 2022 13:03:22 +0000 +Subject: [PATCH] RHEL: builder: Disable opensuse repository + +Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2145160 +(cherry picked from commit 8e0e91c923bd7076fd906a71678ddd3f328ae2c0) +--- + builder/opensuse.conf.in | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/builder/opensuse.conf.in b/builder/opensuse.conf.in +index 19f979699..a57fc6977 100644 +--- a/builder/opensuse.conf.in ++++ b/builder/opensuse.conf.in +@@ -1,3 +1,7 @@ +-[opensuse.org] +-uri=http://download.opensuse.org/repositories/Virtualization:/virt-builder-images/images/index +-gpgkey=file://@SYSCONFDIR@/virt-builder/repos.d/opensuse.gpg ++# https://bugzilla.redhat.com/show_bug.cgi?id=2145160 ++# This is disabled in RHEL by default, but you can enable it by ++# uncommenting the lines below. ++ ++#[opensuse.org] ++#uri=http://download.opensuse.org/repositories/Virtualization:/virt-builder-images/images/index ++#gpgkey=file://@SYSCONFDIR@/virt-builder/repos.d/opensuse.gpg diff --git a/0002-builder-Add-a-test-of-the-chown-parameter.patch b/0002-builder-Add-a-test-of-the-chown-parameter.patch deleted file mode 100644 index 03a7969..0000000 --- a/0002-builder-Add-a-test-of-the-chown-parameter.patch +++ /dev/null @@ -1,64 +0,0 @@ -From 299dc5ec2a0bdd9adecef75adc6a5eca0dc685b1 Mon Sep 17 00:00:00 2001 -From: "Richard W.M. Jones" -Date: Fri, 19 Jan 2024 13:22:51 +0000 -Subject: [PATCH 2/2] builder: Add a test of the --chown parameter - -Also update the libguestfs common submodule, pulling in this change -from libguestfs: - - generator/customize.ml: Split --chown parameter on ':' character - -and this patch to common/mltools: - - mltools/libosinfo-c.c: Fix off-by-one error ---- - builder/test-virt-builder.sh | 4 ++++ - common | 2 +- - 2 files changed, 5 insertions(+), 1 deletion(-) - -diff --git a/builder/test-virt-builder.sh b/builder/test-virt-builder.sh -index 705788a3ccd..f839fd7afe0 100755 ---- a/builder/test-virt-builder.sh -+++ b/builder/test-virt-builder.sh -@@ -69,6 +69,7 @@ virt-builder phony-fedora \ - --write '/etc/append6: - ' \ - --append-line '/etc/append6:line2' \ -+ --chown 1:1:/etc/append6 \ - --firstboot Makefile --firstboot-command 'echo "hello"' \ - --firstboot-install "minicom,inkscape" - -@@ -112,6 +113,7 @@ echo append5: - cat /etc/append5 - echo append6: - cat /etc/append6 -+stat /etc/append6 | grep '^[ug]id:' - - echo ----- - EOF -@@ -154,6 +156,8 @@ append6: - - line2 - -+uid: 1 -+gid: 1 - -----" ]; then - echo "$0: unexpected output:" - cat test-virt-builder.out -Submodule common 0dba002c20b..54869c98753: -diff --git a/common/mlcustomize/customize_cmdline.ml b/common/mlcustomize/customize_cmdline.ml -index 245d996..48ee334 100644 ---- a/common/mlcustomize/customize_cmdline.ml -+++ b/common/mlcustomize/customize_cmdline.ml -@@ -157,7 +157,7 @@ let rec argspec () = - let len = String.length arg in - String.sub arg 0 i, String.sub arg (i+1) (len-(i+1)) - and split_string_triplet option_name arg = -- match String.nsplit ~max:3 "," arg with -+ match String.nsplit ~max:3 ":" arg with - | [a; b; c] -> a, b, c - | _ -> - error (f_"invalid format for '--%s' parameter, see the man page") --- -2.43.0 - diff --git a/0003-customize-Implement-inject-blnsvr-operation.patch b/0003-customize-Implement-inject-blnsvr-operation.patch new file mode 100644 index 0000000..ff7ae18 --- /dev/null +++ b/0003-customize-Implement-inject-blnsvr-operation.patch @@ -0,0 +1,222 @@ +From 566e21933505606a64fe6e7c154ffb90209e7101 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Thu, 16 May 2024 12:49:24 +0100 +Subject: [PATCH] customize: Implement --inject-blnsvr operation + +Also updates the common submodule with the generated changes from +libguestfs, and the implementation of Inject_virtio_win.inject_blnsvr. + +(cherry picked from commit 80d258baa49214c8e59b91d6085595c9b989fc0d) +--- + common | 2 +- + customize/customize_run.ml | 13 +++++++++++-- + 2 files changed, 12 insertions(+), 3 deletions(-) + +Submodule common 93a7f3af5..830cbdcf4: +diff --git a/common/mlcustomize/customize-options.pod b/common/mlcustomize/customize-options.pod +index ff93630d8..b2ac57526 100644 +--- a/common/mlcustomize/customize-options.pod ++++ b/common/mlcustomize/customize-options.pod +@@ -193,6 +193,18 @@ L. + Set the hostname of the guest to C. You can use a + dotted hostname.domainname (FQDN) if you want. + ++=item B<--inject-blnsvr> METHOD ++ ++Inject the Balloon Server (F) into a Windows guest. ++This operation also injects a firstboot script so that the Balloon ++Server is installed when the guest boots. ++ ++The parameter is the same as used by the I<--inject-virtio-win> operation. ++ ++Note that to do a full conversion of a Windows guest from a ++foreign hypervisor like VMware (which involves many other operations) ++you should use the L tool instead of this. ++ + =item B<--inject-qemu-ga> METHOD + + Inject the QEMU Guest Agent into a Windows guest. The guest +diff --git a/common/mlcustomize/customize-synopsis.pod b/common/mlcustomize/customize-synopsis.pod +index bb0ce1255..957de8cf2 100644 +--- a/common/mlcustomize/customize-synopsis.pod ++++ b/common/mlcustomize/customize-synopsis.pod +@@ -3,16 +3,16 @@ + [--copy SOURCE:DEST] [--copy-in LOCALPATH:REMOTEDIR] + [--delete PATH] [--edit FILE:EXPR] [--firstboot SCRIPT] + [--firstboot-command 'CMD+ARGS'] [--firstboot-install PKG,PKG..] +- [--hostname HOSTNAME] [--inject-qemu-ga METHOD] +- [--inject-virtio-win METHOD] [--install PKG,PKG..] +- [--link TARGET:LINK[:LINK..]] [--mkdir DIR] [--move SOURCE:DEST] +- [--password USER:SELECTOR] [--root-password SELECTOR] +- [--run SCRIPT] [--run-command 'CMD+ARGS'] [--scrub FILE] +- [--sm-attach SELECTOR] [--sm-register] [--sm-remove] +- [--sm-unregister] [--ssh-inject USER[:SELECTOR]] +- [--tar-in TARFILE:REMOTEDIR] [--timezone TIMEZONE] [--touch FILE] +- [--truncate FILE] [--truncate-recursive PATH] +- [--uninstall PKG,PKG..] [--update] [--upload FILE:DEST] +- [--write FILE:CONTENT] [--no-logfile] ++ [--hostname HOSTNAME] [--inject-blnsvr METHOD] ++ [--inject-qemu-ga METHOD] [--inject-virtio-win METHOD] ++ [--install PKG,PKG..] [--link TARGET:LINK[:LINK..]] [--mkdir DIR] ++ [--move SOURCE:DEST] [--password USER:SELECTOR] ++ [--root-password SELECTOR] [--run SCRIPT] ++ [--run-command 'CMD+ARGS'] [--scrub FILE] [--sm-attach SELECTOR] ++ [--sm-register] [--sm-remove] [--sm-unregister] ++ [--ssh-inject USER[:SELECTOR]] [--tar-in TARFILE:REMOTEDIR] ++ [--timezone TIMEZONE] [--touch FILE] [--truncate FILE] ++ [--truncate-recursive PATH] [--uninstall PKG,PKG..] [--update] ++ [--upload FILE:DEST] [--write FILE:CONTENT] [--no-logfile] + [--password-crypto md5|sha256|sha512] [--no-selinux-relabel] + [--selinux-relabel] [--sm-credentials SELECTOR] +diff --git a/common/mlcustomize/customize_cmdline.ml b/common/mlcustomize/customize_cmdline.ml +index 48ee33445..c4d6a77d5 100644 +--- a/common/mlcustomize/customize_cmdline.ml ++++ b/common/mlcustomize/customize_cmdline.ml +@@ -61,6 +61,8 @@ and op = [ + (* --firstboot-install PKG,PKG.. *) + | `Hostname of string + (* --hostname HOSTNAME *) ++ | `InjectBalloonServer of string ++ (* --inject-blnsvr METHOD *) + | `InjectQemuGA of string + (* --inject-qemu-ga METHOD *) + | `InjectVirtioWin of string +@@ -286,6 +288,12 @@ let rec argspec () = + s_"Set the hostname" + ), + Some "HOSTNAME", "Set the hostname of the guest to C. You can use a\ndotted hostname.domainname (FQDN) if you want."; ++ ( ++ [ L"inject-blnsvr" ], ++ Getopt.String (s_"METHOD", fun s -> List.push_front (`InjectBalloonServer s) ops), ++ s_"Inject the Balloon Server into a Windows guest" ++ ), ++ Some "METHOD", "Inject the Balloon Server (F) into a Windows guest.\nThis operation also injects a firstboot script so that the Balloon\nServer is installed when the guest boots.\n\nThe parameter is the same as used by the I<--inject-virtio-win> operation.\n\nNote that to do a full conversion of a Windows guest from a\nforeign hypervisor like VMware (which involves many other operations)\nyou should use the L tool instead of this."; + ( + [ L"inject-qemu-ga" ], + Getopt.String (s_"METHOD", fun s -> List.push_front (`InjectQemuGA s) ops), +diff --git a/common/mlcustomize/customize_cmdline.mli b/common/mlcustomize/customize_cmdline.mli +index 51a156eae..ee62961a1 100644 +--- a/common/mlcustomize/customize_cmdline.mli ++++ b/common/mlcustomize/customize_cmdline.mli +@@ -53,6 +53,8 @@ and op = [ + (* --firstboot-install PKG,PKG.. *) + | `Hostname of string + (* --hostname HOSTNAME *) ++ | `InjectBalloonServer of string ++ (* --inject-blnsvr METHOD *) + | `InjectQemuGA of string + (* --inject-qemu-ga METHOD *) + | `InjectVirtioWin of string +diff --git a/common/mlcustomize/inject_virtio_win.ml b/common/mlcustomize/inject_virtio_win.ml +index 2a30b2008..4e0ed0e0e 100644 +--- a/common/mlcustomize/inject_virtio_win.ml ++++ b/common/mlcustomize/inject_virtio_win.ml +@@ -24,6 +24,8 @@ open Common_gettext.Gettext + + open Regedit + ++let re_blnsvr = PCRE.compile ~caseless:true "\\bblnsvr\\.exe$" ++ + type t = { + g : Guestfs.guestfs; (** guestfs handle *) + +@@ -267,6 +269,18 @@ and inject_qemu_ga t = + configure_qemu_ga t msi_files; + msi_files <> [] (* return true if we found some qemu-ga MSI files *) + ++and inject_blnsvr t = ++ let files = copy_blnsvr t in ++ match files with ++ | [] -> false (* Didn't find or install anything. *) ++ ++ (* We usually find blnsvr.exe in two locations (drivers/by-os and ++ * drivers/by-driver). Pick the first. ++ *) ++ | blnsvr :: _ -> ++ configure_blnsvr t blnsvr; ++ true ++ + and add_guestor_to_registry t ((g, root) as reg) drv_name drv_pciid = + let ddb_node = g#hivex_node_get_child root "DriverDatabase" in + +@@ -351,6 +365,11 @@ and copy_qemu_ga t = + (fun () -> + error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log.")) + ++and copy_blnsvr t = ++ copy_from_virtio_win t "/" "/" (virtio_iso_path_matches_blnsvr t) ++ (fun () -> ++ error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log.")) ++ + (* Copy all files from virtio_win directory/ISO located in [srcdir] + * subdirectory and all its subdirectories to the [destdir]. The directory + * hierarchy is not preserved, meaning all files will be directly in [destdir]. +@@ -513,6 +532,10 @@ and virtio_iso_path_matches_qemu_ga t path = + | ("x86_64", "rhev-qga64.msi") -> true + | _ -> false + ++(* Find blnsvr for the current Windows version. *) ++and virtio_iso_path_matches_blnsvr t path = ++ virtio_iso_path_matches_guest_os t path && PCRE.matches re_blnsvr path ++ + (* Look up in libosinfo for the OS, and copy all the locally + * available files specified as drivers for that OS to the [destdir]. + * +@@ -586,3 +609,10 @@ and configure_qemu_ga t files = + Firstboot.add_firstboot_powershell t.g t.root + (sprintf "install-%s.ps1" msi_path) !psh_script; + ) files ++ ++and configure_blnsvr t blnsvr = ++ let cmd = sprintf "\ ++ @echo off\n\ ++ echo Installing %s\n\ ++ c:\\%s -i\n" blnsvr blnsvr in ++ Firstboot.add_firstboot_script t.g t.root (sprintf "install-%s" blnsvr) cmd +diff --git a/common/mlcustomize/inject_virtio_win.mli b/common/mlcustomize/inject_virtio_win.mli +index d14f04973..d273c4dd3 100644 +--- a/common/mlcustomize/inject_virtio_win.mli ++++ b/common/mlcustomize/inject_virtio_win.mli +@@ -93,3 +93,11 @@ val inject_qemu_ga : t -> bool + the MSI(s). + + Returns [true] iff we were able to inject qemu-ga. *) ++ ++val inject_blnsvr : t -> bool ++(** Inject the Balloon Server ([blnsvr.exe]) into a Windows guest. ++ ++ A firstboot script is also injected which should install ++ the server by running [blnsvr -i]. ++ ++ Returns [true] iff we were able to inject the Balloon Server. *) +diff --git a/customize/customize_run.ml b/customize/customize_run.ml +index 1314d6e30..1d7c13eaf 100644 +--- a/customize/customize_run.ml ++++ b/customize/customize_run.ml +@@ -113,8 +113,8 @@ let run (g : G.guestfs) root (ops : ops) = + Hashtbl.replace passwords user pw + in + +- (* Helper function to convert --inject-qemu-ga/--inject-virtio-win +- * method parameter into a virtio-win handle. ++ (* Helper function to convert --inject-blnsvr/--inject-qemu-ga/ ++ * --inject-virtio-win method parameter into a virtio-win handle. + *) + let get_virtio_win_handle op meth = + if g#inspect_get_type root <> "windows" then ( +@@ -216,6 +216,15 @@ let run (g : G.guestfs) root (ops : ops) = + if not (Hostname.set_hostname g root hostname) then + warning (f_"hostname could not be set for this type of guest") + ++ | `InjectBalloonServer meth -> ++ (match get_virtio_win_handle "--inject-blnsvr" meth with ++ | None -> () ++ | Some t -> ++ if not (Inject_virtio_win.inject_blnsvr t) then ++ warning (f_"--inject-blnsvr: blnsvr.exe not found in \ ++ virtio-win source that you specified") ++ ) ++ + | `InjectQemuGA meth -> + (match get_virtio_win_handle "--inject-qemu-ga" meth with + | None -> () diff --git a/0004-Update-common-submodule.patch b/0004-Update-common-submodule.patch new file mode 100644 index 0000000..3189ae8 --- /dev/null +++ b/0004-Update-common-submodule.patch @@ -0,0 +1,344 @@ +From f59b4fcf683f449a7dd1cad3c168f536cc10304a Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 6 Aug 2024 08:51:29 +0100 +Subject: [PATCH] Update common submodule + +Considerable changes have been made in virt-v2v to how powershell +scripts are run in Windows guests, and to qemu-ga installation (also +for Windows). This pulls in the following commits: + +Richard W.M. Jones (10): + mlcustomize: firstboot: Use Linux path for Powershell script path + mlcustomize: firstboot: Use powershell.exe instead of path + mlcustomize: firstboot: Use Powershell -NoProfile flag + mlcustomize: Revert delay installation of qemu-ga MSI + mldrivers/linux_kernels.ml: Prefix general information with ^info: + mlcustomize: Use Start-Process -Wait to run qemu-ga installer + mlcustomize: Add Firstboot.firstboot_dir function + mlcustomize: Place powershell scripts into \Temp + mlcustomize: Inject qemu-ga & blnsvr into /Temp + mlcustomize: Write qemu-ga log file name to log.txt + +(cherry picked from commit b8d57760ea9c9d3ec7a21ee41d74731ab81173df) +--- + common | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Submodule common 830cbdcf4..7b84a370e: +diff --git a/common/mlcustomize/firstboot.ml b/common/mlcustomize/firstboot.ml +index 5dc012340..3bbba714d 100644 +--- a/common/mlcustomize/firstboot.ml ++++ b/common/mlcustomize/firstboot.ml +@@ -239,7 +239,22 @@ WantedBy=%s + end + + module Windows = struct +- let rec install_service (g : Guestfs.guestfs) root = ++ (* Create and return the firstboot directory. *) ++ let create_firstboot_dir (g : Guestfs.guestfs) = ++ let rec loop firstboot_dir firstboot_dir_win = function ++ | [] -> firstboot_dir, firstboot_dir_win ++ | dir :: path -> ++ let firstboot_dir = ++ if firstboot_dir = "" then "/" ^ dir else firstboot_dir // dir in ++ let firstboot_dir_win = firstboot_dir_win ^ "\\" ^ dir in ++ let firstboot_dir = g#case_sensitive_path firstboot_dir in ++ g#mkdir_p firstboot_dir; ++ loop firstboot_dir firstboot_dir_win path ++ in ++ loop "" "C:" ["Program Files"; "Guestfs"; "Firstboot"] ++ ++ let rec install_service (g : Guestfs.guestfs) root ++ firstboot_dir firstboot_dir_win = + (* Either rhsrvany.exe or pvvxsvc.exe must exist. + * + * (Check also that it's not a dangling symlink but a real file). +@@ -254,20 +269,7 @@ module Windows = struct + error (f_"One of rhsrvany.exe or pvvxsvc.exe is missing in %s. One of them is required in order to install Windows firstboot scripts. You can get one by building rhsrvany (https://github.com/rwmjones/rhsrvany)") + (virt_tools_data_dir ()) in + +- (* Create a directory for firstboot files in the guest. *) +- let firstboot_dir, firstboot_dir_win = +- let rec loop firstboot_dir firstboot_dir_win = function +- | [] -> firstboot_dir, firstboot_dir_win +- | dir :: path -> +- let firstboot_dir = +- if firstboot_dir = "" then "/" ^ dir else firstboot_dir // dir in +- let firstboot_dir_win = firstboot_dir_win ^ "\\" ^ dir in +- let firstboot_dir = g#case_sensitive_path firstboot_dir in +- g#mkdir_p firstboot_dir; +- loop firstboot_dir firstboot_dir_win path +- in +- loop "" "C:" ["Program Files"; "Guestfs"; "Firstboot"] in +- ++ (* Create a directory for firstboot scripts in the guest. *) + g#mkdir_p (firstboot_dir // "scripts"); + + (* Copy pvvxsvc or rhsrvany to the guest. *) +@@ -339,11 +341,25 @@ echo uninstalling firstboot service + "PWD", REG_SZ firstboot_dir_win ]; + ] in + reg_import reg regedits +- ); +- +- firstboot_dir ++ ) + end + ++let firstboot_dir (g : Guestfs.guestfs) root = ++ let typ = g#inspect_get_type root in ++ ++ match typ with ++ | "linux" -> ++ let dir = Linux.firstboot_dir in ++ g#mkdir_p dir; ++ dir, None ++ ++ | "windows" -> ++ let dir, dir_win = Windows.create_firstboot_dir g in ++ dir, Some dir_win ++ ++ | _ -> ++ error (f_"guest type %s is not supported") typ ++ + let script_count = ref 0 + + let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = 5000) name +@@ -363,7 +379,8 @@ let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = 5000) name + g#chmod 0o755 filename + + | "windows", _ -> +- let firstboot_dir = Windows.install_service g root in ++ let firstboot_dir, firstboot_dir_win = Windows.create_firstboot_dir g in ++ Windows.install_service g root firstboot_dir firstboot_dir_win; + let filename = firstboot_dir // "scripts" // filename ^ ".bat" in + g#write filename (String.unix2dos content) + +@@ -382,21 +399,18 @@ let add_firstboot_powershell g root ?prio name code = + *) + assert (g#inspect_get_type root = "windows"); + +- let windows_systemroot = g#inspect_get_windows_systemroot root in +- +- (* Create the temporary directory to put the Powershell file. *) +- let tempdir = sprintf "%s/Temp" windows_systemroot in ++ (* Place the Powershell script into firstboot_dir/Temp *) ++ let firstboot_dir, firstboot_dir_win = Windows.create_firstboot_dir g in ++ let tempdir = sprintf "%s/Temp" firstboot_dir in + g#mkdir_p tempdir; ++ ++ let ps_path = sprintf "%s/%s.ps1" tempdir name in ++ let ps_path_win = sprintf "%s\\Temp\\%s.ps1" firstboot_dir_win name in + let code = String.concat "\r\n" code ^ "\r\n" in +- g#write (sprintf "%s/%s" tempdir name) code; ++ g#write ps_path code; + +- (* Powershell interpreter. Should we check this exists? XXX *) +- let ps_exe = +- windows_systemroot ^ +- "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" in +- +- (* Windows path to the Powershell script. *) +- let ps_path = windows_systemroot ^ "\\Temp\\" ^ name in +- +- let fb = sprintf "%s -ExecutionPolicy ByPass -file %s" ps_exe ps_path in ++ (* Create a regular firstboot bat that just invokes powershell *) ++ let fb = ++ sprintf "powershell.exe -ExecutionPolicy ByPass -NoProfile -file \"%s\"" ++ ps_path_win in + add_firstboot_script g root ?prio name fb +diff --git a/common/mlcustomize/firstboot.mli b/common/mlcustomize/firstboot.mli +index 8231af658..34ff06901 100644 +--- a/common/mlcustomize/firstboot.mli ++++ b/common/mlcustomize/firstboot.mli +@@ -16,6 +16,23 @@ + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + ++val firstboot_dir : Guestfs.guestfs -> string -> string * string option ++(** [firstboot_dir g root] ++ returns the path of the firstboot directory, creating it in ++ the guest if necessary. ++ ++ This returns the name of the directory as a guestfs path, and ++ optionally the name as a Windows path (only for Windows guests). ++ ++ For Linux this could be [/usr/lib/virt-sysprep, None] ++ ++ For Windows this could be ["/Program Files/Guestfs/Firstboot", ++ Some "C:\Program Files\Guestfs\Firstboot"] ++ ++ Additional files that are used during firstboot can be placed ++ in this directory, but be careful not to conflict with files ++ and scripts added by the firstboot process itself. *) ++ + val add_firstboot_script : Guestfs.guestfs -> string -> ?prio:int -> string -> + string -> unit + (** [add_firstboot_script g root prio name content] adds a firstboot +diff --git a/common/mlcustomize/inject_virtio_win.ml b/common/mlcustomize/inject_virtio_win.ml +index 4e0ed0e0e..afec1e456 100644 +--- a/common/mlcustomize/inject_virtio_win.ml ++++ b/common/mlcustomize/inject_virtio_win.ml +@@ -263,14 +263,28 @@ let rec inject_virtio_win_drivers ({ g } as t) reg = + } + ) + +-and inject_qemu_ga t = +- let msi_files = copy_qemu_ga t in ++and inject_qemu_ga ({ g; root } as t) = ++ (* Copy the qemu-ga MSI(s) to the guest. *) ++ let dir, dir_win = Firstboot.firstboot_dir g root in ++ let dir_win = Option.value dir_win ~default:dir in ++ let tempdir = sprintf "%s/Temp" dir in ++ let tempdir_win = sprintf "%s\\Temp" dir_win in ++ g#mkdir_p tempdir; ++ ++ let msi_files = copy_qemu_ga t tempdir in + if msi_files <> [] then +- configure_qemu_ga t msi_files; ++ configure_qemu_ga t tempdir_win msi_files; + msi_files <> [] (* return true if we found some qemu-ga MSI files *) + +-and inject_blnsvr t = +- let files = copy_blnsvr t in ++and inject_blnsvr ({ g; root } as t) = ++ (* Copy the files to the guest. *) ++ let dir, dir_win = Firstboot.firstboot_dir g root in ++ let dir_win = Option.value dir_win ~default:dir in ++ let tempdir = sprintf "%s/Temp" dir in ++ let tempdir_win = sprintf "%s\\Temp" dir_win in ++ g#mkdir_p tempdir; ++ ++ let files = copy_blnsvr t tempdir in + match files with + | [] -> false (* Didn't find or install anything. *) + +@@ -278,7 +292,7 @@ and inject_blnsvr t = + * drivers/by-driver). Pick the first. + *) + | blnsvr :: _ -> +- configure_blnsvr t blnsvr; ++ configure_blnsvr t tempdir_win blnsvr; + true + + and add_guestor_to_registry t ((g, root) as reg) drv_name drv_pciid = +@@ -360,13 +374,13 @@ and copy_drivers t driverdir = + (fun () -> + error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log.")) + +-and copy_qemu_ga t = +- copy_from_virtio_win t "/" "/" (virtio_iso_path_matches_qemu_ga t) ++and copy_qemu_ga t tempdir = ++ copy_from_virtio_win t "/" tempdir (virtio_iso_path_matches_qemu_ga t) + (fun () -> + error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log.")) + +-and copy_blnsvr t = +- copy_from_virtio_win t "/" "/" (virtio_iso_path_matches_blnsvr t) ++and copy_blnsvr t tempdir = ++ copy_from_virtio_win t "/" tempdir (virtio_iso_path_matches_blnsvr t) + (fun () -> + error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log.")) + +@@ -575,44 +589,35 @@ and copy_from_libosinfo { g; i_osinfo; i_arch } destdir = + ) driver.Libosinfo.files + with Not_found -> [] + +-and configure_qemu_ga t files = ++(* Install qemu-ga. [files] is the non-empty list of possible qemu-ga ++ * installers we detected. ++ *) ++and configure_qemu_ga t tempdir_win files = ++ let script = ref [] in ++ let add = List.push_back script in ++ ++ add "# Virt-v2v script which installs QEMU Guest Agent"; ++ add ""; ++ add "# Uncomment this line for lots of debug output."; ++ add "# Set-PSDebug -Trace 2"; ++ add ""; ++ add "Write-Host Installing QEMU Guest Agent"; ++ add ""; ++ add "# Run qemu-ga installers"; + List.iter ( +- fun msi_path -> +- (* Windows is a trashfire. +- * https://stackoverflow.com/a/18730884 +- * https://bugzilla.redhat.com/show_bug.cgi?id=1895323 +- *) +- let psh_script = ref [] in +- let add = List.push_back psh_script in ++ fun msi -> ++ add (sprintf "Write-Host \"Writing log to %s\\%s.log\"" ++ tempdir_win msi); ++ (* [`] is an escape char for quotes *) ++ add (sprintf "Start-Process -Wait -FilePath \"%s\\%s\" -ArgumentList \"/norestart\",\"/qn\",\"/l+*vx\",\"`\"%s\\%s.log`\"\"" ++ tempdir_win msi tempdir_win msi) ++ ) files; + +- add "# Uncomment this line for lots of debug output."; +- add "# Set-PSDebug -Trace 2"; +- add ""; +- add "Write-Host Removing any previously scheduled qemu-ga installation"; +- add "schtasks.exe /Delete /TN Firstboot-qemu-ga /F"; +- add ""; +- add (sprintf +- "Write-Host Scheduling delayed installation of qemu-ga from %s" +- msi_path); +- add "$d = (get-date).AddSeconds(120)"; +- add "$dtfinfo = [System.Globalization.DateTimeFormatInfo]::CurrentInfo"; +- add "$sdp = $dtfinfo.ShortDatePattern"; +- add "$sdp = $sdp -replace 'y+', 'yyyy'"; +- add "$sdp = $sdp -replace 'M+', 'MM'"; +- add "$sdp = $sdp -replace 'd+', 'dd'"; +- add "schtasks.exe /Create /SC ONCE `"; +- add " /ST $d.ToString('HH:mm') /SD $d.ToString($sdp) `"; +- add " /RU SYSTEM /TN Firstboot-qemu-ga `"; +- add (sprintf " /TR \"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\"" +- msi_path msi_path); ++ Firstboot.add_firstboot_powershell t.g t.root "install-qemu-ga" !script + +- Firstboot.add_firstboot_powershell t.g t.root +- (sprintf "install-%s.ps1" msi_path) !psh_script; +- ) files +- +-and configure_blnsvr t blnsvr = ++and configure_blnsvr t tempdir_win blnsvr = + let cmd = sprintf "\ + @echo off\n\ + echo Installing %s\n\ +- c:\\%s -i\n" blnsvr blnsvr in +- Firstboot.add_firstboot_script t.g t.root (sprintf "install-%s" blnsvr) cmd ++ \"%s\\%s\" -i\n" blnsvr tempdir_win blnsvr in ++ Firstboot.add_firstboot_script t.g t.root "install-blnsvr" cmd +diff --git a/common/mldrivers/linux_kernels.ml b/common/mldrivers/linux_kernels.ml +index 23ff76a55..e0b6b8a00 100644 +--- a/common/mldrivers/linux_kernels.ml ++++ b/common/mldrivers/linux_kernels.ml +@@ -102,7 +102,7 @@ let detect_kernels (g : G.guestfs) root bootloader apps = + ) apps in + if verbose () then ( + let names = List.map (fun { G.app2_name = name } -> name) kernel_pkgs in +- eprintf "candidate kernel packages in this guest: %s%!\n" ++ eprintf "info: candidate kernel packages in this guest: %s%!\n" + (String.concat " " names) + ); + List.filter_map ( +@@ -306,7 +306,7 @@ let detect_kernels (g : G.guestfs) root bootloader apps = + ) kernel_pkgs in + + if verbose () then ( +- eprintf "installed kernel packages in this guest:\n"; ++ eprintf "info: installed kernel packages in this guest:\n"; + List.iter (print_kernel_info stderr "\t") installed_kernels; + flush stderr + ); +@@ -343,7 +343,7 @@ let detect_kernels (g : G.guestfs) root bootloader apps = + ) vmlinuzes in + + if verbose () then ( +- eprintf "kernels offered by the bootloader in this guest (first in list is default):\n"; ++ eprintf "info: kernels offered by the bootloader in this guest (first in list is default):\n"; + List.iter (print_kernel_info stderr "\t") bootloader_kernels; + flush stderr + ); diff --git a/0005-Update-common-submodule.patch b/0005-Update-common-submodule.patch new file mode 100644 index 0000000..e536917 --- /dev/null +++ b/0005-Update-common-submodule.patch @@ -0,0 +1,57 @@ +From 7cffcb71c393da2ee636eb8bc9360bf83f5066f5 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sat, 10 Aug 2024 14:17:51 +0100 +Subject: [PATCH] Update common submodule + +Further refinements to Windows firstboot code. + +Richard W.M. Jones (2): + mlcustomize: Add some comments to firstboot batch file + mlcustomize: Reboot Windows between each firstboot script + +(cherry picked from commit d7719d6954f48c3a395da7486bcf55fbac66ea07) +--- + common | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Submodule common 7b84a370e..a78839676: +diff --git a/common/mlcustomize/firstboot.ml b/common/mlcustomize/firstboot.ml +index 3bbba714d..52e76401e 100644 +--- a/common/mlcustomize/firstboot.ml ++++ b/common/mlcustomize/firstboot.ml +@@ -278,6 +278,9 @@ module Windows = struct + (* Write a firstboot.bat control script which just runs the other + * scripts in the directory. Note we need to use CRLF line endings + * in this script. ++ * ++ * XXX It would be better to use powershell here. For some ideas see ++ * https://github.com/HCK-CI/HLK-Setup-Scripts/ + *) + let firstboot_script = sprintf "\ + @echo off +@@ -299,6 +302,7 @@ if not exist \"%%scripts_done%%\" ( + mkdir \"%%scripts_done%%\" + ) + ++:: Pick the next script to run. + for %%%%f in (\"%%scripts%%\"\\*.bat) do ( + echo running \"%%%%f\" + move \"%%%%f\" \"%%scripts_done%%\" +@@ -307,8 +311,17 @@ for %%%%f in (\"%%scripts%%\"\\*.bat) do ( + set elvl=!errorlevel! + echo .... exit code !elvl! + popd ++ ++ :: Reboot the computer. This is necessary to free any locked ++ :: files which may prevent later scripts from running. ++ shutdown /r /t 0 /y ++ ++ :: Exit the script (in case shutdown returns before rebooting). ++ :: On next boot, the whole firstboot service will be called again. ++ exit /b + ) + ++:: Fallthrough here if there are no scripts. + echo uninstalling firstboot service + \"%%firstboot%%\\%s\" -s firstboot uninstall + " firstboot_dir_win srvany in diff --git a/copy-patches.sh b/copy-patches.sh new file mode 100755 index 0000000..57ccf1f --- /dev/null +++ b/copy-patches.sh @@ -0,0 +1,65 @@ +#!/bin/bash - + +set -e + +# Maintainer script to copy patches from the git repo to the current +# directory. Use it like this: +# ./copy-patches.sh + +project=guestfs-tools +rhel_version=10.0 + +# Check we're in the right directory. +if [ ! -f $project.spec ]; then + echo "$0: run this from the directory containing '$project.spec'" + exit 1 +fi + +case `id -un` in + rjones) git_checkout=$HOME/d/$project-rhel-$rhel_version ;; + lacos) git_checkout=$HOME/src/v2v/$project ;; + *) git_checkout=$HOME/d/$project-rhel-$rhel_version ;; +esac +if [ ! -d $git_checkout ]; then + echo "$0: $git_checkout does not exist" + echo "This script is only for use by the maintainer when preparing a" + echo "$project release on RHEL." + exit 1 +fi + +# Get the base version of the project. +version=`grep '^Version:' $project.spec | awk '{print $2}'` +tag="v$version" + +# Remove any existing patches. +git rm -f [0-9]*.patch ||: +rm -f [0-9]*.patch + +# Get the patches. +( + cd $git_checkout + rm -f [0-9]*.patch + git -c core.abbrev=9 format-patch -O/dev/null --subject-prefix=PATCH -N \ + --submodule=diff --no-signature --patience $tag +) +mv $git_checkout/[0-9]*.patch . + +# Remove any not to be applied. +rm -f *NOT-FOR-RPM*.patch + +# Add the patches. +git add [0-9]*.patch + +# Print out the patch lines. +echo +echo "--- Copy the following text into $project.spec file" +echo + +echo "# Patches." +for f in [0-9]*.patch; do + n=`echo $f | awk -F- '{print $1}'` + echo "Patch$n: $f" +done + +echo +echo "--- End of text" diff --git a/guestfs-tools.spec b/guestfs-tools.spec index 50cc528..b398490 100644 --- a/guestfs-tools.spec +++ b/guestfs-tools.spec @@ -18,8 +18,8 @@ Summary: Tools to access and modify virtual machine disk images Name: guestfs-tools -Version: 1.52.0 -Release: 6%{?dist} +Version: 1.52.1 +Release: 1%{?dist} License: GPL-2.0-or-later AND LGPL-2.0-or-later # Build only for architectures that have a kernel @@ -41,9 +41,18 @@ Source1: http://download.libguestfs.org/guestfs-tools/%{source_directory}/ Source2: libguestfs.keyring %endif -# Upstream patches since 1.52.0 was released: -Patch: 0001-Move-the-repository-to-https-github.com-libguestfs-g.patch -Patch: 0002-builder-Add-a-test-of-the-chown-parameter.patch +# Maintainer script which helps with handling patches. +Source3: copy-patches.sh + +# Patches are maintained in the following repository: +# https://github.com/rwmjones/guestfs-tools/commits/rhel-10.0 + +# Patches. +Patch0001: 0001-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch +Patch0002: 0002-RHEL-builder-Disable-opensuse-repository.patch +Patch0003: 0003-customize-Implement-inject-blnsvr-operation.patch +Patch0004: 0004-Update-common-submodule.patch +Patch0005: 0005-Update-common-submodule.patch %if 0%{patches_touch_autotools} BuildRequires: autoconf, automake, libtool, gettext-devel @@ -402,6 +411,16 @@ end %changelog +* Tue Aug 27 2024 Richard W.M. Jones - 1.52.1-1 +- New stable version 1.52.1 +- Rebase on top of patches from RHEL 9.5 +- Reboot Windows between each firstboot script to improve reliability + resolves: RHEL-56319 +- customize: Implement --inject-blnsvr operation + resolves: RHEL-56330 +- Add support for nbd+unix:// URIs + resolves: RHEL-56332 + * Tue Jun 25 2024 Troy Dawson - 1.52.0-6 - Bump release for June 2024 mass rebuild diff --git a/sources b/sources index 0831c62..bab9436 100644 --- a/sources +++ b/sources @@ -1,2 +1,2 @@ -SHA512 (guestfs-tools-1.52.0.tar.gz) = afef6163c9005ca9fab5aa414c9b73f08f5c6403448b9a513c56eb2f15e9d3a3444046c5a1677fbd7334189cc7739545dff8412a85cb896bc46a44b42e0d0172 -SHA512 (guestfs-tools-1.52.0.tar.gz.sig) = 5586c7a536f58e7690b93027e6dc67c3077fed35b2972e24a697e1772722f09f5038a202860a7312e80a12533ef8f1a09f72089ea6646ca2eb43a785dd72066f +SHA512 (guestfs-tools-1.52.1.tar.gz) = 0db4b6cc49b18d26cb9a3a1e8f76fcb16127d41fac65b2e6e40e823b697a5581be0b85d54d2a36dbf4e45aea72ecddfc2cf6d198093c8cc52ce1a2712cc26d25 +SHA512 (guestfs-tools-1.52.1.tar.gz.sig) = 8fde96929e1f868aa5e4d76d08c899300d2b0dba7ab413c65cd9ae2e97a46426acddeede1be99a937e57cf5e5706463c21a071862e5df7add85c615123d1634c