summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Woods <wwoods@redhat.com>2012-04-30 14:40:37 -0400
committerWill Woods <wwoods@redhat.com>2012-04-30 14:40:37 -0400
commit39713006dc1012f2537a9cae9a3f09e21469837e (patch)
tree5e82e08525c682d844076369f81a0c015ca57a5f
downloadtestboot-39713006dc1012f2537a9cae9a3f09e21469837e.tar.gz
testboot-39713006dc1012f2537a9cae9a3f09e21469837e.tar.xz
testboot-39713006dc1012f2537a9cae9a3f09e21469837e.zip
Initial commit.
-rw-r--r--README10
-rwxr-xr-xtestboot.sh168
2 files changed, 178 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..128a7fc
--- /dev/null
+++ b/README
@@ -0,0 +1,10 @@
+Hi! This is my super-fancy test script that I use for working on the dracut
+module in anaconda. It was never intended for public release so I don't really
+care that it's ugly and kind of stupid in places. It gets the job done and
+that's good enough for me.
+
+If you're reading this, I hope maybe some of this will be useful to you?
+
+-w
+
+Will Woods <wwoods@redhat.com>
diff --git a/testboot.sh b/testboot.sh
new file mode 100755
index 0000000..1ec7e32
--- /dev/null
+++ b/testboot.sh
@@ -0,0 +1,168 @@
+#!/bin/bash
+
+# defaults
+dir=/home/wwoods/test/qemu/dracut
+dracutdir=/home/wwoods/src/dracut
+anacondadir=/home/wwoods/src/anaconda
+ram=768
+disk=$dir/disk.img
+disk2=$dir/disk2.img
+#cdrom=$dir/iso/Fedora-17-x86_64-DVD.iso
+cdrom=$dir/iso/fedora-17-x86_64-netinst.iso
+#graphics="spice"
+graphics="vnc"
+
+usecd="true"
+ARGS=$(getopt --options "dcstm:" \
+ --longoptions "fromcd,nocd,virtconsole,serialconsole,text,ram:" \
+ --name testboot.sh \
+ -- "$@") || exit 1
+eval set -- "$ARGS"
+while :; do case "$1" in
+ -d|--fromcd) fromcd="true"; shift;;
+ --nocd) usecd=""; shift;;
+ -c|--virtconsole) console="--console pty"; shift;;
+ -s|--serialconsole) console="--serial pty"; shift;;
+ -t|--text) graphics="none"; shift;;
+ -m|--ram) ram="$2"; shift 2;;
+ --) shift; break;;
+ *) echo "getopt parse error"; exit 1 ;;
+esac; done
+
+if [ ! -f $cdrom ]; then
+ echo "Can't find cdrom!"
+ exit 1
+fi
+
+[ $(id -u) = 0 ] || { echo "be root."; exit 1; }
+chcon -t virt_content_t $cdrom
+
+
+get_modules() {
+ local cat=cat
+ case `file $1` in
+ *:\ gzip*) cat=zcat ;;
+ *:\ xz*|*:\ XZ*) cat=xzcat ;;
+ esac
+ echo -n "finding kernel version..."
+ moddir=$($cat $1 | cpio --quiet -t */modules.dep)
+ moddir=${moddir%/modules.dep}
+ kv=${moddir##*/}
+ echo "$kv"
+ if [ ! -d /lib/modules/$kv ]; then
+ echo -n "getting modules..."
+ tmpdir=$dir/.modules.tmp
+ mkdir -p $tmpdir
+ ( cd $tmpdir; $cat $1 | cpio --quiet -iumd $moddir/* )
+ mv $tmpdir/$moddir /lib/modules/$kv
+ rm -rf $tmpdir
+ echo "done"
+ fi
+ if [ ! -f $dir/.buildstamp ]; then
+ echo -n "getting buildstamp..."
+ $cat $1 | cpio --quiet -ium .buildstamp
+ echo "done"
+ fi
+}
+
+apply_updates() {
+ (
+ cd $dir/updates
+ find . -depth -type d | while read d; do
+ [ ! -d "../initramfs/$d" ] && mkdir -p "../initramfs/$d"
+ done
+ find . -depth \! -type d | while read f; do
+ cp -a "$f" "../initramfs/$f"
+ echo " ${f#.}"
+ done
+ )
+}
+
+initrd_cpio() {
+ ( cd $dir/initramfs; find . | cpio -co ) 2>/dev/null
+}
+
+if [ "$fromcd" != "true" ]; then
+ kernel_args="$@"
+
+ # check RAM
+ [ "$ram" -lt 768 ] && kernel_args="$* inst.memcheck=0"
+
+ # do we need to pull out the kernel/modules?
+ vmlinuz="$dir/vmlinuz"
+ [ -e $vmlinuz.kv ] && kv=$(< $vmlinuz.kv)
+ if [ $cdrom -nt $vmlinuz -o -z "$kv" -o ! -d /lib/modules/$kv ]; then
+ echo "getting kernel and modules"
+ umount .mnt &>/dev/null
+ mkdir -p $dir/.mnt
+ if mount -o ro,loop $cdrom $dir/.mnt; then
+ cp -f $dir/.mnt/isolinux/vmlinuz $vmlinuz
+ cp -f $dir/.mnt/isolinux/initrd.img initrd.img.orig
+ get_modules $dir/.mnt/isolinux/initrd.img # sets $kv
+ umount $dir/.mnt
+ [ -z "$kv" ] && echo "couldn't figure out kernel ver??" && exit 1
+ echo "$kv" > $vmlinuz.kv
+ fi
+ rmdir $dir/.mnt
+ rm -rf $dir/initramfs
+ fi
+
+ # do we need to rebuild initrd?
+ initrd="$dir/initrd.img"
+ if [ ! -d $dir/initramfs ] || [ $cdrom -nt $dir/initramfs ]; then
+ echo "rebuilding initramfs"
+ # TODO: check for $dracutdir/dracut.sh and git pull otherwise
+ if ! [ -f $dracutdir/modules.d/80anaconda/parse-kickstart ]; then
+ if [ ! -d $anacondadir/dracut ]; then
+ # TODO: git pull
+ echo "ERROR: can't find anaconda dracut module :/"
+ exit 1
+ else
+ ln -s $anacondadir/dracut $dracutdir/modules.d/80anaconda
+ fi
+ fi
+ rm -rf $dir/initramfs $initrd
+ (
+ cd $dracutdir
+ ./dracut.sh --local --no-compress --nomdadmconf --nolvmconf \
+ --prefix /run/initramfs --add anaconda \
+ --omit plymouth \
+ $dir/.initrd.cpio $kv
+ ) || exit 1
+ rm -rf $dir/.initramfs.tmp; mkdir $dir/.initramfs.tmp
+ ( cd $dir/.initramfs.tmp; cpio -iumd ) < $dir/.initrd.cpio
+ rm -f $dir/.initrd.cpio
+ mv $dir/.initramfs.tmp $dir/initramfs
+ cp $dir/.buildstamp $dir/initramfs/.buildstamp
+ fi
+
+ if [ ! -e $initrd ] || \
+ find initramfs updates -newer $initrd | grep -q .; then
+ echo "applying updates to initramfs"
+ apply_updates
+ echo "making initrd.img"
+ initrd_cpio | xz -1 --check=crc32 > $dir/.initrd.tmp || exit 1
+ mv -f $dir/.initrd.tmp $initrd
+ fi
+
+ bootarg="kernel=$vmlinuz,initrd=$initrd,kernel_args=$kernel_args"
+fi
+
+echo "Creating 'testboot' guest..."
+virsh destroy testboot &>/dev/null
+virsh undefine testboot &>/dev/null
+virt-install --name testboot --ram $ram --graphics $graphics \
+ --os-type linux --os-variant fedora16 $console \
+ --disk $disk,size=10 --disk $disk2,size=10 \
+ --network network=default,model=virtio,mac=52:54:00:03:31:38 \
+ ${usecd:+--disk $cdrom,device=cdrom} \
+ ${bootarg:+--boot "$bootarg"}
+virsh destroy testboot &>/dev/null
+
+# historical interest: this is how it'd work in qemu
+do_qemu() {
+ echo "starting qemu"
+ echo "C-a x to exit, C-a c for console monitor"
+ qemu-kvm -m $ram -kernel $kernel -initrd $initrd \
+ -cdrom $cdrom -nographic -append $kernel_args
+}