Skip to content

Instantly share code, notes, and snippets.

@halferty
Created May 4, 2024 23:07
Show Gist options
  • Save halferty/43880eac6a00e8f715083f252b81e5e6 to your computer and use it in GitHub Desktop.
Save halferty/43880eac6a00e8f715083f252b81e5e6 to your computer and use it in GitHub Desktop.
Fill a drive with random data
#!/bin/bash
ruby "$(dirname "${BASH_SOURCE[0]}")/filldrive.rb" $@
current_dir = `pwd`.strip
# Ensure we're filling a drive in /Volumes, (and not Macintosh HD!!!)
if current_dir.start_with?("/Volumes") == false
puts "Please run this script from a directory in /Volumes"
exit
elsif current_dir.include?("Macintosh HD")
puts "Please don't run this script from the Macintosh HD directory!"
exit
end
gigs = ARGV[0].to_i
puts "Filling drive with #{gigs} gigs of data"
puts "This will take a while..."
# Create files with random sizes from 1MB to 1GB, until target size is reached
total_size = 0
while total_size < gigs * 1024
size = rand(1024) + 1
total_size += size
puts "Creating file of size #{size}MB, total size: #{total_size}MB"
`openssl rand -out fillsample#{total_size}.txt -base64 #{2**20 * size}`
end
puts "Drive filled with #{total_size}MB of data"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment