git.annexia.org
/
virt-p2v.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Additional logging on the failing "devices" state.
[virt-p2v.git]
/
virt-p2v.sh
diff --git
a/virt-p2v.sh
b/virt-p2v.sh
index
ae0d021
..
228e1fc
100755
(executable)
--- a/
virt-p2v.sh
+++ b/
virt-p2v.sh
@@
-22,7
+22,11
@@
#
# $Id$
#
# $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 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
# 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
@@
-96,12
+100,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 {
# Use the function read_line instead of the shell built-in read.
# It reads from the console.
function read_line {
- read "$*"
</dev/console
+ read "$*"
}
# Launch a bash subshell connected to the console.
function shell {
}
# Launch a bash subshell connected to the console.
function shell {
- PS1='\u@\h:\w\$ ' bash
</dev/console >/dev/console 2>&1
+ PS1='\u@\h:\w\$ ' bash
}
#----------------------------------------------------------------------
}
#----------------------------------------------------------------------
@@
-247,6
+251,13
@@
function search_parts {
# $parts is returned.
}
# $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.
#----------------------------------------------------------------------
# Network configuration functions.
@@
-286,7
+297,7
@@
function auto_network {
echo "(Hint: if not sure, there is a shell on console [ALT] [F2])"
echo -n " (y/n) "
local line
echo "(Hint: if not sure, there is a shell on console [ALT] [F2])"
echo -n " (y/n) "
local line
- read_line line
</dev/console
+ read_line line
if [ "$line" = "y" -o "$line" = "yes" ]; then return 0; fi
return 1
fi
if [ "$line" = "y" -o "$line" = "yes" ]; then return 0; fi
return 1
fi
@@
-299,15
+310,22
@@
function auto_network {
#----------------------------------------------------------------------
# General script setup.
#----------------------------------------------------------------------
# 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.
# We can safely write files into /tmp without modifying anything.
cd /tmp
#----------------------------------------------------------------------
# Dialog with the user.
-log
-log virt-p2v starting up at `date`
-
if [ "$greeting" != "no" ]; then
dialog \
--title "virt-p2v" \
if [ "$greeting" != "no" ]; then
dialog \
--title "virt-p2v" \
@@
-419,9
+437,12
@@
while [ "$state" != "exit" ]; do
else
stat=off
fi
else
stat=off
fi
+ log running blockdev --getsize /dev/$d
gigs=$(($(blockdev --getsize /dev/$d)/2/1024/1024))
gigs=$(($(blockdev --getsize /dev/$d)/2/1024/1024))
+ log /dev/$d has size $gigs
deviceslist="$deviceslist $d /dev/$d(${gigs}GB) $stat"
done
deviceslist="$deviceslist $d /dev/$d(${gigs}GB) $stat"
done
+ log deviceslist="$deviceslist"
dialog \
--extra-button --extra-label "Back" --nocancel \
dialog \
--extra-button --extra-label "Back" --nocancel \
@@
-529,13
+550,14
@@
rm -f /etc/lvm/cache/.cache
# Snapshot the block devices.
for d in $devices_to_send; do
# 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.
# 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.
done
# Rescan for LVs.
@@
-549,8
+571,11
@@
vgchange -a y
log mount $root_filesystem as /mnt/root
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
else
mount /dev/$root_filesystem /mnt/root
fi
@@
-634,12
+659,14
@@
for dev in $devices_to_send; do
name="$basename-$rdev.img"
log sending $dev to $name
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"
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" \
case "$remote_transport" in
ssh)
ssh -p "$remote_port" "$remote_host" \
@@
-647,7
+674,8
@@
for dev in $devices_to_send; do
;;
tcp)
echo "p2v $name $sectors" > header
;;
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
;;
esac
done
@@
-657,8
+685,9
@@
done
# Clean up.
#for d in $devices_to_send; do
# 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
#done
# This file must end with a newline