From a94bb18c0a05a1dddcb3304472a3c2dd4483399e Mon Sep 17 00:00:00 2001 From: rjones Date: Fri, 11 Jan 2008 16:45:42 +0000 Subject: [PATCH] Pull in some changes from the HP branch. --- virt-p2v.sh | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/virt-p2v.sh b/virt-p2v.sh index 0007e54..7bae812 100755 --- a/virt-p2v.sh +++ b/virt-p2v.sh @@ -251,6 +251,13 @@ function search_parts { # $parts is returned. } +# This generates a snapshot device name from a device name. +# eg. sda -> snap_sda +# Sets $dname. +function snap_name { + dname=`echo -n snap_"$1" | tr -cs '[:alnum:]' _` +} + #---------------------------------------------------------------------- # Network configuration functions. @@ -540,13 +547,14 @@ rm -f /etc/lvm/cache/.cache # Snapshot the block devices. for d in $devices_to_send; do - log snapshotting block device /dev/$d ... + snap_name $d + log snapshotting block device /dev/$d to $dname ... - snapshot $d snap_$d + snapshot $d $dname # The block devices are whole disks. Use kpartx to repartition them. - log running kpartx -a /dev/mapper/snap_$d ... - kpartx -a /dev/mapper/snap_$d + log running kpartx -a /dev/mapper/$dname ... + kpartx -a /dev/mapper/$dname done # Rescan for LVs. @@ -560,8 +568,11 @@ vgchange -a y log mount $root_filesystem as /mnt/root -if [ -f /dev/mapper/snap_$root_filesystem ]; then - mount /dev/mapper/snap_$root_filesystem /mnt/root +snap_name $root_filesystem +root_filesystem_dname="$dname" + +if [ -b /dev/mapper/$root_filesystem_dname ]; then + mount /dev/mapper/$root_filesystem_dname /mnt/root else mount /dev/$root_filesystem /mnt/root fi @@ -645,12 +656,14 @@ for dev in $devices_to_send; do name="$basename-$rdev.img" log sending $dev to $name - sectors=`blockdev --getsize /dev/mapper/snap_$dev` + snap_name $dev + + sectors=`blockdev --getsize /dev/mapper/$dname` gigs=$(($sectors/2/1024/1024)) echo "Sending /dev/$dev (${gigs} GB) to remote machine" - dd if=/dev/mapper/snap_$dev | gzip --best | + dd if=/dev/mapper/$dname | gzip --best | case "$remote_transport" in ssh) ssh -p "$remote_port" "$remote_host" \ @@ -669,8 +682,9 @@ done # Clean up. #for d in $devices_to_send; do -# kpartx -d /dev/mapper/snap_$d -# drop_snapshot snap_$d +# snap_name $d +# kpartx -d /dev/mapper/$dname +# drop_snapshot $dname #done # This file must end with a newline -- 1.8.3.1