Last active
October 17, 2024 16:45
-
-
Save rustybird/750a5b28e7b285669fe90851e6f48b32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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