From f49e003a875ce5703b7e8d4109a145ebe673129d Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 17 May 2014 11:15:54 +0100 Subject: [PATCH] p2v-iso: Add a kickstart target. This also changes the old p2v-iso/README file into a POD file which is installed as a manual page. --- .gitignore | 6 + Makefile.am | 1 + configure.ac | 2 + p2v-iso/Makefile.am | 34 ++++- p2v-iso/README | 100 ------------- p2v-iso/guestfs-p2v-iso.pod | 238 ++++++++++++++++++++++++++++++ p2v-iso/kickstart-target.sh.in | 87 +++++++++++ p2v-iso/p2v.ks.in | 157 ++++++++++++++++++++ p2v-iso/virt-builder-target.sh.in | 6 +- 9 files changed, 527 insertions(+), 104 deletions(-) delete mode 100644 p2v-iso/README create mode 100644 p2v-iso/guestfs-p2v-iso.pod create mode 100644 p2v-iso/kickstart-target.sh.in create mode 100644 p2v-iso/p2v.ks.in diff --git a/.gitignore b/.gitignore index 32b95039d..16eae54ea 100644 --- a/.gitignore +++ b/.gitignore @@ -215,6 +215,7 @@ Makefile.in /html/guestfs-java.3.html /html/guestfs-lua.3.html /html/guestfs-ocaml.3.html +/html/guestfs-p2v-iso.1.html /html/guestfs-performance.1.html /html/guestfs-perl.3.html /html/guestfs-python.3.html @@ -318,7 +319,12 @@ Makefile.in /p2v/stamp-virt-p2v.pod /p2v/virt-p2v /p2v/virt-p2v.1 +/p2v-iso/guestfs-p2v-iso.1 +/p2v-iso/guestfs-p2v-iso.txt +/p2v-iso/kickstart-target.sh /p2v-iso/launch-virt-p2v +/p2v-iso/p2v.ks +/p2v-iso/stamp-guestfs-p2v-iso.pod /p2v-iso/virt-builder-target.sh /perl/bindtests.pl /perl/blib diff --git a/Makefile.am b/Makefile.am index 3da8021e6..8eb43cfc9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -225,6 +225,7 @@ HTMLFILES = \ html/guestfs-java.3.html \ html/guestfs-lua.3.html \ html/guestfs-ocaml.3.html \ + html/guestfs-p2v-iso.1.html \ html/guestfs-performance.1.html \ html/guestfs-perl.3.html \ html/guestfs-python.3.html \ diff --git a/configure.ac b/configure.ac index a64882541..552ed7792 100644 --- a/configure.ac +++ b/configure.ac @@ -1605,6 +1605,8 @@ AC_CONFIG_FILES([appliance/libguestfs-make-fixed-appliance], [chmod +x,-w appliance/libguestfs-make-fixed-appliance]) AC_CONFIG_FILES([inspector/test-xmllint.sh], [chmod +x,-w inspector/test-xmllint.sh]) +AC_CONFIG_FILES([p2v-iso/kickstart-target.sh], + [chmod +x,-w p2v-iso/kickstart-target.sh]) AC_CONFIG_FILES([p2v-iso/virt-builder-target.sh], [chmod +x,-w p2v-iso/virt-builder-target.sh]) AC_CONFIG_FILES([php/extension/php-for-tests.sh], diff --git a/p2v-iso/Makefile.am b/p2v-iso/Makefile.am index 9e3c636f4..95bf48bbc 100644 --- a/p2v-iso/Makefile.am +++ b/p2v-iso/Makefile.am @@ -17,14 +17,26 @@ include $(top_srcdir)/subdir-rules.mk +CLEANFILES = \ + *~ \ + kickstart-target.sh \ + launch-virt-p2v \ + p2v.ks \ + stamp-guestfs-p2v-iso.pod \ + virt-builder-target.sh + EXTRA_DIST = \ - README \ + guestfs-p2v-iso.pod \ + guestfs-p2v-iso.txt \ issue \ + kickstart-target.sh.in \ launch-virt-p2v.in \ + p2v.ks.in \ p2v.service \ virt-builder-target.sh.in -# You need to read the README file before trying any of these targets. +# You need to read 'guestfs-p2v-iso.txt' before trying any of these +# targets. virt-builder-target: virt-builder-target.sh launch-virt-p2v srcdir=$(srcdir) $(top_builddir)/run ./virt-builder-target.sh @@ -35,3 +47,21 @@ launch-virt-p2v: launch-virt-p2v.in sed 's,@''libexecdir@,$(libexecdir),g' < $< > $@-t chmod 0555 $@-t mv $@-t $@ + +kickstart-target: kickstart-target.sh launch-virt-p2v + srcdir=$(srcdir) $(top_builddir)/run ./kickstart-target.sh + +man_MANS = guestfs-p2v-iso.1 +noinst_DATA = $(top_builddir)/html/guestfs-p2v-iso.1.html + +guestfs-p2v-iso.1 guestfs-p2v-iso.txt $(top_builddir)/html/guestfs-p2v-iso.1.html: stamp-guestfs-p2v-iso.pod + +stamp-guestfs-p2v-iso.pod: guestfs-p2v-iso.pod + $(PODWRAPPER) \ + --section 1 \ + --man guestfs-p2v-iso.1 \ + --text guestfs-p2v-iso.txt \ + --html $(top_builddir)/html/guestfs-p2v-iso.1.html \ + --license GPLv2+ \ + $< + touch $@ diff --git a/p2v-iso/README b/p2v-iso/README deleted file mode 100644 index 2db727d6c..000000000 --- a/p2v-iso/README +++ /dev/null @@ -1,100 +0,0 @@ -virt-p2v ISO -====================================================================== - -virt-p2v converts physical machines to run on KVM. Normally you -should not run virt-p2v directly. Instead you have to boot the -physical machine using the bootable CD-ROM, ISO, PXE or disk image -which is provided by this directory. The reason for this is so that -virt-p2v runs in a "clean" environment, with no other processes -running and modifying the disks. - -- This directory (libguestfs.git/p2v-iso) contains the scripts - used to build the bootable image. - -- It *does not* contain the source to virt-p2v. See ../p2v/ for the - source of virt-p2v. - -- It *does not* contain instructions for how to run virt-p2v. For - that you need to read the virt-p2v(1) manual page (see ../p2v/). - -- It *does not* build anything when you run 'make'. This is because: - - * building the disk image takes a long time - - * you wouldn't want to rebuild it every time virt-p2v changes - - * how and what to build depends on your environment - - * for some targets, it isn't even possible to build anything without - root permissions / a network connection / a remote service (like - Fedora's Koji) - - * some targets require interaction, eg. inserting a USB key - -- For the same reasons as above, 'make check' and 'make install' in - this directory do nothing. - -Although for historical reasons this is known as the virt-p2v "ISO", -it may not actually build an ISO-formatted CD image. Some of the -targets are simple disk images, USB keys and so on. - -Although virt-p2v should be run on a physical machine, for testing -purposes you can (and we often do) run it in a virtual machine. - -Running the virt-p2v ISO in a VM is also a legitimate way to convert a -virtual machine from a hypervisor which is not supported by virt-v2v -(Hyper-V is one such hypervisor). - - -Which target should you choose? ----------------------------------------------------------------------- - -For a list of all targets and how to use them, see below. - -MOST USERS should choose 'virt-builder-target'. - -Fedora, RHEL, CentOS and Scientific Linux users may wish to try -the 'kickstart-target'. - -Fedora and RHEL developers who have been given 'spin-livecd' -permission by the Fedora/RHEL Koji/Brew administrators may wish to try -building the 'kickstart-target' as a Fedora/RHEL "Spin". - - -virt-builder-target ----------------------------------------------------------------------- - -This target uses virt-builder (see ../builder/) to build a bootable -disk image or USB key containing the locally built virt-p2v binary -from ../p2v - -Use a disk image if you want to test virt-p2v inside a virtual -machine. To use virt-p2v for real, you will need an empty USB key >= -6 GB in size. Use this target to write the USB key, which you can -then plug into the physical machine to start the P2V process. - -Most users should use this target. It does not require any special -permissions, but it does need network access. - -To use the virt-builder target: - -(1) Choose the os-version which most closely matches your distro -from this list: - - virt-builder -l - -(2) Choose the output, which could be a file [filename] or a USB key -[eg. /dev/sdX]. - -Then run this command (from the p2v-iso directory): - - make virt-builder-target OSVERSION=fedora-20 OUTPUT=/dev/sdX - -After building the image, you can boot it directly on physical -hardware, or for testing in qemu or KVM (see the virt-builder man page -for example qemu and virt-install command lines). - - -kickstart-target ----------------------------------------------------------------------- - diff --git a/p2v-iso/guestfs-p2v-iso.pod b/p2v-iso/guestfs-p2v-iso.pod new file mode 100644 index 000000000..7c67c882c --- /dev/null +++ b/p2v-iso/guestfs-p2v-iso.pod @@ -0,0 +1,238 @@ +=head1 NAME + + guestfs-p2v-iso - How to build the virt-p2v disk image or CD/ISO + +=head1 ABOUT THIS DOCUMENT + +This document describes how to build the virt-p2v disk image from the +C directory in the libguestfs sources. + +It B describe how to use or boot virt-p2v. For that you +need to read the L manual page. This document is only +for developers. + +=head1 ABOUT THE VIRT-P2V ISO + +virt-p2v converts physical machines to run on KVM. Normally you +should not run virt-p2v directly. Instead you have to boot the +physical machine using the bootable CD-ROM, ISO, PXE or disk image +which is provided by this directory. The reason for this is so that +virt-p2v runs in a "clean" environment, with no other processes +running and modifying the disks. + +The libguestfs source directory C contains the scripts used +to build the bootable image. + +=over 4 + +=item * + +It B contain the source to L. See C for +the source of virt-p2v. + +=item * + +It B contain instructions for how to run virt-p2v. For +that you need to read the L manual page. + +=item * + +It B build anything when you run C. This is because: + +=over 4 + +=item * + +building the disk image takes a long time + +=item * + +you wouldn't want to rebuild it every time virt-p2v changes + +=item * + +how and what to build depends on your environment + +=item * + +for some targets, it isn't even possible to build anything without +root permissions / a network connection / a remote service (like +Fedora's Koji) + +=item * + +some targets require interaction, eg. inserting a USB key + +=back + +=item * + +For the same reasons as above, C and C in +this directory do nothing. + +=back + +Although for historical reasons this is known as the virt-p2v "ISO", +it may not actually build an ISO-formatted CD image. Some of the +targets build simple disk images or USB keys. + +Although virt-p2v should be run on a physical machine, for testing +purposes you can (and we often do) run it in a virtual machine. + +Running the virt-p2v ISO in a VM is also a legitimate way to convert a +virtual machine from a hypervisor which is not supported by virt-v2v +(Hyper-V is one such hypervisor). + +=head1 WHICH TARGET SHOULD YOU CHOOSE? + +For a list of all targets and how to use them, see below. + +B should choose C. + +Fedora, Red Hat Enterprise Linux, CentOS and Scientific Linux users +may wish to try the C. + +Fedora and RHEL developers who have been given C +permission by the Fedora/RHEL Koji/Brew administrators may wish to try +building the C as a Fedora/RHEL "Spin". + +=head1 C + +This target uses virt-builder (see L) to build a +bootable disk image or USB key containing the locally built virt-p2v +binary from the C in the source. + +Use a disk image if you want to test virt-p2v inside a virtual +machine. To use virt-p2v for real, you will need an empty USB key +E 6 GB in size. Use this target to write the USB key, which you +can then plug into the physical machine to start the P2V process. + +Most users should use this target. It does not require any special +permissions, but it does need network access. + +To use the virt-builder target: + +=over 4 + +=item 1. + +Choose the os-version which most closely matches your distro from this +list: + + virt-builder -l + +=item 2. + +Choose the output, which could be a file [filename] or a USB key +[eg. C]. + +=back + +Then run this command (from the C directory): + + make virt-builder-target OSVERSION=fedora-20 OUTPUT=/dev/sdX + +After building the image, you can boot it directly on physical +hardware, or for testing in qemu or KVM (see the virt-builder man page +for example qemu and virt-install command lines). + +=head1 C + +=head2 Building the kickstart file + +Kickstart is a format used by Red Hat-derived distributions (such as +Fedora, Red Hat Enterprise Linux, CentOS, Scientific Linux, and +others) to describe how to make live CDs, install the distro, make +"Spins" and so on. It is driven by a kickstart file. + +Running: + + make kickstart-target.sh REPO=... [PROXY=...] + +simply builds the kickstart file called C. + +The variables you can specify are: + +=over 4 + +=item REPO + +A list of repositories to use, eg: REPO=fedora,rawhide + +=item PROXY + +An optional web proxy (URL) to use for downloading packages. + +=back + +After building the kickstart file (C) it's a good idea to +check it. + +=head2 Locally building a live CD/ISO + +You can make a live CD on a Red Hat-derived distribution using +livecd-creator: + + sudo livecd-creator p2v.ks + +Before running this note that you should probably run +C in a disposable virtual machine for these reasons: + +=over 4 + +=item * + +You have to disable SELinux when running the tool. + +=item * + +This tool has to be run as root, and has some nasty failure modes. + +=item * + +You can only create the exact same Live CD distro as the host +distro. Cross-builds will fail in strange ways (eg. RHBZ#1092327). + +=back + +=head2 Building a spin using Koji + +This requires C permissions on Koji, which are not given +out usually, even to Fedora packagers. However assuming you have been +given these permissions (or have your own Koji instance, I guess), +then you can do: + + koji spin-livecd [--scratch] p2v 1.XX.YY rawhide x86_64 p2v.ks + +=over 4 + +=item * + +Add the C<--scratch> option to do a scratch build (recommended for +testing). + +=item * + +C<1.XX.YY> should match the libguestfs version + +=item * + +Instead of C you can use any Koji target. + +=back + +=head1 SEE ALSO + +L, +L, +L, +L, +L + +=head1 AUTHOR + +Richard W.M. Jones + +=head1 COPYRIGHT + +Copyright (C) 2009-2014 Red Hat Inc. diff --git a/p2v-iso/kickstart-target.sh.in b/p2v-iso/kickstart-target.sh.in new file mode 100644 index 000000000..0ab7fcbf6 --- /dev/null +++ b/p2v-iso/kickstart-target.sh.in @@ -0,0 +1,87 @@ +#!/bin/bash - +# @configure_input@ +# (C) Copyright 2014 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# This script just builds the kickstart file ('p2v.ks'). +# Read guestfs-p2v-iso.txt! + +unset CDPATH +set -e + +if [ -z "$REPO" ]; then + echo "$0: You didn't set the repository (REPO)." + echo "Read guestfs-p2v-iso.txt!" + exit 1 +fi + +if [ -z "$srcdir" ]; then + echo "$0: internal error: srcdir is not set" + exit 1 +fi + +# Deal with stupid autotools libexecdir-not-expandable crap. +prefix="@prefix@" +exec_prefix="@exec_prefix@" +libexecdir="@libexecdir@" + +# Base64-encode the files that we need to embed into the kickstart. +base64_issue="$(base64 $srcdir/issue)" +base64_launch_virt_p2v="$(base64 launch-virt-p2v)" +base64_p2v_service="$(base64 $srcdir/p2v.service)" + +# Proxy. +if [ -n "$PROXY" ]; then + proxy="--proxy=$PROXY" +fi + +# Repository: +if [[ $REPO =~ fedora ]]; then + repo="$repo +repo --name=fedora --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-\$releasever\\\\&arch=\$basearch $proxy +" +fi +if [[ $REPO =~ rawhide ]]; then + repo="$repo +repo --name=rawhide --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rawhide\\\\&arch=\$basearch $proxy +" +fi +if [[ $REPO =~ koji ]]; then + repo="$repo +repo --name=koji --baseurl=http://koji.fedoraproject.org/repos/rawhide/latest/\$basearch/ $proxy +" +fi + +# Now generate the final kickstart, substituting as necessary. +# AWK FTW! +@AWK@ \ + -v "base64_issue=$base64_issue" \ + -v "base64_launch_virt_p2v=$base64_launch_virt_p2v" \ + -v "base64_p2v_service=$base64_p2v_service" \ + -v "repo=$repo" \ + '{ + gsub (/__PACKAGE_NAME__/, "@PACKAGE_NAME@"); + gsub (/__PACKAGE_VERSION__/, "@PACKAGE_VERSION@"); + gsub (/__BASE64_ISSUE__/, base64_issue); + gsub (/__BASE64_LAUNCH_VIRT_P2V__/, base64_launch_virt_p2v); + gsub (/__BASE64_P2V_SERVICE__/, base64_p2v_service); + gsub (/__REPO__/, repo); + print; + }' \ + $srcdir/p2v.ks.in > p2v.ks-t +mv p2v.ks-t p2v.ks + +echo "Kickstart file written to p2v.ks" diff --git a/p2v-iso/p2v.ks.in b/p2v-iso/p2v.ks.in new file mode 100644 index 000000000..ddb70df76 --- /dev/null +++ b/p2v-iso/p2v.ks.in @@ -0,0 +1,157 @@ +# Kickstart file for creating the virt-p2v ISO. +# (C) Copyright 2014 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Read guestfs-p2v-iso.txt! + +install +lang en_US.UTF-8 +keyboard us +timezone --utc GMT + +selinux --enforcing +firewall --enabled + +# Need to specify --device, else: +# Error creating Live CD : No --device specified with network kickstart command +network --bootproto=dhcp --device=eth0 + +bootloader --location=mbr --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH" +zerombr +clearpart --all --initlabel +part / --size 3000 --fstype ext4 + +reboot + +# Repositories: +__REPO__ + +# Packages to install in the ISO. For dependencies, see +# p2v/Makefile.am. Note that libguestfs is NOT required by virt-p2v. + +%packages +@core +# Note you must have a kernel, else the boot menu won't work: +kernel + +/usr/bin/base64 +/usr/bin/xinit +/usr/bin/ssh +/usr/bin/qemu-nbd +/usr/bin/Xorg +xorg-x11-drivers +xorg-x11-fonts-Type1 + +# This just includes the virt-p2v binary. It does NOT depend on +# libguestfs, but it does depend on libraries that the binary needs +# (such as gtk2). +libguestfs-pvhelper + +%end + +# Post-install configuration. + +%post + +base64 -d > /etc/issue << EOF +__BASE64_ISSUE__ +EOF + +cp /etc/issue /etc/issue.net + +base64 -d > /usr/bin/launch-virt-p2v < /etc/systemd/system/p2v.service <> /etc/systemd/logind.conf + +%end + +%post --nochroot + +PRODUCT='Virt P2V' +PRODUCT_SHORT='virt-p2v' +PACKAGE='__PACKAGE_NAME__' +VERSION='__PACKAGE_VERSION__' + +echo "Customizing boot menu" +sed -i -e ' +# Put product information at the top of the file +1 { + i '"say $PRODUCT $VERSION"' + i '"menu title $PRODUCT_SHORT $VERSION"' +} + +# Remove any existing menu title +/^menu title .*/d + +# Remove quiet bootparam +#s/ quiet// + +# Disable selinux. +#/^\s*append\s/ s/\s*$/ selinux=0/ + +# Remove Verify and Boot option +#/label check0/{N;N;N;d;} + +# Set the default timeout to 60 seconds +s/^timeout .*/timeout 60/ +' $LIVE_ROOT/isolinux/isolinux.cfg + +# TODO: Replace the splash screen with something P2V appropriate +#cp $INSTALL_ROOT//syslinux-vesa-splash.jpg $LIVE_ROOT/isolinux/splash.jpg + +# store image version info in the ISO +cat > $LIVE_ROOT/isolinux/version < $INSTALL_ROOT/etc/$PACKAGE-release <> $INSTALL_ROOT/etc/issue +#cp $INSTALL_ROOT/etc/issue $INSTALL_ROOT/etc/issue.net + +# replace initramfs if regenerated +if [ -f "$INSTALL_ROOT/initrd0.img" ]; then + mv -v "$INSTALL_ROOT/initrd0.img" "$LIVE_ROOT/isolinux/initrd0.img" +fi + +%end diff --git a/p2v-iso/virt-builder-target.sh.in b/p2v-iso/virt-builder-target.sh.in index 36d09a0c2..59fed7f3d 100644 --- a/p2v-iso/virt-builder-target.sh.in +++ b/p2v-iso/virt-builder-target.sh.in @@ -20,12 +20,14 @@ unset CDPATH set -e if [ -z "$OUTPUT" ]; then - echo "$0: You didn't set the output file or device (OUTPUT). Read the README file!" + echo "$0: You didn't set the output file or device (OUTPUT)." + echo "Read guestfs-p2v-iso.txt!" exit 1 fi if [ -z "$OSVERSION" ]; then - echo "$0: You didn't set OSVERSION. Read the README file!" + echo "$0: You didn't set OSVERSION." + echo "Read guestfs-p2v-iso.txt!" exit 1 fi