简体   繁体   English

使用DD递归写入特定文件

[英]Use DD to write specific file recursively

I have a hard drive that I want to overwrite, not with null bytes, but with a message. 我有一个我要覆盖的硬盘驱动器,不是使用空字节,而是使用消息。

48 69 64 64 65 6e 20 = "Hidden " 48 69 64 64 65 6e 20 =“隐藏”

Here's my command thus far: 到目前为止,这是我的命令:

echo "Hidden " > /myfile
dd if=/myfile of=/dev/sdb bs=1M

Note: I have also tried an assorment of parameters such as count and conv to no avail 注意:我也尝试过诸如count和conv之类的参数,但无济于事

Now, this is fine. 现在,这很好。 When I run: 当我跑:

dd if=/dev/sdb | hexdump -C | less

I can see the first few bytes written over, however, the rest is unchanged. 我可以看到写过的前几个字节,但其余的都没有改变。 I'd like to recursively write "Hidden " to the drive. 我想以递归方式将“隐藏”写入驱动器。

I don't have a spare disk to try this out on, but you can use the yes command to continuously push your string into the pipe : 我没有备用磁盘来试试这个,但你可以使用yes命令不断将你的字符串推入管道

yes "Hidden" | dd of=/dev/sdb

I assume once dd has written the whole disk, then it will close the pipe and this command will finish. 我假设一旦dd编写了整个磁盘,那么它将关闭管道并且此命令将完成。

The above will newline-delimit the "Hidden" string. 以上将换行 - 分隔“隐藏”字符串。 If you want it space-delimited, as in the question you can do: 如果你想要它以空格分隔,就像你可以做的问题一样:

yes "Hidden" | paste -d' ' -s - | dd of=/dev/sdb

Or if you want it null-delimited: 或者如果你想要以null分隔:

yes "Hidden" | tr '\n' '\0' | dd of=/dev/sdb

If you don't specify if parameter, input is read from stdin. 如果未指定if参数,则从stdin读取输入。 This allows you to do something like this: 这允许你做这样的事情:

dd of=/dev/sdb < for((i=0;i<100000;i++)); do echo 'Hidden '; done;

The value of 100000 obviously needs to be at least diskSizeInBytes / strlen('Hidden ') . 100000显然需要至少为diskSizeInBytes / strlen('Hidden ')

Given the consequences I didn't test this for you but it ought to work ;) 鉴于后果我没有为你测试这个,但它应该工作;)

dcfldd , a fork of dd, has some additional features that you may find useful. dcfldd是dd的一个分支,它有一些你可能会觉得有用的附加功能。 For example, your problem would be solved by: 例如,您的问题将通过以下方式解决:

dcfldd textpattern="Hidden " of=/dev/sdb bs=1M

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM