6

I can wipe a single partition:

dd if="/dev/zero" of="/dev/sdaX"

or I can wipe the whole disk along with all partitions on it:

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

But what if I wanted to keep my current partitions and wipe any data on the unpartitioned space which may have been used by a previous partition scheme?

1 Answer 1

6

There is an easy way and a hard way.

The hard way is to identify the beginning and end of your unpartitioned space, and do

dd if=/dev/zero of=/dev/sda seek=10000 obs=512 count=20000 bs=512

This is saying, skip the first 10000x512 bytes and then write zeros for 20000x512 bytes.

You need to make sure you get your sector math correct to ensure you are targetting the right portion of the disk, otherwise there is risk of overwriting real data. Which leads me to the easy way:

  1. Create a partition in the unpartitioned space
  2. dd as normal for a partition
  3. Delete the partition
7
  • It is not always easy to figure out how to create a partition that covers all of the unpartitioned space, particularly if some of the existing partitions are not aligned the way your partitioning tool expects. Can you offer any tips on how to accomplish this? Aug 1, 2016 at 21:02
  • @NateEldredge Do you mean where fdisk reports that the partition doesn't end on a cylinder boundary? This doesn't matter normally, and you can still make the next partition right on the next sector after the previous partition.
    – Paul
    Aug 2, 2016 at 1:25
  • Sorry, I realized my problem was not about alignment, but about logical partitions in an extended partition: the EBRs typically get stored in unallocated space between logical partitions. So you can't create logical partitions that use all the space; there's at least one sector you will miss, and it's hard to figure out which one it is. But for primary partitions there is no problem, you're right. Aug 2, 2016 at 3:58
  • @NateEldredge Yeah I see what you mean. In those cases (assuming you couldn't delete the entire extended partition and create a primary) you'd have to resort to sector math and examining the EBR chain. Then use the first approach. If you come up with a good approach, feel free to edit and enhance the answer.
    – Paul
    Aug 2, 2016 at 5:21
  • I did end up deleting the extended partition and creating the primary. The alternative would have been especially tricky: the first 445 bytes of an EBR are normally unused, and when I created the logical partition with gparted, it preserved the contents of those 445 bytes, i.e. the sensitive data I wanted to wipe! Aug 2, 2016 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.