Skip to content

Instantly share code, notes, and snippets.

@tobert
Last active August 29, 2015 14:17
Show Gist options
  • Save tobert/02ccf4cd856fcce7bb8d to your computer and use it in GitHub Desktop.
Save tobert/02ccf4cd856fcce7bb8d to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script creates a 128MB loopback file + device then puts
# dm-delay in front of it to cause all IOs to take >= 500ms.
bytes=$((2**27)) # 134217728 or 128MB
blocks=$(($bytes / 512)) # 262144
# create the loopback file
dd if=/dev/zero of=/srv/tmp.img bs=512 count=$(($blocks + 32))
# create the loop device, --show makes it print the /dev
loop=$(losetup --find --show /srv/tmp.img)
# create the delay target device on top of the loop device
echo "0 $blocks delay $loop 0 500" | dmsetup create delay
# create an ext4 filesystem - it will be slow since IOs are 500ms
mkfs.ext4 /dev/mapper/delay # takes a while
mkdir -p /mnt/delay
mount /dev/mapper/delay /mnt/delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment