X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=virt-p2v.sh;h=2bc82a492ada752703b775bc0575988777102cb8;hb=52433696d9755eb0e6cc5caa0f35b6690ace67fd;hp=274b087fc04ea6740db6e948b5ab8291aae75327;hpb=fe0ff26b9757ac927f13bf97692974be41e07e23;p=virt-p2v.git diff --git a/virt-p2v.sh b/virt-p2v.sh index 274b087..2bc82a4 100755 --- a/virt-p2v.sh +++ b/virt-p2v.sh @@ -22,7 +22,11 @@ # # $Id$ +# Because we're running from a start-up script, we don't have much +# of a login environment, so set one up. export PATH=/usr/sbin:/sbin:/usr/local/bin:/usr/kerberos/bin:/usr/bin:/bin +export HOME=/root +export LOGNAME=root # The defaults here make a generic virt-p2v.sh script, but if you want # to build a partially-/fully-automatic P2V solution, then you can set @@ -58,12 +62,27 @@ override_root_filesystem="" override_network="" #---------------------------------------------------------------------- -# Logging. +# General script setup and logging. + +exec 2>> /tmp/virt-p2v.log function log { - echo "$@" >> /tmp/virt-p2v.log + echo "$@" 1>&2 } +log +log virt-p2v starting up at `date` + +# The first and only parameter must be the tty. Connect +# stdin/stdout to this device. +if [ -n "$1" ]; then + log connecting to /dev/$1 + exec /dev/$1 +fi + +# We can safely write files into /tmp without modifying anything. +cd /tmp + #---------------------------------------------------------------------- # Helper functions. @@ -96,12 +115,12 @@ function word_in_list { # Use the function read_line instead of the shell built-in read. # It reads from the console. function read_line { - read "$*" /dev/console 2>&1 + PS1='\u@\h:\w\$ ' bash } #---------------------------------------------------------------------- @@ -165,7 +184,17 @@ function device_of_lvs_device { # Get list of physical block devices. Sets variable $devices # to something like "sda sdb". function search_devices { - devices=$(cd /sys/block && /bin/ls -d [hs]d*) + devices1=$(cd /sys/block && /bin/ls -d [hs]d*) + log search_devices: devices1: $devices1 + # Ignore devices which fail 'blockdev --getsize' - probably + # removable devices or other strange ones. + devices="" + for d in $devices1; do + if blockdev --getsize /dev/$d > /dev/null; then + devices="$devices${devices:+ }$d" + fi + done + log search_devices: devices: $devices } # Get list of partitions from a physical block device. Sets @@ -247,6 +276,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. @@ -286,7 +322,7 @@ function auto_network { echo "(Hint: if not sure, there is a shell on console [ALT] [F2])" echo -n " (y/n) " local line - read_line line $remote_directory/$name" + "zcat > $remote_directory/$name" ;; tcp) echo "p2v $name $sectors" > header - cat header - | nc "$remote_host" "$remote_port" + echo > newline + cat header - newline | nc "$remote_host" "$remote_port" ;; esac done @@ -657,8 +693,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