dd : Basic behaviour not what expected
I know the Learn the DD command page here in LQ
and I have read the FM ;-) But I can't understand something very basic with DD Let me show an example : Here an USB stick with a dos parts table, 1 NFS part with some Files written onto Code:
Disque /dev/sdb : 14,9 GiB, 16008609792 octets, 31266816 secteurs Code:
# dd if=/dev/sdb of=mbr.img bs=512 count=1 conv=noerror,sync Code:
# dd if=mbr.img of=/dev/sdb bs=512 I would have an empty pen drive with the same NTFS part, but the files are still here. Normaly I should use : Code:
# dd if=mbr.img of=/dev/sdb bs=512 conv=notrunc So, please someone might tell me where I'm wrong ? Thanks. If that matters I'm running Bash on Debian Testing Code:
|
All you have done is copy one sector, then write the same data back. Why would you think that would affect your files (or the filesystem) that exist elsewhere on the disk ?. The partition table merely defines the start and length of each partition - nothing more.
|
Quote:
Quote:
|
The files are still there because you haven't altered the part of the disk they are on. You've only rewritten the MBR. And since the new MBR is identical to the old one, the partition table inside it will still allow the kernel to find out where the first partition starts and so find the files.
Also, according to https://stackoverflow.com/questions/...a-disk-with-dd, the notrunc option doesn't affect device files. |
Quote:
But there is no mention of such behaviour in the FM :( Is there other kinds of exception that basic user should be aware ? |
this is not an exception, this is how things work.
If you write a file (in a filesystem) the size will be determined based on the data you write into it. dd, copy and a lot of other tools will remove your original file and create a new one (= overwrite). But if you write data directly onto a physical device you cannot remove/overwrite files but simply overwrite blocks on the device. Obviously non-touched blocks will not be affected. It is your own decision [a basic user should be aware of] if you dd into a file on a filesystem or on a device - without using any filesystem. |
All times are GMT -5. The time now is 10:40 PM. |