Rewrite /etc/fstab and transport image to remote end.
authorrjones <devnull@localhost>
Sat, 15 Sep 2007 11:53:19 +0000 (12:53 +0100)
committerrjones <devnull@localhost>
Sat, 15 Sep 2007 11:53:19 +0000 (12:53 +0100)
Version 0.4
GPL licensing.

Makefile
livecd-post.sh.in
livecd.ks.in
virt-p2v.sh

index f72896d..a5bb478 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,29 @@
+# Makefile for virt-p2v
+#
+# Copyright (C) 2007 Red Hat Inc.
+# Written by Richard W.M. Jones <rjones@redhat.com>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
 # $Id$
 
 #----------------------------------------------------------------------
 # General configuration
 
 PACKAGE  := virt-p2v
-VERSION  := 0.3
+VERSION  := 0.4
 
 # i386 images also work on x86-64, so best to stick with i386.
 ARCH     := i386
index 985dda8..c5ade08 100644 (file)
@@ -2,6 +2,25 @@
 # installer.  It runs inside the live CD chroot while it is
 # being created (after all the packages have been installed)
 # but before we make the ISO.
+#
+# Copyright (C) 2007 Red Hat Inc.
+# Written by Richard W.M. Jones <rjones@redhat.com>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+# $Id$
 
 # Create a 'p2v' init script which runs last thing during the
 # boot.
index 03b9897..bb0a6f5 100644 (file)
@@ -1,3 +1,22 @@
+# LiveCD kickstart file for virt-p2v
+#
+# Copyright (C) 2007 Red Hat Inc.
+# Written by Richard W.M. Jones <rjones@redhat.com>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
 # $Id$
 
 lang @LANG@
index ab62404..274b087 100755 (executable)
@@ -6,6 +6,20 @@
 # Copyright (C) 2007 Red Hat Inc.
 # Written by Richard W.M. Jones <rjones@redhat.com>
 #
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
 # $Id$
 
 export PATH=/usr/sbin:/sbin:/usr/local/bin:/usr/kerberos/bin:/usr/bin:/bin
@@ -236,7 +250,7 @@ function search_parts {
 #----------------------------------------------------------------------
 # Network configuration functions.
 
-# `auto_network $fs' tries to configure the network from the
+# `auto_network' tries to configure the network from the
 # root filesystem.  Returns true or false.
 function auto_network {
     # Make sure this file exists, otherwise Fedora gives a warning.
@@ -504,6 +518,7 @@ done
 
 clear
 
+#----------------------------------------------------------------------
 # De-activate all volume groups and switch to new dm-only LVM config.
 log deactivating volume groups
 
@@ -540,6 +555,7 @@ else
     mount /dev/$root_filesystem /mnt/root
 fi
 
+#----------------------------------------------------------------------
 # Now see if we can get a network configuration.
 log network configuration $network
 
@@ -561,26 +577,89 @@ case "$network" in
        ;;
 
     auto)
-       echo "Trying to auto-configure network from /dev/$network ..."
+       echo "Trying to auto-configure network from root filesystem ..."
        echo
-       if ! auto_network "$network"; then
+       if ! auto_network; then
            echo "Auto-configuration failed.  Starting a shell."
            echo
            shell
        fi
 esac
 
+#----------------------------------------------------------------------
+# Rewrite /mnt/root/etc/fstab
+
+log rewriting /etc/fstab
+
+cp /mnt/root/etc/fstab /mnt/root/etc/fstab.p2vsaved
+while read dev mountpoint fstype options freq passno; do
+    # If device is /dev/sd* then on the target fullvirt machine
+    # it will be /dev/sd*
+    if matches_regexp "^/dev/sd[[:alpha:]]+[[:digit:]]+$" "$dev"; then
+       dev=`echo $dev | sed 's|^/dev/sd|/dev/hd|'`
+    fi
+
+    # Print out again with all the fields nicely lined up.
+    printf "%-23s %-23s %-7s %-15s %d %d\n" \
+       "$dev" "$mountpoint" "$fstype" "$options" "$freq" "$passno"
+done < /mnt/root/etc/fstab.p2vsaved > /mnt/root/etc/fstab
+
+#----------------------------------------------------------------------
+# XXX Look for other files which might need to be changed here ...
+
 
 
+# We've now finished with /mnt/root (the real root filesystem),
+# so unmount it and synch everything.
+umount /mnt/root
+sync
+
+#----------------------------------------------------------------------
+# Send the device snapshots (underlying device + changes in ramdisk)
+# to the remote server.
+
+log sending disks
 
+# XXX Effectively this is using the hostname derived from network
+# configuration, but we might want to ask the user instead.
+# XXX How do we ensure that we won't overwrite target files?  Currently
+# tries to use the current date as a uniquifier.
 
+# Names will be something like
+# p2v-oirase-200709011249-hda.img
+basename=p2v-`hostname -s|tr -cd '[0-9a-zA-Z]'`-`date +'%Y%m%d%H%M'`
+
+for dev in $devices_to_send; do
+    rdev=`echo $dev | sed 's|^sd|hd|'`
+    name="$basename-$rdev.img"
+    log sending $dev to $name
+
+    sectors=`blockdev --getsize /dev/mapper/snap_$dev`
+
+    gigs=$(($sectors/2/1024/1024))
+    echo "Sending /dev/$dev (${gigs} GB) to remote machine"
+
+    dd if=/dev/mapper/snap_$dev |
+    case "$remote_transport" in
+       ssh)
+           ssh -p "$remote_port" "$remote_host" \
+               "cat > $remote_directory/$name"
+           ;;
+       tcp)
+           echo "p2v $name $sectors" > header
+           cat header - | nc "$remote_host" "$remote_port"
+           ;;
+    esac
+done
 
 
 #----------------------------------------------------------------------
 # Clean up.
 
-umount /mnt/root
-drop_snapshot snap
+#for d in $devices_to_send; do
+#    kpartx -d /dev/mapper/snap_$d
+#    drop_snapshot snap_$d
+#done
 
 # This file must end with a newline