#----------------------------------------------------------------------
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' \
-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
}
#----------------------------------------------------------------------
+# 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.
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
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
;;
*)
if ! auto_network "$network"; then
echo "Auto-configuration failed. Starting a shell."
echo
- bash
+ shell
fi
esac