Add default path and port to dialog.
[virt-p2v.git] / virt-p2v.sh
index 7bae812..2bc82a4 100755 (executable)
@@ -62,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 >/dev/$1
+fi
+
+# We can safely write files into /tmp without modifying anything.
+cd /tmp
+
 #----------------------------------------------------------------------
 # Helper functions.
 
@@ -169,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
@@ -306,23 +331,6 @@ function auto_network {
     return $status
 }
 
-
-#----------------------------------------------------------------------
-# General script setup.
-
-log
-log virt-p2v starting up at `date`
-
-# The first and only parameter must be the tty.  Connect
-# stdin/stdout/stderr to this device.
-if [ -n "$1" ]; then
-    log connecting to /dev/$1
-    exec </dev/$1 &>/dev/$1
-fi
-
-# We can safely write files into /tmp without modifying anything.
-cd /tmp
-
 #----------------------------------------------------------------------
 # Dialog with the user.
 
@@ -437,9 +445,12 @@ while [ "$state" != "exit" ]; do
                    else
                        stat=off
                    fi
+                   log running blockdev --getsize /dev/$d
                    gigs=$(($(blockdev --getsize /dev/$d)/2/1024/1024))
+                   log /dev/$d has size $gigs
                    deviceslist="$deviceslist $d /dev/$d(${gigs}GB) $stat"
                done
+               log deviceslist="$deviceslist"
 
                dialog \
                    --extra-button --extra-label "Back" --nocancel \
@@ -616,7 +627,7 @@ 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*
+    # it will be /dev/hd*
     if matches_regexp "^/dev/sd[[:alpha:]]+[[:digit:]]+$" "$dev"; then
        dev=`echo $dev | sed 's|^/dev/sd|/dev/hd|'`
     fi