Update test framework to create and use LVM on cryptroot
authorVictor Lowther <victor.lowther@gmail.com>
Mon, 16 Mar 2009 09:42:02 +0000 (04:42 -0500)
committerVictor Lowther <victor.lowther@gmail.com>
Fri, 20 Mar 2009 08:08:39 +0000 (03:08 -0500)
12 files changed:
dracut
modules.d/00test/check [new file with mode: 0755]
modules.d/00test/copy-root.sh [new file with mode: 0755]
modules.d/00test/create-root.sh [new file with mode: 0755]
modules.d/00test/halt.sh [new file with mode: 0755]
modules.d/00test/install [new file with mode: 0755]
modules.d/90crypt/cryptroot.sh
modules.d/90crypt/install
modules.d/99base/init
test/dracut.conf.test
test/make-test-root
test/test-initramfs

diff --git a/dracut b/dracut
index eb3ff24..7a14765 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -19,6 +19,7 @@ while (($# > 0)); do
        -c|--conf) conffile="$2"; shift;;
        -l|--local) allowlocal="yes" ;;
        -h|--hostonly) hostonly="-h" ;;
+       -i|--include) include_src="$2"; include_target="$3"; shift 2;;
        --skip-missing) skipmissing="yes" ;;
        *) break ;;
     esac
@@ -102,4 +103,9 @@ unset moddir
 # make sure that library links are correct and up to date
 ldconfig -n -r "$initdir" /lib* /usr/lib*
 
+[[ $include_src && $include_target ]] && {
+    mkdir -p "$initdir$include_target"
+    cp -a -t "$initdir$include_target" "$include_src"/*
+}
+
 ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
diff --git a/modules.d/00test/check b/modules.d/00test/check
new file mode 100755 (executable)
index 0000000..afe8ade
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+exit 1
diff --git a/modules.d/00test/copy-root.sh b/modules.d/00test/copy-root.sh
new file mode 100755 (executable)
index 0000000..fe9f57a
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+cp -a -t "$NEWROOT" /source/*
\ No newline at end of file
diff --git a/modules.d/00test/create-root.sh b/modules.d/00test/create-root.sh
new file mode 100755 (executable)
index 0000000..ce9f40b
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+sfdisk /dev/sda <<EOF
+
+;
+;
+;
+EOF
+cryptsetup -q luksFormat /dev/sda1 <<EOF
+test
+EOF
+cryptsetup luksOpen /dev/sda1 dracut_crypt_test <<EOF
+test
+EOF
+lvm pvcreate -ff  -y /dev/mapper/dracut_crypt_test
+lvm vgcreate dracut /dev/mapper/dracut_crypt_test
+lvm lvcreate -l 100%FREE -n root dracut
+udevadm settle --timeout=4
+[ -b /dev/dracut/root ] || emergency_shell
+mke2fs /dev/dracut/root
\ No newline at end of file
diff --git a/modules.d/00test/halt.sh b/modules.d/00test/halt.sh
new file mode 100755 (executable)
index 0000000..5d51e8b
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+umount "$NEWROOT"
+lvm lvchange -a n /dev/dracut/root
+cryptsetup luksClose /dev/mapper/dracut_crypt_test
+poweroff -f
\ No newline at end of file
diff --git a/modules.d/00test/install b/modules.d/00test/install
new file mode 100755 (executable)
index 0000000..46a83af
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+dracut_install sfdisk mke2fs poweroff cp umount
+inst_hook pre-pivot 02 "$moddir/halt.sh"
+inst_hook pre-pivot 01 "$moddir/copy-root.sh"
+inst_hook pre-mount 01 "$moddir/create-root.sh"
\ No newline at end of file
index 86e3bbf..d00d5cc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 [ -s /cryptroot ] && { 
-    udevadm control --stop-exec-queue
+    udevadm control --stop_exec_queue
     while read cryptopts; do
        (   exec >/dev/console 2>&1 </dev/console
           set $cryptopts
@@ -8,6 +8,6 @@
        )
     done </cryptroot
     >/cryptroot
-    udevadm control --start-exec-queue
+    udevadm control --start_exec_queue
     udevadm settle --timeout=30
 }
index 92b5169..82f8ffd 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/bash
 inst cryptsetup
+instmods dm_crypt =crypto
 inst_rules "$moddir/63-luks.rules"
 inst_hook mount 10 "$moddir/cryptroot.sh"
\ No newline at end of file
index b45bb7b..5661d60 100755 (executable)
@@ -41,7 +41,7 @@ mount -t sysfs /sys /sys >/dev/null 2>&1
 mount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1
 
 read CMDLINE </proc/cmdline;
-
+getarg debug && set -x
 # Make some basic devices first, let udev handle the rest
 mknod /dev/ptmx c 5 2
 mknod /dev/console c 5 1
@@ -77,6 +77,9 @@ while :; do
     [ $i -gt 10 ] && emergency_shell
 done
 
+getarg 'break=pre-pivot' && emergency_shell
+source_all pre-pivot
+
 # by the time we get here, the root filesystem should be mounted.
 # Try to find init.
 for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
@@ -89,8 +92,7 @@ done
 }
 
 # pre pivot scripts are sourced just before we switch over to the new root.
-getarg 'break=pre-pivot' && emergency_shell
-source_all pre-pivot
+
 getarg break && emergency_shell
 kill $(pidof udevd)
 echo "Switching to real root filesystem $root"
index 7273df7..d6c1742 100644 (file)
@@ -1,2 +1,2 @@
-dracutmodules="kernel-modules udev-rules base"
+dracutmodules="kernel-modules crypt lvm udev-rules base"
 modules="ata_piix ext2 sd_mod"
index 474c9af..f310d5f 100755 (executable)
@@ -1,15 +1,22 @@
 #!/bin/bash
-. ./dracut-functions
-readonly initdir=$(mktemp -d -t initramfs-test-XXXXXXXX)
-readonly mnttarget=$(mktemp -d -t initramfs-test-target-XXXXXXXX)
-trap 'rm -rf "$initdir"' 0
-dracut_install sh df free ls shutdown poweroff stty cat ps ln \
-    /lib/terminfo/l/linux mount dmesg
-inst test/test-init /sbin/init
-dd if=/dev/zero of=test/root.ext2 bs=1M count=10
-mke2fs -F test/root.ext2
-mount -o loop -t ext2 test/root.ext2 "$mnttarget"
-cp -a -t "$mnttarget" "$initdir"/*
-(cd "$mnttarget"; mkdir -p dev sys proc etc)
-umount -l "$mnttarget"
-rm -rf "$mnttarget" "$initdir"
\ No newline at end of file
+initdir=$(mktemp -d -t initramfs-test-target-XXXXXXXX)
+kernel=$(uname -r)
+(
+    . ./dracut-functions
+    dracut_install sh df free ls shutdown poweroff stty cat ps ln \
+       /lib/terminfo/l/linux mount dmesg
+    inst test/test-init /sbin/init
+    (cd "$initdir"; mkdir -p dev sys proc etc)
+)
+targetfs="$initdir"
+unset initdir
+dd if=/dev/zero of=test/root.ext2 bs=1M count=20
+./dracut -l -i "$targetfs" /source \
+    -m "dash kernel-modules test crypt lvm udev-rules base" \
+    -d "ata_piix ext2 sd_mod" \
+    -f test/initramfs.makeroot
+
+qemu-kvm -hda test/root.ext2 -m 512M -nographic -net none \
+    -kernel "/boot/vmlinuz-$kernel" \
+    -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
+    -initrd test/initramfs.makeroot
\ No newline at end of file
index 2fde6e3..3975d1f 100755 (executable)
@@ -3,7 +3,7 @@ kernel=$(uname -r)
 [[ -f test/root.ext2 ]] || test/make-test-root
 ./dracut -c test/dracut.conf.test -l -f test/initramfs.testing || exit
 
-exec qemu-kvm -hda test/root.ext2 -nographic -net none \
+qemu-kvm -hda test/root.ext2 -m 512M -nographic -net none \
     -kernel /boot/vmlinuz-$kernel \
-    -append "root=/dev/sda rw rootfstype=ext2 console=ttyS0,115200n81 quiet" \
+    -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
     -initrd test/initramfs.testing
\ No newline at end of file