3 # virt-p2v.sh is a shell script which performs a physical to
4 # virtual conversion of local disks.
6 # By Richard W.M. Jones <rjones@redhat.com>
8 # Copyright (C) 2007 Red Hat Inc.
10 export PATH=/usr/sbin:/sbin:/usr/local/bin:/usr/kerberos/bin:/usr/bin:/bin
12 # The defaults here make a generic virt-p2v.sh script, but if you want
13 # to build a partially-/fully-automatic P2V solution, then you can set
14 # these variables to something, and the script won't ask the user for
23 # can be 'ssh' or 'tcp'
24 override_remote_transport=
26 # eg. override_remote_directory=/var/lib/xen/images
27 # (only if override_remote_transport is 'ssh')
28 override_remote_directory=
30 # list of devices to send, separated by spaces, if empty ask user
31 override_devices_to_send=""
33 #----------------------------------------------------------------------
34 # Device mapper snapshotting.
36 # Create a device-mapper snapshot of a device with ramdisk overlay.
38 # snapshot /dev/sda1 snap
39 # creates a snapshot of /dev/sda1 called /dev/mapper/snap
47 # Get size of the device in sectors.
48 sectors=`blockdev --getsize $dev`
50 dmsetup create ${name}_org \
51 --table="0 $sectors snapshot-origin $dev"
52 dmsetup create $name \
53 --table="0 $sectors snapshot /dev/mapper/${name}_org /dev/ram1 n 64"
56 # Drop an existing snapshot created by snapshot function.
59 # drops a snapshot called /dev/mapper/snap
60 function drop_snapshot {
61 dmsetup remove /dev/mapper/$name
62 dmsetup remove /dev/mapper/${name}_org
66 #----------------------------------------------------------------------
67 # General script setup.
69 # We can safely write files into /tmp without modifying anything.
72 #----------------------------------------------------------------------
73 # Dialog with the user.
75 if [ "$greeting" != "no" ]; then
78 --msgbox "\nWelcome to virt-p2v, a live CD for migrating a physical machine to a virtualized host.\n\nTo continue press the Return key.\n\nTo get a shell you can use [ALT] [F2] and log in as root with no password." 17 50
81 # Get configuration from the user.
83 # To make the [Back] button work, we make this into a looping state
84 # machine. Each state asks a question and jumps to the next state
85 # (unless [Back] is pressed, in which case it jumps back to the previous
86 # state). Finally the 'exit' state causes us to quit the loop.
89 while [ "$state" != "exit" ]; do
92 if [ -n "$override_remote_host" ]; then
93 remote_host="$override_remote_host"
97 --inputbox "Remote host" 10 50 "$remote_host" \
99 remote_host=`cat line`
104 if [ -n "$override_remote_port" ]; then
105 remote_port="$override_remote_port"
108 --extra-button --extra-label "Back" --nocancel \
109 --inputbox "Remote port" 10 50 "$remote_port" \
111 if [ $? -eq 3 ]; then state=hostname
113 remote_port=`cat line`
120 echo "Invalid state: $state"
127 echo remote_host $remote_host
128 echo remote_port $remote_port