Ubuntu – What happens when I use ‘dd’ to overwrite the disk from which Ubuntu is running

ddpartitioningsecure-eraseuninstall

What would happen if I use

sudo dd if=/dev/zero of=/dev/sda

from an Ubuntu install running from /dev/sda?


I tried it in a VM, and it appears to correctly have wiped the disk. Will this be the case every time? Is this a secure way to "wipe" an Ubuntu install and all data?

My question is somewhat inspired by:

  1. How do I uninstall Ubuntu from a computer?
  2. How is 'rm -rf /' able to delete all files in the system?.

Best Answer

Actually, the filesystem is still mounted, and some writes are buffered meaning they are still in RAM waiting to be written to the disk. Let's say dd correctly overwrites everything, and just behind it the buffers are getting flushed and some potentially sensitive data is getting written back to the disk. So no, this is not a secure way of wiping a disk.

You can avoid this issue by first remounting in read-only mode the root filesystem and any other filesystems that are on the disk (or unmounting them completely, but you won't be able to with the root file system), and then, no more writes should be allowed on the filesystems at all (so no buffers to flush) so your command should be safe now, even though it's still a bad idea in case of panic because it takes a long time.

If you want to have some sort of panic delete feature, I suggest encrypting your disk with LUKS (the Ubuntu installer can do that) and then following my answer over on Security Stack Exchange. This involves wiping the cryptheader which is only 2MBs in size and that takes less than a second to overwrite. Then restart the system and the disk encryption keys will be gone from memory, with no ways to restore them since the cryptheader itself is gone as well.

Related Question