Skip to content

Instantly share code, notes, and snippets.

@rustybird
Last active October 17, 2024 16:45
Show Gist options
  • Save rustybird/750a5b28e7b285669fe90851e6f48b32 to your computer and use it in GitHub Desktop.
Save rustybird/750a5b28e7b285669fe90851e6f48b32 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
fstype=$1
_du() { du -BM img; }
_fstrim() { fstrim --verbose mnt; }
_sync() { sync; sync; }
mkdir mnt
set -o noclobber
> img
truncate -s 5G img
dev=$(losetup --direct-io --find --show img)
mkfs."$fstype" -q "$dev"
mount -o nodiscard "$dev" mnt
for i in 1 2 3; do head -c 1G /dev/random >mnt/file$i; done; _sync
for i in 1 2 ; do rm mnt/file$i; done; _sync
_du
_fstrim; _sync
_du
_fstrim; _sync
_du
_fstrim; _sync
_du
umount mnt
rmdir mnt
losetup --detach "$dev"
rm img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment