More
authorrjones <devnull@localhost>
Wed, 12 Sep 2007 14:16:39 +0000 (15:16 +0100)
committerrjones <devnull@localhost>
Wed, 12 Sep 2007 14:16:39 +0000 (15:16 +0100)
.cvsignore
Makefile
livecd.ks.in
virt-p2v.sh

index 6823f46..4fcb6af 100644 (file)
@@ -1,4 +1,5 @@
 *.iso
+*.img
 livecd.ks
 livecd-test.ks
 livecd-post.sh
\ No newline at end of file
index 0124250..f9622fe 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,19 +24,17 @@ LABEL        := virt-p2v-$(VERSION)
 #----------------------------------------------------------------------
 
 all:
-       @echo "make build              Build the live CD ISO"
-       @echo "make boot [ISO=foo.iso] Boot built/named ISO (uses qemu)"
+       @echo "make build     Build the live CD ISO"
+       @echo "make boot [HDA=hda.img] [HDB=hdb.img] [ISO=livecd.iso]"
+       @echo "               Boot built/named ISO (uses qemu)"
 
-build: livecd.ks
+# Build live CD.
+
+build: checkroot livecd.ks
        rm -f $(LABEL).iso
-       livecd-creator --config=$< --fslabel=$(LABEL)
+       livecd-creator --config=livecd.ks --fslabel=$(LABEL)
        ls -lhtr *.iso
 
-ISO    = $(LABEL).iso
-
-boot:
-       qemu -m 512 -cdrom $(ISO)
-
 livecd.ks: livecd.ks.in livecd-post.sh Makefile
        sed \
          -e 's|@BASEREPO@|$(BASEREPO)|g' \
@@ -55,5 +53,33 @@ livecd-post.sh: livecd-post.sh.in p2v.init virt-p2v.sh inittab Makefile
          -e '/@INITTAB@/ d' \
          < $< > $@
 
+# Run live CD under qemu.
+
+QEMU   := qemu
+ISO    := $(LABEL).iso
+HDA    :=
+HDB    :=
+
+QEMU_ARGS := -m 512 -cdrom $(ISO) -boot d
+ifneq ($(HDA),)
+QEMU_ARGS += -hda $(HDA)
+endif
+ifneq ($(HDB),)
+QEMU_ARGS += -hdb $(HDB)
+endif
+
+boot:
+       $(QEMU) $(QEMU_ARGS)
+
+# Standard rules.
+
+checkroot:
+       @if [ `id -u` -ne 0 ]; then \
+         echo "You must be root to perform this operation."; \
+         exit 1; \
+       fi
+
 clean:
        rm -f *~ core livecd.ks livecd-post.sh
+
+.PHONY:        build boot checkroot
\ No newline at end of file
index 1ed9aa7..c69d693 100644 (file)
@@ -46,6 +46,11 @@ dhclient
 which
 perl
 rpm
+lsof
+strace
+vim-minimal
+vim-enhanced
+bind-utils
 
 
 
index faaaf20..d472578 100755 (executable)
@@ -81,6 +81,20 @@ function word_in_list {
 }
 
 #----------------------------------------------------------------------
+# I/O functions
+
+# Use the function read_line instead of the shell built-in read.
+# It reads from the console.
+function read_line {
+    read "$*" </dev/console
+}
+
+# Launch a bash subshell connected to the console.
+function shell {
+    PS1='\u@\h:\w\$ ' bash </dev/console >/dev/console 2>&1
+}
+
+#----------------------------------------------------------------------
 # Device mapper snapshotting.
 
 # Create a device-mapper snapshot of a device with ramdisk overlay.
@@ -223,31 +237,42 @@ function search_parts {
 function auto_network {
     if ! mount -o ro /dev/$1 /mnt; then return 1; fi
 
+    # Make sure this file exists, otherwise Fedora gives a warning.
+    touch /etc/resolv.conf
+
     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
+    # Originally I symlinked these, but that causes dhclient to
+    # keep open /mnt (as its cwd is in network-scripts subdir).
+    # So now we will copy them recursively instead.
+    cp -r /mnt/etc/sysconfig/network .
+    cp -r /mnt/etc/sysconfig/networking .
+    cp -r /mnt/etc/sysconfig/network-scripts .
+    # This also means we can umount /mnt early.
+    umount /mnt
 
     /etc/init.d/network start
     local status=$?
 
-    rm network networking network-scripts
+    rm -rf network networking network-scripts
     mv network.saved network
     mv networking.saved networking
     mv network-scripts.saved network-scripts
-    umount /mnt
+
+    popd
+
+    ping -c 3 $remote_host
 
     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
+       read_line line </dev/console
        if [ "$line" = "y" -o "$line" = "yes" ]; then return 0; fi
        return 1
     fi
@@ -531,13 +556,13 @@ case "$network" in
        echo
        echo "When finished, exit with ^D or exit"
        echo
-       bash
+       shell
        ;;
 
     ask)
        # XXX Not implemented
        echo "Sorry, we didn't implement this one yet."
-       bash
+       shell
        ;;
 
     *)
@@ -546,7 +571,7 @@ case "$network" in
        if ! auto_network "$network"; then
            echo "Auto-configuration failed.  Starting a shell."
            echo
-           bash
+           shell
        fi
 esac