From bb875bd7a3846ac1241b8317db9d9ac0a49e52fa Mon Sep 17 00:00:00 2001 From: rjones Date: Wed, 12 Sep 2007 15:16:39 +0100 Subject: [PATCH] More --- .cvsignore | 1 + Makefile | 44 +++++++++++++++++++++++++++++++++++--------- livecd.ks.in | 5 +++++ virt-p2v.sh | 43 ++++++++++++++++++++++++++++++++++--------- 4 files changed, 75 insertions(+), 18 deletions(-) diff --git a/.cvsignore b/.cvsignore index 6823f46..4fcb6af 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,4 +1,5 @@ *.iso +*.img livecd.ks livecd-test.ks livecd-post.sh \ No newline at end of file diff --git a/Makefile b/Makefile index 0124250..f9622fe 100644 --- 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 diff --git a/livecd.ks.in b/livecd.ks.in index 1ed9aa7..c69d693 100644 --- a/livecd.ks.in +++ b/livecd.ks.in @@ -46,6 +46,11 @@ dhclient which perl rpm +lsof +strace +vim-minimal +vim-enhanced +bind-utils diff --git a/virt-p2v.sh b/virt-p2v.sh index faaaf20..d472578 100755 --- a/virt-p2v.sh +++ b/virt-p2v.sh @@ -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 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