r/linux4noobs • • 7d ago

Any way to wipe a drive clean using Linux ?

6 Upvotes

22 comments sorted by

8

u/Unique_Low_1077 Arch btw 6d ago • Popcorn

Ok so by "wipe a drive clean" I assume you want a full wipe, like completely erase the bytes bu overriding then rather then just marking it as deleted (if you just want it marked as deleted then you can do this much faster using an app called gparted)

Yes but this is gonna take a long time so grab your popcorn

First check which device is your drive with

lsblk

This will show a list of devices, you need to find out which one is your drive. One pro tip if you cant fund out which one it is, run the command one time with the drive attached and one without the drive, the device that got removed is your drive

Next we wipe the drive

dd if=/dev/null of=/dev/<your-device> status=progress bs=4M

This command will take a long time and that is normal. Put on your big boy pants and be patient

Good luck!

1

u/Low-Muffin6888 6d ago

Thanks G I tried fdisk with no luck I hope this well work thanks again

4

u/sudomakemetacos 6d ago

Does if=/dev/null actually work? I remember seeing that this wouldn't do anything. I thought best practice was to use /dev/urandom, or  /dev/zeros for a quick wipe.

I better go down the learning rabbit hole... 

1

u/Unique_Low_1077 Arch btw 3d ago

/dev/null does work. The reason they say /dev/urandom is better is while /dev/null fills zeros, urandom fills random garbage so better security technically

3

u/redyos_s 4d ago

If you just want to remove existing filesystem and partition table signatures to reuse the drive, "wipefs" may be sufficient. You don't need to overwrite the entire drive.

Are you trying to securely erase all data or simply prepare the drive for reuse?

1

u/Low-Muffin6888 3d ago

Erase and reuse fresh new start for the drive.

2

u/Unlikely-Sympathy626 4d ago edited 4d ago

dd but it works great for recovery but also please know it before trying. Test in vm or some seperate system first because it is a low level command.

It does raw so please don’t mess with it without screwing up non critical stuff first and when you think you did enough don’t assume it is same on different system. 

Welcome to raw ops mate! No condom and self help with this one but dd is what you after. But seriously jokes aside make very sure you understand the system and dev stuff… double check triple check else you gonna get instead of double d pleasure double d in ass without vaseline

1

u/Low-Muffin6888 3d ago

I tried it this weekend like everyone said and no luck with it yet. But I'm giving up yet

2

u/Distinct-Window-4542 4d ago

You can try to put gparted OS on a usb stick

1

u/Low-Muffin6888 3d ago

I've never heard of that before. So far I've been having no luck with it.

6

u/DamsLcs4421 6d ago

A good old dd 🥇 as u/Unique_Low_1077 said. A good old dd ;)

But be careful using it! I'm always unsure and shivering when using this command, triple checking I'm not erasing my main drive or anything... :)

4

u/atlasraven council member but not master 6d ago

It's called disk destroyer for a reason. Telling it to destroy a disk on purpose will either get it to do something constructive like move a folder or go horribly wrong. You could very well wipe a backbone DNS server.

5

u/DamsLcs4421 6d ago

One of my first actions to remind me about bash syntax was to write a simple wrapper around dd ^ It would analyse arguments and refuse to operate on 'of=/dev/sda' (based on regex) even with sudo ! (It's completely forbidden for sda, sda1 & sda2, and sda3 is partially allowed with rules: allowed in a dedicated directory only, like a little lab for when I need to generate a virtual floppy disk with dd for example)

If the check gets passed, the command is forwarded to the real dd.

And if I ever really needed dd on my disk for whatever reason, I wouldn't rely on this wrapper at all but rather bypass it and explicitly call the binary /usr/bin/dd with sudo, knowing exactly what I'll be doing.

Still, I'm not impatient for this :p

(This was more a fun propose for a mind refreshing micro-project than something to be taken too seriously 😌)

3

u/NoTime4YourBullshit 6d ago

Ahh good old disk destroyer. It earned its name just a few months ago when I miscalculated the seek, scan, and count values in light of the blocksize I had chosen.

3

u/Captain_Oysta_Cracka 6d ago

Badblocks -wsv /dev/{your block device} takes about 22hrs per TB.

2

u/rcentros 3d ago

I'm lazy, I just use Gparted.

1

u/michaelpaoli 2d ago

Yes.  Though for non-ancient drives, best to use their secure erase capability.  If you don't do that, you'll fail to wipe any blocks that have been mapped out, and also any reserved blocks, etc. - at least if you're attempting via software means.  Hardware there are of course other means, but that will render the drive quite useless.

1

u/Individual_Show_9709 1d ago

shred (Built-in terminal tool): Pre-installed on Ubuntu and overwrites whole drives or partitions. Run sudo shred -vfz -n 1 /dev/sdX (replace X with your target drive letter) for a single-pass overwrite with a final zero pass, which multiple commenters on AskUbuntu note is typically enough to block data recovery while saving time and hardware wear.

0

u/[deleted] 4d ago

Post the exact title into google.