Some filesystems fall back silently to read-only if there are problems
such a dirty filesystem and an unrecoverable journal. Almost all
conversions involve writing to the root filesystem, so these will
inevitably fail later on with a strange error message.
Test the root filesystem is writable by creating and deleting a
temporary file, and if the creation fails then give better
diagnostics.
Reported-by: Piotr Kliczewski
---
generator/OCaml.ml | 1 +
v2v/inspect_source.ml | 37 +++++++++++++++++++++++++++----------
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/generator/OCaml.ml b/generator/OCaml.ml
index e58f387cc..467a1f0d8 100644
--- a/generator/OCaml.ml
+++ b/generator/OCaml.ml
@@ -40,6 +40,7 @@ let ocaml_errnos = [
"EPERM";
"ESRCH";
"ENOENT";
+ "EROFS";
]
(* Generate the OCaml bindings interface. *)
diff --git a/v2v/inspect_source.ml b/v2v/inspect_source.ml
index bd382cb11..c1a7e5737 100644
--- a/v2v/inspect_source.ml
+++ b/v2v/inspect_source.ml
@@ -41,16 +41,33 @@ let rec inspect_source root_choice g =
let mps = List.sort cmp mps in
List.iter (
fun (mp, dev) ->
- try g#mount dev mp
- with G.Error msg ->
- if mp = "/" then ( (* RHBZ#1145995 *)
- if String.find msg "Windows" >= 0 && String.find msg
"NTFS partition is in an unsafe state" >= 0 then
- error (f_"unable to mount the disk image for writing. This has probably
happened because Windows Hibernation or Fast Restart is being used in this guest. You have
to disable this (in the guest) in order to use virt-v2v.\n\nOriginal error message:
%s") msg
- else
- error "%s" msg
- )
- else
- warning (f_"%s (ignored)") msg
+ (try g#mount dev mp
+ with G.Error msg ->
+ if mp = "/" then ( (* RHBZ#1145995 *)
+ if String.find msg "Windows" >= 0 && String.find msg
"NTFS partition is in an unsafe state" >= 0 then
+ error (f_"unable to mount the disk image for writing. This has probably
happened because Windows Hibernation or Fast Restart is being used in this guest. You have
to disable this (in the guest) in order to use virt-v2v.\n\nOriginal error message:
%s") msg
+ else
+ error "%s" msg
+ )
+ else
+ warning (f_"%s (ignored)") msg
+ );
+
+ (* Some filesystems (hello, ntfs-3g) can silently fall back to
+ * a read-only mount. Check the root filesystem is really writable.
+ * RHBZ#1567763
+ *)
+ if mp = "/" then (
+ let file = sprintf "/%s" (String.random8 ()) in
+ (try g#touch file
+ with G.Error msg ->
+ if g#last_errno () = G.Errno.errno_EROFS then
+ error (f_"filesystem was mounted read-only, even though we asked for it
to be mounted read-write. This usually means that the filesystem was not cleanly
unmounted. Possible causes include trying to convert a guest which is running, or using
Windows Hibernation or Fast Restart.\n\nOriginal error message: %s") msg
+ else
+ error (f_"could not write to the guest filesystem: %s") msg
+ );
+ g#rm file
+ )
) mps;
(* Get list of applications/packages installed. *)
--
2.16.2