From: rjones Date: Tue, 11 Sep 2007 10:55:58 +0000 (+0100) Subject: Up to network configuration. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=1b397fce73c2fb3141250518a408b5196a577577;p=virt-p2v.git Up to network configuration. --- diff --git a/livecd-post.sh.in b/livecd-post.sh.in index 2f8d7e3..48ca5c5 100644 --- a/livecd-post.sh.in +++ b/livecd-post.sh.in @@ -44,3 +44,6 @@ echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot # Stopgap fix for RH #217966; should be fixed in HAL instead touch /media/.hal-mtab + +# Make some mountpoints. +mkdir /mnt/root \ No newline at end of file diff --git a/livecd.ks.in b/livecd.ks.in index 89513e8..1ed9aa7 100644 --- a/livecd.ks.in +++ b/livecd.ks.in @@ -39,6 +39,9 @@ sed gawk findutils +# For network configuration +dhclient + # Some other generally useful packages which perl diff --git a/virt-p2v.sh b/virt-p2v.sh index 92b840f..faaaf20 100755 --- a/virt-p2v.sh +++ b/virt-p2v.sh @@ -28,14 +28,25 @@ override_remote_transport= # (only if override_remote_transport is 'ssh') override_remote_directory= -# list of devices to send, separated by spaces, if empty ask user +# list of local physical devices to examine, separated by spaces, +# if empty ask user. # this is usually a list of whole disk devices (eg. "sda") -override_devices_to_send="" +override_physical_devices="" + +# list of filesystems to send (eg. "sda1 sda2 VolGroup00/LogVol00") +override_filesystems_to_send="" # list of root filesystems to examine (eg. "sda3" or # "VolGroup00/LogVol00") override_root_filesystems="" +# network configuration +# - if empty, ask user +# - if contains a filesystem name (eg. "VolGroup00/LogVol00") try to +# auto-configure network from that +# (XXX needs to contain more ways to override in future) +override_network="" + #---------------------------------------------------------------------- # Logging. @@ -76,9 +87,6 @@ function word_in_list { # Example: # snapshot sda1 snap # creates a snapshot of /dev/sda1 called /dev/mapper/snap - - -# XXX Error checking. function snapshot { local dev=$1 name=$2 @@ -87,8 +95,10 @@ function snapshot { dmsetup create ${name}_org \ --table="0 $sectors snapshot-origin /dev/$dev" + if [ $? -ne 0 ]; then exit 1; fi dmsetup create $name \ --table="0 $sectors snapshot /dev/mapper/${name}_org /dev/ram1 n 64" + if [ $? -ne 0 ]; then exit 1; fi } # Drop an existing snapshot created by snapshot function. @@ -206,6 +216,48 @@ function search_parts { } #---------------------------------------------------------------------- +# Network configuration functions. + +# `auto_network $fs' mounts /dev/$fs read-only on /mnt/root and then +# tries to configure the network from it. Returns true or false. +function auto_network { + if ! mount -o ro /dev/$1 /mnt; then return 1; fi + + pushd /etc/sysconfig + + mv network network.saved + mv networking networking.saved + mv network-scripts network-scripts.saved + + ln -s /mnt/etc/sysconfig/network + ln -s /mnt/etc/sysconfig/networking + ln -s /mnt/etc/sysconfig/network-scripts + + /etc/init.d/network start + local status=$? + + rm network networking network-scripts + mv network.saved network + mv networking.saved networking + mv network-scripts.saved network-scripts + umount /mnt + + if [ "$greeting" != "no" ]; then + echo "Did automatic network configuration work?" + echo "(Hint: if not sure, there is a shell on console [ALT] [F2])" + echo -n " (y/n) " + local line + read line + if [ "$line" = "y" -o "$line" = "yes" ]; then return 0; fi + return 1 + fi + + # In non-interactive mode, return the status of /etc/init.d/network. + return $status +} + + +#---------------------------------------------------------------------- # General script setup. # We can safely write files into /tmp without modifying anything. @@ -309,86 +361,144 @@ while [ "$state" != "exit" ]; do fi fi ;; + + # Block devices configuration. devices) - if [ -n "$override_devices_to_send" ]; then - devices_to_send="$override_devices_to_send" - state=roots + if [ -n "$override_physical_devices" ]; then + physical_devices="$override_physical_devices" + state=filesystems else - # Returns the list of possible devices in $devices + # Returns the list of physical devices in $devices search_devices log devices returned by search_devices: $devices deviceslist="" for d in $devices; do - if word_in_list $d $devices_to_send; then + if word_in_list $d $physical_devices; then stat=on else stat=off fi - deviceslist="$deviceslist $d /dev/$d $stat" + gigs=$(($(blockdev --getsize /dev/$d)/2/1024/1024)) + deviceslist="$deviceslist $d /dev/$d(${gigs}GB) $stat" done dialog \ --extra-button --extra-label "Back" --nocancel \ --single-quoted \ - --checklist "Pick which local disk images to send" 10 50 5 \ + --checklist "Pick local disks to examine" 15 50 8 \ $deviceslist \ 2> line if [ $? -eq 3 ]; then state=directory else - devices_to_send=`cat line` + physical_devices=`cat line` + state=filesystems + fi + fi + ;; + filesystems) + if [ -n "$override_filesystems_to_send" ]; then + filesystems_to_send="$override_filesystems_to_send" + state=roots + else + # Returns the list of possible partitions / LVs in $parts + search_parts $physical_devices + + log partitions returned by search_parts: $parts + + partslist="" + for p in $parts; do + if word_in_list $p $filesystems_to_send; then + stat=on + else + stat=off + fi + gigs=$(($(blockdev --getsize /dev/$p)/2/1024/1024)) + partslist="$partslist $p /dev/$p(${gigs}GB) $stat" + done + + dialog \ + --extra-button --extra-label "Back" --nocancel \ + --single-quoted \ + --checklist "Pick filesystems to send" 15 70 8 \ + $partslist \ + 2> line + if [ $? -eq 3 ]; then state=devices + else + filesystems_to_send=`cat line` state=roots - log user selected devices_to_send = $devices_to_send fi fi ;; roots) if [ -n "$override_root_filesystems" ]; then root_filesystems="$override_root_filesystems" - state=verify + state=network else - # Returns the list of possible partitions / LVs in $parts - search_parts $devices_to_send - - log filesystems returned by search_parts: $parts + partslist="" + for r in $filesystems_to_send; do + if word_in_list $r $root_filesystems; then + stat=on + else + stat=off + fi + partslist="$partslist $r /dev/$r $stat" + done - if [ -z "$parts" ]; then - root_filesystems="" - state=verify + dialog \ + --extra-button --extra-label "Back" --nocancel \ + --single-quoted \ + --checklist "Pick partition(s) containing a root (/) filesystem" 10 70 5 \ + $partslist \ + 2> line + if [ $? -eq 3 ]; then state=filesystems else - partslist="" - for r in $parts; do - if word_in_list $r $root_filesystems; then - stat=on - else - stat=off - fi - partslist="$partslist $r /dev/$r $stat" - done - - dialog \ - --extra-button --extra-label "Back" --nocancel \ - --single-quoted \ - --checklist "Pick partition(s) containing root (/) filesystem" 10 70 5 \ - $partslist \ - 2> line - if [ $? -eq 3 ]; then state=devices + root_filesystems=`cat line` + state=network + fi + fi + ;; + + # Network configuration. + network) + if [ -n "$override_network" ]; then + network="$override_network" + state=verify + else + partslist="" + for r in $root_filesystems; do + if [ "$r" = "$network" ]; then + stat=on else - root_filesystems=`cat line` - state=verify - log user selected root_filesystems = $root_filesystems + stat=off fi + partslist="$partslist $r Auto-configure $stat" + done + + dialog \ + --extra-button --extra-label "Back" --nocancel \ + --radiolist "Network configuration" 10 70 5 \ + $partslist \ + "ask" "Manual configuration" off \ + "sh" "Configure from the shell" off \ + 2> line + if [ $? -eq 3 ]; then state=roots + else + network=`cat line` + state=verify fi fi ;; + + # Verify configuration. verify) if [ "$greeting" = "no" ]; then state=exit else dialog \ --title "Summary" \ - --yesno "Transport: $remote_transport\nRemote host: $remote_host\nRemote port: $remote_port\nRemote directory (ssh only): $remote_directory\nDisks to send: $devices\nRoot filesystem(s): $root_filesystems\n\nProceed with these settings?" \ + --yesno "Transport: $remote_transport\nRemote host: $remote_host\nRemote port: $remote_port\nRemote directory (ssh only): $remote_directory\nFilesystems to send: $filesystems_to_send\nRoot filesystem(s): $root_filesystems\nNetwork configuration: $network\n\nProceed with these settings?" \ 23 70 if [ $? -eq 1 ]; then state=transport @@ -406,10 +516,48 @@ done clear +# Now see if we can get a network configuration. +log network configuration $network + +case "$network" in + sh) + echo "Network configuration" + echo + echo "Please configure the network from this shell." + echo + echo "You can modify any file under /etc (especially /etc/sysconfig)." + echo "No changes are made to the system disks unless you mount them" + echo "and explicitly modify them." + echo + echo "When finished, exit with ^D or exit" + echo + bash + ;; + + ask) + # XXX Not implemented + echo "Sorry, we didn't implement this one yet." + bash + ;; + + *) + echo "Trying to auto-configure network from /dev/$network ..." + echo + if ! auto_network "$network"; then + echo "Auto-configuration failed. Starting a shell." + echo + bash + fi +esac + # Mount the root filesystem(s) using device-mapper snapshots. -# For example, if asked to examine VolGroup00/LogVol00, then -# we might find that it is located on physical device sda, and -# the snapshot in that case will be called sda_snap. +# The snapshots are called snap0, snap1, etc. with the number +# corresponding to its index in $root_filesystems array. + + + + +