|
|
e76f14 |
From 44afd4c1f26379b32f62690cf19e06022cafa994 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Thu, 2 Jun 2016 14:51:12 +0100
|
|
|
e76f14 |
Subject: [PATCH] builder: Warn if --output is a host partition (RHBZ#1342337).
|
|
|
e76f14 |
|
|
|
e76f14 |
But allow the warning to be turned off using --no-warn-if-partition.
|
|
|
e76f14 |
|
|
|
e76f14 |
Ming Xie tried to create a bootable USB key using
|
|
|
e76f14 |
'virt-p2v-make-disk -o /dev/sdX1'. That works, but doesn't create a
|
|
|
e76f14 |
bootable key because it puts everything into the first partition.
|
|
|
e76f14 |
|
|
|
e76f14 |
Emit a warning if someone tries to do this to try to prevent user
|
|
|
e76f14 |
error:
|
|
|
e76f14 |
|
|
|
e76f14 |
virt-builder: warning: output device (/dev/sdb1) is a partition. If you
|
|
|
e76f14 |
are writing to a USB key or external drive then you probably need to write
|
|
|
e76f14 |
to the whole device, not to a partition. If this warning is wrong then you
|
|
|
e76f14 |
can disable it with --no-warn-if-partition
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 7274f11ad408bcd4299ba82b3b26f46e62930d03)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
builder/builder.ml | 9 +++++++++
|
|
|
e76f14 |
builder/cmdline.ml | 6 ++++++
|
|
|
e76f14 |
builder/cmdline.mli | 1 +
|
|
|
e76f14 |
builder/virt-builder.pod | 9 +++++++++
|
|
|
e76f14 |
4 files changed, 25 insertions(+)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/builder/builder.ml b/builder/builder.ml
|
|
|
e76f14 |
index a6f92c7..ac4c748 100644
|
|
|
e76f14 |
--- a/builder/builder.ml
|
|
|
e76f14 |
+++ b/builder/builder.ml
|
|
|
e76f14 |
@@ -268,6 +268,15 @@ let main () =
|
|
|
e76f14 |
|
|
|
e76f14 |
(* --- If we get here, we want to create a guest. --- *)
|
|
|
e76f14 |
|
|
|
e76f14 |
+ (* Warn if the user might be writing to a partition on a USB key. *)
|
|
|
e76f14 |
+ (match cmdline.output with
|
|
|
e76f14 |
+ | Some device when is_partition device ->
|
|
|
e76f14 |
+ if cmdline.warn_if_partition then
|
|
|
e76f14 |
+ warning (f_"output device (%s) is a partition. If you are writing to a USB key or external drive then you probably need to write to the whole device, not to a partition. If this warning is wrong then you can disable it with --no-warn-if-partition")
|
|
|
e76f14 |
+ device;
|
|
|
e76f14 |
+ | Some _ | None -> ()
|
|
|
e76f14 |
+ );
|
|
|
e76f14 |
+
|
|
|
e76f14 |
(* Download the template, or it may be in the cache. *)
|
|
|
e76f14 |
let template =
|
|
|
e76f14 |
let template, delete_on_exit =
|
|
|
e76f14 |
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
|
|
|
e76f14 |
index 4893cbf..5205fe6 100644
|
|
|
e76f14 |
--- a/builder/cmdline.ml
|
|
|
e76f14 |
+++ b/builder/cmdline.ml
|
|
|
e76f14 |
@@ -51,6 +51,7 @@ type cmdline = {
|
|
|
e76f14 |
smp : int option;
|
|
|
e76f14 |
sources : (string * string) list;
|
|
|
e76f14 |
sync : bool;
|
|
|
e76f14 |
+ warn_if_partition : bool;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
let parse_cmdline () =
|
|
|
e76f14 |
@@ -115,6 +116,7 @@ let parse_cmdline () =
|
|
|
e76f14 |
let add_source arg = push_front arg sources in
|
|
|
e76f14 |
|
|
|
e76f14 |
let sync = ref true in
|
|
|
e76f14 |
+ let warn_if_partition = ref true in
|
|
|
e76f14 |
|
|
|
e76f14 |
let argspec = [
|
|
|
e76f14 |
"--arch", Arg.Set_string arch, "arch" ^ " " ^ s_"Set the output architecture";
|
|
|
e76f14 |
@@ -163,6 +165,8 @@ let parse_cmdline () =
|
|
|
e76f14 |
"--smp", Arg.Int set_smp, "vcpus" ^ " " ^ s_"Set number of vCPUs";
|
|
|
e76f14 |
"--source", Arg.String add_source, "URL" ^ " " ^ s_"Set source URL";
|
|
|
e76f14 |
"--no-sync", Arg.Clear sync, " " ^ s_"Do not fsync output file on exit";
|
|
|
e76f14 |
+ "--no-warn-if-partition", Arg.Clear warn_if_partition,
|
|
|
e76f14 |
+ " " ^ s_"Do not warn if writing to a partition";
|
|
|
e76f14 |
] in
|
|
|
e76f14 |
let customize_argspec, get_customize_ops = Customize_cmdline.argspec () in
|
|
|
e76f14 |
let customize_argspec =
|
|
|
e76f14 |
@@ -212,6 +216,7 @@ read the man page virt-builder(1).
|
|
|
e76f14 |
let smp = !smp in
|
|
|
e76f14 |
let sources = List.rev !sources in
|
|
|
e76f14 |
let sync = !sync in
|
|
|
e76f14 |
+ let warn_if_partition = !warn_if_partition in
|
|
|
e76f14 |
|
|
|
e76f14 |
(* No arguments and machine-readable mode? Print some facts. *)
|
|
|
e76f14 |
if args = [] && machine_readable then (
|
|
|
e76f14 |
@@ -323,4 +328,5 @@ read the man page virt-builder(1).
|
|
|
e76f14 |
gpg = gpg; list_format = list_format; memsize = memsize;
|
|
|
e76f14 |
network = network; ops = ops; output = output;
|
|
|
e76f14 |
size = size; smp = smp; sources = sources; sync = sync;
|
|
|
e76f14 |
+ warn_if_partition = warn_if_partition;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
diff --git a/builder/cmdline.mli b/builder/cmdline.mli
|
|
|
e76f14 |
index 4c201dd..854db61 100644
|
|
|
e76f14 |
--- a/builder/cmdline.mli
|
|
|
e76f14 |
+++ b/builder/cmdline.mli
|
|
|
e76f14 |
@@ -39,6 +39,7 @@ type cmdline = {
|
|
|
e76f14 |
smp : int option;
|
|
|
e76f14 |
sources : (string * string) list;
|
|
|
e76f14 |
sync : bool;
|
|
|
e76f14 |
+ warn_if_partition : bool;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
val parse_cmdline : unit -> cmdline
|
|
|
e76f14 |
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
|
|
|
e76f14 |
index 545b134..94ba430 100644
|
|
|
e76f14 |
--- a/builder/virt-builder.pod
|
|
|
e76f14 |
+++ b/builder/virt-builder.pod
|
|
|
e76f14 |
@@ -495,6 +495,15 @@ Note that you should not point I<--source> to sources that you don't
|
|
|
e76f14 |
trust (unless the source is signed by someone you do trust). See also
|
|
|
e76f14 |
the I<--no-network> option.
|
|
|
e76f14 |
|
|
|
e76f14 |
+=item B<--no-warn-if-partition>
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+Do not emit a warning if the output device is a partition. This
|
|
|
e76f14 |
+warning avoids a common user error when writing to a USB key or
|
|
|
e76f14 |
+external drive, when you should normally write to the whole device
|
|
|
e76f14 |
+(S<I<--output /dev/sdX>>), not to a partition on the device
|
|
|
e76f14 |
+(S<I<--output /dev/sdX1>>). Use this option to I<suppress> this
|
|
|
e76f14 |
+warning.
|
|
|
e76f14 |
+
|
|
|
e76f14 |
=item B<-v>
|
|
|
e76f14 |
|
|
|
e76f14 |
=item B<--verbose>
|
|
|
e76f14 |
--
|
|
|
7af31e |
1.8.3.1
|
|
|
e76f14 |
|