#!/bin/sh set -e #CRYPTSETUP=/lib/systemd/systemd-cryptsetup CRYPTSETUP=./systemd-cryptsetup rc=0 modprobe scsi_debug while [ -z $devpath ]; do devpath=$(udevadm trigger --verbose --dry-run --property-match=ID_MODEL=scsi_debug) sleep 0.1 done devnode=/dev/$(basename $devpath) [ -b "$devnode" ] echo "creating normal swap partition..." mkswap $devnode blkid -p $devnode uuid=$(blkid -o value -s UUID -p $devnode) echo "attaching..." $CRYPTSETUP attach testcryptswap1 /dev/disk/by-uuid/$uuid /dev/urandom 'swap,offset=1024,cipher=aes-xts-plain64' /sbin/mkswap /dev/mapper/testcryptswap1 echo "checking that raw swap UUID is still valid" [ "$(blkid -o value -s UUID -p /dev/sdb)" = $uuid ] || { echo "FAIL: UUID of raw device changed!" >&2 rc=1 } blkid -p /dev/mapper/testcryptswap1 | grep 'TYPE="swap"' echo "stopping cryptswap.." $CRYPTSETUP detach testcryptswap1 echo "checking that raw swap UUID is still valid" [ "$(blkid -o value -s UUID -p /dev/sdb)" = $uuid ] || { echo "FAIL: UUID of raw device changed!" >&2 rc=1 } rmmod scsi_debug exit $rc