You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.2 KiB

16 years ago
#!/bin/bash
TEST_DESCRIPTION="root filesystem over iSCSI"
KVERSION=${KVERSION-$(uname -r)}
#DEBUGFAIL="rdshell"
run_server() {
# Start server first
echo "iSCSI TEST SETUP: Starting DHCP/iSCSI server"
$testdir/run-qemu -hda server.ext2 -hdb root.ext2 -m 256M -nographic \
-net nic,macaddr=52:54:00:12:34:56,model=e1000 \
-net socket,mcast=230.0.0.1:1235 \
-serial udp:127.0.0.1:9999 \
-kernel /boot/vmlinuz-$KVERSION \
-append "root=/dev/sda rw quiet console=ttyS0,115200n81 selinux=0" \
-initrd initramfs.server -pidfile server.pid -daemonize || return 1
sudo chmod 644 server.pid || return 1
# Cleanup the terminal if we have one
tty -s && stty sane
echo Sleeping 10 seconds to give the server a head start
sleep 10
}
run_client() {
# Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
if ! dd if=/dev/zero of=client.img bs=1M count=1; then
echo "Unable to make client sda image" 1>&2
return 1
fi
$testdir/run-qemu -hda client.img -m 256M -nographic \
-net nic,macaddr=52:54:00:12:34:00,model=e1000 \
-net socket,mcast=230.0.0.1:1235 \
-kernel /boot/vmlinuz-$KVERSION \
16 years ago
-append "root=dhcp rw quiet rdinitdebug rdinfo rdnetdebug console=ttyS0,115200n81 selinux=0 rdshell $DEBUGFAIL" \
-initrd initramfs.testing
grep -m 1 -q iscsi-OK client.img || return 1
}
16 years ago
test_run() {
if ! run_server; then
echo "Failed to start server" 1>&2
return 1
fi
run_client
if [[ -s server.pid ]]; then
sudo kill -TERM $(cat server.pid)
rm -f server.pid
fi
16 years ago
}
test_setup() {
if [ ! -x /usr/sbin/iscsi-target ]; then
echo "Need iscsi-target from netbsd-iscsi"
return 1
fi
# Create the blank file to use as a root filesystem
dd if=/dev/zero of=root.ext2 bs=1M count=20
16 years ago
kernel=$KVERSION
16 years ago
# Create what will eventually be our root filesystem onto an overlay
(
initdir=overlay/source
. $basedir/dracut-functions
dracut_install sh shutdown poweroff stty cat ps ln ip \
/lib/terminfo/l/linux mount dmesg mkdir \
cp ping grep
inst ./client-init /sbin/init
16 years ago
(cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
ldconfig -n -r "$initdir" /lib* /usr/lib*
16 years ago
)
# second, install the files needed to make the root filesystem
(
initdir=overlay
. $basedir/dracut-functions
dracut_install sfdisk mke2fs poweroff cp umount
initqueue now loops until /dev/root exists or root is mounted init now has the following points to inject scripts: /cmdline/*.sh scripts for command line parsing /pre-udev/*.sh scripts to run before udev is started /pre-trigger/*.sh scripts to run before the main udev trigger is pulled /initqueue/*.sh runs in parallel to the udev trigger Udev events can add scripts here with /sbin/initqueue. If /sbin/initqueue is called with the "--onetime" option, the script will be removed after it was run. If /initqueue/work is created and udev >= 143 then this loop can process the jobs in parallel to the udevtrigger. If the udev queue is empty and no root device is found or no root filesystem was mounted, the user will be dropped to a shell after a timeout. Scripts can remove themselves from the initqueue by "rm $job". /pre-mount/*.sh scripts to run before the root filesystem is mounted NFS is an exception, because it has no device node to be created and mounts in the udev events /mount/*.sh scripts to mount the root filesystem NFS is an exception, because it has no device node to be created and mounts in the udev events If the udev queue is empty and no root device is found or no root filesystem was mounted, the user will be dropped to a shell after a timeout. /pre-pivot/*.sh scripts to run before the real init is executed and the initramfs disappears All processes started before should be killed here. The behaviour of the dmraid module demonstrates how to use the new mechanism. If it detects a device which is part of a raidmember from a udev rule, it installs a job to scan for dmraid devices, if the udev queue is empty. After a scan, it removes itsself from the queue.
16 years ago
inst_simple ./create-root.sh /initqueue/01create-root.sh
16 years ago
)
# create an initramfs that will create the target root filesystem.
# We do it this way so that we do not risk trashing the host mdraid
# devices, volume groups, encrypted partitions, etc.
$basedir/dracut -l -i overlay / \
-m "dash crypt lvm mdraid udev-rules base rootfs-block kernel-modules" \
16 years ago
-d "ata_piix ext2 sd_mod" \
-f initramfs.makeroot $KVERSION || return 1
16 years ago
rm -rf overlay
# Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
if ! dd if=/dev/zero of=client.img bs=1M count=1; then
echo "Unable to make client sdb image" 1>&2
return 1
fi
16 years ago
# Invoke KVM and/or QEMU to actually create the target filesystem.
$testdir/run-qemu -hda root.ext2 -hdb client.img -m 256M -nographic -net none \
16 years ago
-kernel "/boot/vmlinuz-$kernel" \
-append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
16 years ago
-initrd initramfs.makeroot || return 1
grep -m 1 -q dracut-root-block-created client.img || return 1
rm client.img
16 years ago
(
initdir=overlay
. $basedir/dracut-functions
dracut_install poweroff shutdown
inst_simple ./hard-off.sh /emergency/01hard-off.sh
16 years ago
)
sudo $basedir/dracut -l -i overlay / \
-o "plymouth dmraid" \
-a "debug" \
16 years ago
-d "ata_piix ext2 sd_mod" \
-f initramfs.testing $KVERSION || return 1
# Make server root
dd if=/dev/zero of=server.ext2 bs=1M count=60
mke2fs -F server.ext2
mkdir mnt
sudo mount -o loop server.ext2 mnt
kernel=$KVERSION
(
initdir=mnt
. $basedir/dracut-functions
(
cd "$initdir";
mkdir -p dev sys proc etc var/run tmp var/lib/dhcpd /etc/iscsi
)
inst /etc/passwd /etc/passwd
dracut_install sh ls shutdown poweroff stty cat ps ln ip \
/lib/terminfo/l/linux dmesg mkdir cp ping \
modprobe tcpdump \
/etc/services sleep mount chmod
dracut_install /usr/sbin/iscsi-target
instmods iscsi_tcp crc32c ipv6
inst ./targets /etc/iscsi/targets
[ -f /etc/netconfig ] && dracut_install /etc/netconfig
which dhcpd >/dev/null 2>&1 && dracut_install dhcpd
[ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
inst ./server-init /sbin/init
inst ./hosts /etc/hosts
inst ./dhcpd.conf /etc/dhcpd.conf
dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
inst /etc/group /etc/group
/sbin/depmod -a -b "$initdir" $kernel
ldconfig -n -r "$initdir" /lib* /usr/lib*
)
sudo umount mnt
rm -fr mnt
# Make server's dracut image
$basedir/dracut -l -i overlay / \
-m "dash udev-rules base rootfs-block debug kernel-modules" \
-d "ata_piix ext2 sd_mod e1000" \
-f initramfs.server $KVERSION || return 1
16 years ago
}
test_cleanup() {
if [[ -s server.pid ]]; then
sudo kill -TERM $(cat server.pid)
rm -f server.pid
fi
rm -rf mnt overlay
rm -f client.ext2 server.ext2 client.img initramfs.server initramfs.testing
rm -f initramfs.makeroot root.ext2
16 years ago
}
. $testdir/test-functions