From 57b9f5b7827c0545ee286b3f0cfab7ae5fcadeb1 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 27 Jan 2016 11:48:53 +0000 Subject: [PATCH] p2v: virt-p2v-make-disk: Make os-version parameter optional. Having to choose the os-version of the virt-p2v disk was confusing. Users thought it had something to do with the physical machine being converted. In some cases, virt-p2v-make-disk can now choose a suitable os-version for the user. Usually it's the latest numeric version of Fedora or Debian, depending on the host distro. If we don't recognize the host distro, we bail and ask the user to choose, but this is still an improvement. (cherry picked from commit 3aaa4c9419d539dada31004b47121bbaac5241c6) --- p2v/virt-p2v-make-disk.in | 26 ++++++++++++++++++++++---- p2v/virt-p2v-make-disk.pod | 30 ++++++++++++++++++------------ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/p2v/virt-p2v-make-disk.in b/p2v/virt-p2v-make-disk.in index 6769707..88c171f 100644 --- a/p2v/virt-p2v-make-disk.in +++ b/p2v/virt-p2v-make-disk.in @@ -38,7 +38,7 @@ upload= usage () { echo "Usage:" - echo " $program [--options] -o /dev/sdX os-version" + echo " $program [--options] -o /dev/sdX [os-version]" echo echo "Read $program(1) man page for more information." exit $1 @@ -71,12 +71,30 @@ if [ -z "$output" ]; then exit 1 fi -if [ $# -ne 1 ]; then - echo "$program: Missing os-version. See $program(1)." +if [ $# -gt 1 ]; then + echo "$program: Too many parameters. See $program(1)." exit 1 fi -osversion="$1" +if [ $# -eq 1 ]; then + osversion="$1" +else + # If osversion was not set, then we must guess a good value + # based on the host distro. + if test -f /etc/redhat-release; then + osversion="$(virt-builder -l | sort | + @AWK@ '/^fedora-[1-9]/ {print $1}' | tail -1)" + elif test -f /etc/debian_version; then + osversion="$(virt-builder -l | sort | + @AWK@ '/^debian-[1-9]/ {print $1}' | tail -1)" + fi + if [ "x$osversion" = "x" ]; then + echo "$program: unable to guess a suitable os-version." + echo "You must supply one on the command line and output of 'virt-builder -l'." + echo "See $program(1) for further details." + exit 1 + fi +fi # Create a temporary directory and clean it up when we finish. tmpdir="$(mktemp -d)" diff --git a/p2v/virt-p2v-make-disk.pod b/p2v/virt-p2v-make-disk.pod index d401097..79bf499 100644 --- a/p2v/virt-p2v-make-disk.pod +++ b/p2v/virt-p2v-make-disk.pod @@ -4,7 +4,7 @@ virt-p2v-make-disk - Build the virt-p2v disk using virt-builder =head1 SYNOPSIS - virt-p2v-make-disk -o /dev/sdX os-version + virt-p2v-make-disk -o /dev/sdX [os-version] =head1 DESCRIPTION @@ -17,28 +17,34 @@ virt-p2v-make-disk is a script which creates a bootable disk image or USB key containing virt-p2v. It uses L to do this, and is just a small shell script around virt-builder. -virt-p2v-make-disk has two required parameters: +The required I<-o> parameter specifies where the output should go, for +example to a USB key (eg. C<-o /dev/sdX>) or to a file. If you pass a +device name, then B. -The I<-o> parameter specifies where the output should go, for example -to a USB key (eg. C<-o /dev/sdX>) or to a file. If you pass a device -name, then B. +=head2 C parameter -The C parameter is the base Linux distro to use for the -operating system on the ISO. To list possible C -combinations, do: +The optional C parameter is the base Linux distro to use +for the operating system on the ISO. If you don't set this parameter, +the script tries to choose a suitable default for you. Most users +should I use the C parameter. + +The base OS selected for virt-p2v is not related in any way to the OS +of the physical machine that you are trying to convert. + +To list possible C combinations, do: virt-builder -l -=head2 EXAMPLES +=head1 EXAMPLES Write a virt-p2v bootable USB key on F (any existing content -is erased), using Fedora 20 as the base distribution: +on F is erased): - virt-p2v-make-disk -o /dev/sdX fedora-20 + virt-p2v-make-disk -o /dev/sdX Write a virt-p2v bootable virtual disk image, and boot it under qemu: - virt-p2v-make-disk -o /var/tmp/p2v.img fedora-20 + virt-p2v-make-disk -o /var/tmp/p2v.img qemu-kvm -m 1024 -boot c \ -drive file=/var/tmp/p2v.img,if=virtio,index=0 \ -drive file=/var/tmp/guest.img,if=virtio,index=1 -- 2.7.4