为什么/dev/random和/dev/urandom在32MiB后停止?



我在下面列出的单个命令行中得到了这个输出:

0+1 records in
0+1 records out
33554431 bytes (34 MB, 32 MiB) copied, 0.14532 s, 231 MB/s

以下是我尝试过的不同选项:

a)dd if=/dev/random of=/dev/null status=progress bs=1G count=1

b)dd if=/dev/urandom of=/dev/null status=progress bs=1G count=1

c)dd if=/dev/urandom of=/dev/null status=progress bs=100M count=1

d)dd if=/dev/urandom of=/dev/null status=progress bs=50M count=1

e)dd if=/dev/random of=/dev/null status=progress bs=50M count=1

f)dd if=/dev/random of=/dev/null status=progress bs=33M count=1

g)dd if=/dev/urandom of=/dev/null status=progress bs=33M count=1

dd if=/dev/urandom of=/dev/null status=progress bs=10M count=1按预期执行并输出:

1+0 records in
1+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0518184 s, 202 MB/s

我在MX Linux (Kernel 5.10)、KDE neon和Ubuntu 20.04上尝试了这个

有人有秘密的答案吗?或者一些可能的想法?

来自Linux手册页:

从Linux 3.16开始,从/dev/urandom读取(2)将最多返回一次32 MB

原因在于它是一个特殊的字符文件,与底层驱动程序接口,而不是一个"常规"字符文件。文件。在这种情况下,底层驱动程序将输出大小限制为32 MB。这里的另一个答案提供了关于此事的更多细节。

bs,缓冲区大小,表示dd执行的单个read()调用的大小。

(例如,bs=1M count=1和bs=1k count=1k都将产生一个1 MiB文件,但是第一个版本将在一个步骤中完成,而第二个版本将在1024个小块中完成。)

我有一个解决方案,读取32块32 MB大,使1GB:

dd if=/dev/urandom of=output bs=32M count=32

最新更新