4 ms·
If I recall correctly: dd if=/dev/urandom of=/home/myrandomfile bs=1 count=N
by ape4 6mo ago
If I recall correctly:
dd if=/dev/urandom of=/home/myrandomfile bs=1 count=N
- fragmede 6mo agobs=1 is a recipe for waiting far longer than you have to because of the overhead of the system calls. Better bs=N count=1
- deleted 6mo ago[deleted]
- __david__ 6mo agoThat’s also not great if you’re trying to make a 10 gigabyte file. In that case, use bs=1M and count=SizeInMB.
- marcosdumay 6mo agoModern computers are crazily overengineered... Most current desktops (smaller than your usual server) won't have any problem with the GP's command. Yours is still better, of course.
- Twirrim 6mo agoIf you want to do it really quickly openssl enc -aes-256-ctr -pbkdf2 -pass pass:"$(date '+%s')" < /dev/zero | dd of=/home/myrandomfile bs=1M count=1024 Almost all CPUs have AES native instructions so you'll be able to produce pseudorandom junk really fast. Even my old system will produce it at about 3Gb/s. Much faster than urandom can go.
- ape4 6mo agoThat's very cool. Sadly running that exact command gets an incomplete file and error "error writing output file". It suggests adding iflag=fullblock (to dd). Running that makes a file of the correct size. But still gives "error writing output file". I suppose that occurs because dd breaks the pipe.
- Twirrim 6mo agoWeird, I could have sworn that used to work, maybe I wrote the notes down wrong. Easiest alternative I guess is to pipe through head. It still grumbles, but it does work openssl enc -aes-256-ctr -pbkdf2 -pass pass:"$(date '+%s')" < /dev/zero | head -c 10M > foo
- tdeck 6mo agoFwiw you can also do this with head -c 1G /dev/urandom > /home/myrandomfile And not have to remember dd's bizarre snowflake command syntax.
- bugfix 6mo agoI just use fallocate to create a 1GB or 2GB file, depending on the total storage size. It has saved me twice now. I had a nasty issue with a docker container log quickly filling up the 1GB space before I could even identify the problem, causing the shell to break down and commands to fail. After that, I started creating a 2GB file.
- ape4 6mo agoInteresting! I did `fallocate -l 1G myfile` - very fast. Its all zeros but probably won't be compressed by the filesystem since its created with the fallocate() system call.
- dotancohen 6mo agoMy choice has always been `shred`: $ sudo truncate --size 1G /emergency-space $ sudo shred /emergency-space I find it widely available, even in tiny distros.
- ape4 6mo agoVery cool. Reading the man page I see, by default, shred does 3 iterations. Adding --iterations=1 makes it random enough for this purpose and faster.
- dotancohen 6mo agoTerrific, thank you!