[PATCH 2/2] v2v: ilnux: detect name of grub2-mkconfig
by Tomáš Golembiovský
On Debian family of OSes Grub2 tools are prefixed with 'grub-', not with
'grub2-'. We have to detect the correct name of the tool to use it.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/linux_bootloaders.ml | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
index a5e4c8d..0729f17 100644
--- a/v2v/linux_bootloaders.ml
+++ b/v2v/linux_bootloaders.ml
@@ -189,6 +189,22 @@ class bootloader_grub2 (g : G.guestfs) grub_config =
object (self)
inherit bootloader
+ method private grub2_mkconfig_cmd =
+ let elems = [
+ "/sbin/grub2-mkconfig";
+ "/usr/sbin/grub2-mkconfig";
+ "/sbin/grub-mkconfig"
+ "/usr/sbin/grub-mkconfig"
+ ] in
+ try
+ List.find (
+ let e ->
+ try g#is_file ~followsymlinks:true e
+ with G.Error _ -> false
+ ) elems
+ with Not_found ->
+ error (f_"failed to find grub2-mkconfig binary (but Grub2 was detected on guest)")
+
method private grub2_update_console ~remove () =
let rex = Str.regexp "\\(.*\\)\\bconsole=[xh]vc0\\b\\(.*\\)" in
@@ -218,7 +234,7 @@ object (self)
g#aug_save ();
try
- ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |])
+ ignore (g#command [| grub2_mkconfig_cmd; "-o"; grub_config |])
with
G.Error msg ->
warning (f_"could not rebuild grub2 configuration file (%s). This may mean that grub output will not be sent to the serial port, but otherwise should be harmless. Original error message: %s")
@@ -290,7 +306,7 @@ object (self)
method remove_console = self#grub2_update_console ~remove:true
method update () =
- ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |])
+ ignore (g#command [| grub2_mkconfig_cmd; "-o"; grub_config |])
end
let detect_bootloader (g : G.guestfs) inspect =
--
2.9.3
8 years, 1 month
[PATCH] v2v: ova: Make OVA directory public readable to work around libvirt bug (RHBZ#1375157).
by Richard W.M. Jones
Only do this if running as root and if the backend is set
to libvirt.
---
v2v/input_ova.ml | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index 4f848e2..bb9cb1b 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -104,6 +104,19 @@ object
(* Exploded path must be absolute (RHBZ#1155121). *)
let exploded = absolute_path exploded in
+ (* If virt-v2v is running as root, and the backend is libvirt, then
+ * we have to chmod the directory to 0755 and files to 0644
+ * so it is readable by qemu.qemu. This is libvirt bug RHBZ#890291.
+ *)
+ if Unix.geteuid () = 0 then (
+ let libguestfs_backend = (open_guestfs ())#get_backend () in
+ if libguestfs_backend = "libvirt" then (
+ warning (f_"making OVA directory public readable to workaround libvirt bug https://bugzilla.redhat.com/890291");
+ let cmd = [ "chmod"; "-R"; "go=u,go-w"; exploded ] in
+ ignore (run_command cmd)
+ )
+ );
+
(* Find files in [dir] ending with [ext]. *)
let find_files dir ext =
let rec loop = function
--
2.7.4
8 years, 1 month
[PATCH 0/2] *** SUBJECT HERE ***
by Tomáš Golembiovský
*** BLURB HERE ***
Tomáš Golembiovský (2):
v2v: linux: correctly reconfigure the initrd on Debian
v2v: ilnux: detect name of grub2-mkconfig
v2v/convert_linux.ml | 21 +++++++++++++++++++++
v2v/linux_bootloaders.ml | 20 ++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
v1 -> v2:
- rebased to current master
- using list as Pino suggested when searching for grub2-mkconfig
--
2.9.3
8 years, 1 month
[PATCH 1/2] v2v: linux: correctly reconfigure the initrd on Debian
by Tomáš Golembiovský
Using update-initramfs is the native way of updating initrd on Debian
based systems.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/convert_linux.ml | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 08f4b2a..b09d03e 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -478,6 +478,15 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
ignore (g#command (Array.of_list args))
in
+ let run_update_initramfs_command () =
+ let args =
+ "/usr/sbin/update-initramfs" ::
+ (if verbose () then [ "-v" ] else [])
+ @ [ "-c"; "-k"; mkinitrd_kv ]
+ in
+ ignore (g#command (Array.of_list args))
+ in
+
if g#is_file ~followsymlinks:true "/sbin/dracut" then
run_dracut_command "/sbin/dracut"
else if g#is_file ~followsymlinks:true "/usr/bin/dracut" then
@@ -491,6 +500,18 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
"-k"; kernel.ki_vmlinuz |]
)
)
+ else if family = `Debian_family then (
+ if not (g#is_file ~followsymlinks:true "/usr/sbin/update-initramfs") then
+ error (f_"unable to rebuild initrd (%s) because update-initramfs was not found in the guest")
+ initrd;
+
+ (* The modules to add to initrd are defined in a file. *)
+ let modules = String.concat "\n" modules in
+ let modules = "#\n# Added by virt-v2v\n" ^ modules ^ "\n" in
+ ignore (g#write_append "/etc/initramfs-tools/modules" modules);
+
+ run_update_initramfs_command ()
+ )
else if g#is_file ~followsymlinks:true "/sbin/mkinitrd" then (
let module_args = List.map (sprintf "--with=%s") modules in
let args =
--
2.9.3
8 years, 1 month
[PATCH 1/2] v2v: linux: Avoid recursive functions.
by Richard W.M. Jones
Just code motion.
---
v2v/convert_linux.ml | 68 +++++++++++++++++++++++++++-------------------------
1 file changed, 36 insertions(+), 32 deletions(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 7bc1dde..3fd58ce 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -78,7 +78,7 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
(*----------------------------------------------------------------------*)
(* Conversion step. *)
- let rec augeas_grub_configuration () =
+ let augeas_grub_configuration () =
if bootloader#set_augeas_configuration () then
Linux.augeas_reload g
@@ -675,6 +675,41 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
and configure_kernel_modules block_type net_type =
(* This function modifies modules.conf (and its various aliases). *)
+ let augeas_modprobe query =
+ (* Execute g#aug_match, but against every known location of
+ modules.conf. *)
+ let paths = [
+ "/files/etc/conf.modules/alias";
+ "/files/etc/modules.conf/alias";
+ "/files/etc/modprobe.conf/alias";
+ "/files/etc/modprobe.d/*/alias";
+ ] in
+ let paths =
+ List.map (
+ fun p ->
+ let p = sprintf "%s[%s]" p query in
+ Array.to_list (g#aug_match p)
+ ) paths in
+ List.flatten paths
+
+ and discover_modpath () =
+ (* Find what /etc/modprobe.conf is called today. *)
+ if g#is_dir ~followsymlinks:true "/etc/modprobe.d" then (
+ (* Create a new file /etc/modprobe.d/virt-v2v-added.conf. *)
+ "/etc/modprobe.d/virt-v2v-added.conf"
+ ) else (
+ (* List of methods, in order of preference. *)
+ let paths = [
+ "/etc/modprobe.conf";
+ "/etc/modules.conf";
+ "/etc/conf.modules"
+ ] in
+ try List.find (g#is_file ~followsymlinks:true) paths
+ with Not_found ->
+ error (f_"unable to find any valid modprobe configuration file such as /etc/modprobe.conf");
+ )
+ in
+
(* Update 'alias eth0 ...'. *)
let paths = augeas_modprobe ". =~ regexp('eth[0-9]+')" in
let net_device =
@@ -744,37 +779,6 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
(* Update files. *)
g#aug_save ()
- and augeas_modprobe query =
- (* Execute g#aug_match, but against every known location of modules.conf. *)
- let paths = [
- "/files/etc/conf.modules/alias";
- "/files/etc/modules.conf/alias";
- "/files/etc/modprobe.conf/alias";
- "/files/etc/modprobe.d/*/alias";
- ] in
- let paths =
- List.map (
- fun p ->
- let p = sprintf "%s[%s]" p query in
- Array.to_list (g#aug_match p)
- ) paths in
- List.flatten paths
-
- and discover_modpath () =
- (* Find what /etc/modprobe.conf is called today. *)
- if g#is_dir ~followsymlinks:true "/etc/modprobe.d" then (
- (* Create a new file /etc/modprobe.d/virt-v2v-added.conf. *)
- "/etc/modprobe.d/virt-v2v-added.conf"
- ) else (
- (* List of methods, in order of preference. *)
- let paths = [ "/etc/modprobe.conf"; "/etc/modules.conf"; "/etc/conf.modules" ] in
-
- try
- List.find (g#is_file ~followsymlinks:true) paths
- with Not_found ->
- error (f_"unable to find any valid modprobe configuration file such as /etc/modprobe.conf");
- )
-
and remap_block_devices block_type =
(* This function's job is to iterate over boot configuration
* files, replacing "hda" with "vda" or whatever is appropriate.
--
2.9.3
8 years, 1 month
[PATCH] v2v: utils: Replace "remove_duplicates" function with call to sort_uniq.
by Richard W.M. Jones
---
v2v/linux_bootloaders.ml | 2 +-
v2v/utils.ml | 9 ---------
v2v/utils.mli | 3 ---
3 files changed, 1 insertion(+), 13 deletions(-)
diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
index a5e4c8d..7c48480 100644
--- a/v2v/linux_bootloaders.ml
+++ b/v2v/linux_bootloaders.ml
@@ -76,7 +76,7 @@ object
let paths = Array.to_list paths in
(* Remove duplicates. *)
- let paths = remove_duplicates paths in
+ let paths = sort_uniq paths in
(* Get the default kernel from grub if it's set. *)
let default =
diff --git a/v2v/utils.ml b/v2v/utils.ml
index ec69abb..6e68583 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -79,15 +79,6 @@ let compare_app2_versions app1 app2 =
compare_version app1.Guestfs.app2_release app2.Guestfs.app2_release
)
-let remove_duplicates xs =
- let h = Hashtbl.create (List.length xs) in
- let rec loop = function
- | [] -> []
- | x :: xs when Hashtbl.mem h x -> xs
- | x :: xs -> Hashtbl.add h x true; x :: loop xs
- in
- loop xs
-
let du filename =
(* There's no OCaml binding for st_blocks, so run coreutils 'du'. *)
let cmd =
diff --git a/v2v/utils.mli b/v2v/utils.mli
index bea9cf3..7f57eec 100644
--- a/v2v/utils.mli
+++ b/v2v/utils.mli
@@ -38,9 +38,6 @@ val find_uefi_firmware : string -> Uefi.uefi_firmware
val compare_app2_versions : Guestfs.application2 -> Guestfs.application2 -> int
(** Compare two app versions. *)
-val remove_duplicates : 'a list -> 'a list
-(** Remove duplicates from a list. *)
-
val du : string -> int64
(** Return the true size of a file in bytes, including any wasted
space caused by internal fragmentation (the overhead of using
--
2.9.3
8 years, 1 month
[PATCH] tests: do not assume '.' is in Perl's @INC
by Pino Toscano
Upstream Perl is going to remove '.' from @INC (the include path for
modules) by default for the next major release (= 5.26) [1], as measure
to fix security issues. Debian already started backporting the fixes
for this [2], thus behaving this way in current Sid installations.
Since the affected Perl sources are only the local daemon testing
scripts, a simple fix is to force the 'requires' for the local
captive-daemon.pm module to start from the current directory: this way
there is no need to manually augment @INC, and only our local module is
loaded automatically.
[1] https://rt.perl.org/Public/Bug/Display.html?id=127810
[2] https://lists.debian.org/debian-devel-announce/2016/08/msg00013.html
---
tests/daemon/test-btrfs.pl | 2 +-
tests/daemon/test-daemon-start.pl | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/daemon/test-btrfs.pl b/tests/daemon/test-btrfs.pl
index 302ecb9..7b306b7 100755
--- a/tests/daemon/test-btrfs.pl
+++ b/tests/daemon/test-btrfs.pl
@@ -23,7 +23,7 @@ use warnings;
use File::Temp qw/tempdir/;
-require 'captive-daemon.pm';
+require './captive-daemon.pm';
# Set $PATH to include directory that will have phony 'btrfs' binary.
my $bindir = tempdir (CLEANUP => 1);
diff --git a/tests/daemon/test-daemon-start.pl b/tests/daemon/test-daemon-start.pl
index 8cc59d9..93e0b24 100755
--- a/tests/daemon/test-daemon-start.pl
+++ b/tests/daemon/test-daemon-start.pl
@@ -21,7 +21,7 @@
use strict;
use warnings;
-require 'captive-daemon.pm';
+require './captive-daemon.pm';
sub tests {
my $g = shift;
--
2.7.4
8 years, 1 month
[PATCH] daemon: Use reply_with_error instead of *_perror for setfiles command.
by Richard W.M. Jones
Fixes commit 9d205f1c284a69390907120ca44f5c723fecc244.
---
daemon/selinux-relabel.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon/selinux-relabel.c b/daemon/selinux-relabel.c
index daafe9e..cfc4cf8 100644
--- a/daemon/selinux-relabel.c
+++ b/daemon/selinux-relabel.c
@@ -92,7 +92,7 @@ do_selinux_relabel (const char *specfile, const char *path,
ADD_ARG (argv, i, NULL);
if (commandv (NULL, &err, argv) == -1) {
- reply_with_perror ("%s", err);
+ reply_with_error ("%s", err);
return -1;
}
--
2.7.4
8 years, 1 month