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.
This commit is contained in:
Richard W.M. Jones
2014-05-17 11:15:54 +01:00
parent 1939cd4849
commit f49e003a87
9 changed files with 527 additions and 104 deletions

6
.gitignore vendored
View File

@@ -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

View File

@@ -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 \

View File

@@ -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],

View File

@@ -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 $@

View File

@@ -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
----------------------------------------------------------------------

238
p2v-iso/guestfs-p2v-iso.pod Normal file
View File

@@ -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<p2v-iso> directory in the libguestfs sources.
It B<does not> describe how to use or boot virt-p2v. For that you
need to read the L<virt-p2v(1)> 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<p2v-iso> contains the scripts used
to build the bootable image.
=over 4
=item *
It B<does not> contain the source to L<virt-p2v(1)>. See C<p2v> for
the source of virt-p2v.
=item *
It B<does not> contain instructions for how to run virt-p2v. For
that you need to read the L<virt-p2v(1)> manual page.
=item *
It B<does not> build anything when you run C<make>. 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<make check> and C<make install> 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<Most users> should choose C<virt-builder-target>.
Fedora, Red Hat Enterprise Linux, CentOS and Scientific Linux users
may wish to try the C<kickstart-target>.
Fedora and RHEL developers who have been given C<spin-livecd>
permission by the Fedora/RHEL Koji/Brew administrators may wish to try
building the C<kickstart-target> as a Fedora/RHEL "Spin".
=head1 C<virt-builder-target>
This target uses virt-builder (see L<virt-builder(1)>) to build a
bootable disk image or USB key containing the locally built virt-p2v
binary from the C<p2v> 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<ge> 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</dev/sdX>].
=back
Then run this command (from the C<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).
=head1 C<kickstart-target>
=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<p2v.ks>.
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<p2v.ks>) 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<livecd-creator> 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<spin-livecd> 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<rawhide> you can use any Koji target.
=back
=head1 SEE ALSO
L<virt-p2v(1)>,
L<virt-v2v(1)>,
L<virt-builder(1)>,
L<livecd-creator(8)>,
L<http://libguestfs.org/>
=head1 AUTHOR
Richard W.M. Jones
=head1 COPYRIGHT
Copyright (C) 2009-2014 Red Hat Inc.

View File

@@ -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"

157
p2v-iso/p2v.ks.in Normal file
View File

@@ -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 <<EOF
__BASE64_LAUNCH_VIRT_P2V__
EOF
chmod 0755 /usr/bin/launch-virt-p2v
base64 -d > /etc/systemd/system/p2v.service <<EOF
__BASE64_P2V_SERVICE__
EOF
systemctl enable p2v.service
# Update the default getty target to login automatically as root without
# prompting for a password
sed -i 's/^ExecStart=\(.*\)/ExecStart=\1 -a root/' \
/usr/lib/systemd/system/getty@.service
# Reserve tty1 as a getty so we can document it clearly
echo ReserveVT=1 >> /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 <<EOF
PRODUCT='$PRODUCT'
PRODUCT_SHORT='${PRODUCT_SHORT}'
#PRODUCT_CODE=$PRODUCT_CODE
#RECIPE_SHA256=$RECIPE_SHA256
#RECIPE_RPM=$RECIPE_RPM
PACKAGE=$PACKAGE
VERSION=$VERSION
EOF
# overwrite user visible banners with the image versioning info
cat > $INSTALL_ROOT/etc/$PACKAGE-release <<EOF
$PRODUCT release $VERSION
EOF
#ln -snf $PACKAGE-release $INSTALL_ROOT/etc/redhat-release
#ln -snf $PACKAGE-release $INSTALL_ROOT/etc/system-release
#cp $INSTALL_ROOT/etc/$PACKAGE-release $INSTALL_ROOT/etc/issue
#echo "Kernel \r on an \m (\l)" >> $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

View File

@@ -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