Linux fill with zeros

Filling my hard drive with zeros

I m looking for best and fastest way to remove all my data From hard drive. I M on linux Of you know something with doing this operation on a USB stick share with me. Other ways are also acceptable Anything quick Best regards

Upvoted since you usually find the cryptic DD response and you almost never find the cat command response, which is wonderful in its simplicity.

Are you planning to re-use the disk or is this about removal of data before the destruction of the disk?

4 Answers 4

cat /dev/zero > /dev/device is the fastest way bar none for the spinning rust.

If you have an SSD drive, blkdiscard /dev/device is even faster. It will not physically write zeros but it will effectively wipe the data (so you’ll get zeros if you try to read it).

Very good solution, make sure you redirect into a file (not directly into the device, but a mount point, such as cat /dev/zero > /media/device-mount/this_file_grows_huge_till_it_fills_whole_device.fill ——- use— watch df -h —— to see the drive fill. This command is also a lot more safe and easier to remember than the cryptic dd command. DD has by the way no safety locks, you can do terrible things with it and one little typo and your SSD or HDD is destroyed forever, it is a truely ancient UNIX tool, from the days where userfriendlyness was a new rare concept.

dd if=/dev/zero of=/dev/sdX bs=1M 

dd copies bits from «if» to «of». Blocksize 1M is usually a good value for performance. Repace sdX with your actual drive.

If you need to track progress, install «pv» (pipeviewer)

or, in newer versions of dd , specify status=progress (which will actually be faster as there is a slight overhead using pv ).

To list disk details use fdisk or GNOME Disk.
fdisk:

dd is powerful tool for clobbering (overwriting). date is also often a good idea. Use ; instead of &&, because ; doesn’t care if dd succeeds/fails and – no matter what happens – you get the date printed. If you don’t like the shell, you can also do this step with GNOME Disk.
dd:

$ date; dd if=/dev/zero of=/dev/drive_or_partition bs=1M; date 

Can list drives with lsblk -o name,size,mountpoint,type,uuid too for a (I think) easier to read output.

looking for best and fastest way to remove all my data from hard drive

Asked 1 year, 9 months ago

it is important to distinguish between hard drive and solid state drive (SSD)

with SSD you can take advantage of TRIM, For example (in windows) if you have win10 running and the SSD in question mounted as a secondary drive such as D: then it’s as easy as re-GPT’ing the disk and making one large partition on the entire SSD and then using Tools on D: to cause TRIM to happen, which will zero out the SSD. How to manually cause TRIM to happen in linux on mounted file systems is with fstrim which is provided by the util-linux rpm.

Читайте также:  Средства защиты информации astra linux special edition

In the case of a hard drive where you can’t make use of TRIM, three software utilities I know of in linux are shred , nwipe , and scrub (which would also work on an SSD).

And there is always the tried and true dban which is dariks boot and nuke which is a bootable linux that you put on cd or usb, and it boots a stripped down linux OS giving only the menu option of which disk to choose and various wipe methods. On an 8+ terabyte hard drive of today, choosing a 7-pass wipe method, would not be fast, but it does offer a quick zero out menu option. DBAN is often the easiest when you have one pc, one disk which is your operating system, and you can’t entirely nuke a running operating system disk while it’s in operation.

In the enterprise space, if you are using a self-encrypting disk (SED) which I believe are always an SSD, all you have to do is in the BIOS/EFI under the RAID card menu is change the encryption key of the disk which is one mouse click. while it does not zero out data the existing data is lost because it can no longer be self-decrypted. There’s a fancy term for this. basically amounts to a «secure delete» where the AES encryption algorithm in affect no longer has the key on the existing data.

One other utility in linux I recently came across is provided by sg3_utils-1.37-19.el7.x86_64 and is sg_sanitize; how fast it may be I do not know, it works at the SCSI level. sg_sanitize [—quick] —overwrite —zero /dev/sdX and check progress via sg_requests /dev/sdX . This might do better than cat /dev/zero > /dev/device but I don’t know.

Источник

How to fill a device with zeros, without overwriting the bytes that are already zeros?

I have a USB flash drive usb 3, the reading speed is much more than the writing speed. Let’s say that 99% of the flash memory is already full with zeros, and I would like to fill it with zeros until 100%, by overwriting all the memory flash with zeros dd if=/dev/zero of=/dev/FLASH . This process is going to be long, and it will minimize the life expectancy of the flash drive. I thought, maybe it would be much quicker to check which areas are non-zero, and overwrite only those non-zertos areas with zeros? Are there anyways of doing this? If it is interesting, I would need all this for security reasons.

Does the device have a file system on it? And files? Mainly, though, if this is a one-time affair, then dd if=/dev/zero of=/dev/FLASH would be a heck of a lot faster than writing a program to read the drive one block at a time, comparing it to zeros, and rewriting it if it is.

dd if=/dev/zero of=/dev/FLASH is not secure enough for legal/compliance purposes, if that is a concern readmoar on secure erase.

Читайте также:  Apt get linux headers debian

who do you need to be secure from? what sort of budget does the attacker have? writing zeros to a flash drive may only hide the data.

@RonJohn imagine that there is no file system. I want to be 100% that there are only zeros on the flash drive, regardless of whether there is a file system there or not.

1 Answer 1

Security reasons aside, let’s do it. We can (ab)use GNU ddrescue .

To detect sectors of zeros —generate-mode is useful.

When ddrescue is invoked with the —generate-mode option it operates in «generate mode», which is different from the default «rescue mode». That is, if you use the —generate-mode option, ddrescue does not rescue anything. It only tries to generate a mapfile for later use.

[…]

ddrescue can in some cases generate an approximate mapfile , from infile and the (partial) copy in outfile , that is almost as good as an exact mapfile . It makes this by simply assuming that sectors containing all zeros were not rescued.

[…]

ddrescue --generate-mode infile outfile mapfile 

Let’s pretend your device is outfile from previous ddrescue run. We cannot use it as infile (because ddrescue refuses to work when infile and outfile are the same file), we need a dummy one, /dev/zero will do. We should know the physical sector size of your device and use it with -b option. This command may help:

lsblk -o NAME,PHY-SeC /dev/FLASH 
ddrescue -b 512 --generate-mode /dev/zero /dev/FLASH flash.map 

Now flash.map describes every sector either as non-tried ( ? ) or as finished ( + ), depending on whether it was full of zeros or not. The next step is to fill non-zero sectors with zeros; —fill-mode is perfect for this job:

When ddrescue is invoked with the —fill-mode option it operates in «fill mode», which is different from the default «rescue mode». That is, if you use the —fill-mode option, ddrescue does not rescue anything. It only fills with data read from infile the blocks of outfile whose status character from mapfile coincides with one of the type characters specified as argument to the —fill-mode option.

We must use the same -b value as with —generate-mode , additionally —force to overwrite the output device. This is the command:

ddrescue -b 512 --force --fill-mode=+ /dev/zero /dev/FLASH flash.map 

This time /dev/zero is not just a dummy argument, it’s the actual source of data (zeros) written to the device.

Now /dev/FLASH is filled with zeros. Note there may be buffers you need to flush before you physically disconnect the device (useful links: 1, 2, 3).

Источник

How to write zeros in one pass to free space on FAT32 drive? [duplicate]

Most people will think either using dd or sfill to usually wipe free space with zeros. however, the limit with FAT32 drives are that the largest file size can only be 4 GB. How can I create multiple, smaller, files, to wipe free space of a FAT32 drive, to overcome this limit?

Not a duplicate. Can’t use dd to fill a full fat32 drive. And my question was how to wipe in ZEROs @karel

Читайте также:  Графические оболочки linux kde

The accepted answer to the linked question does not use dd . It uses command-line utility called shred and has an option to set all bits to zero after the last iteration by adding the option -z to the shred command.

The shred program is provided by the coreutils package which is included with Ubuntu by default and is installed at /usr/bin/shred

2 Answers 2

This really sounds like an XY problem.

sfill , or shred which is more generally available (part of coreutils) overwrite the contents of existing files (if everything goes well, e.g. the file system overwrites in place, and see other gotchas mentioned in their manuals).

If you wanted this, you could do so with shred -n 1 —random-source /dev/zero ; or a tiny shell script that gets the file’s size and then does a dd conv=notrunc if=/dev/zero of=the_file_to_be_zeroed_out bs=. count=. .

But as far as I understand, this is not what you need. (Unless can make sure that you only ever delete a file after zeroing it out, which sounds truly cumbersome and hardly feasible.) What you need is to zero the space that’s currently unused by any file, so that instead of the remains of previously deleted files (which would still need to be compressed) the unused area is as compressible as possible, that is, preferably full of zeros.

You should create a new file that’s as large as possible, and is full of zeros. Go with something like dd if=/dev/zero of=tmpfile bs=1M , wait until it exits with the error message «No space left on device» and then delete this file. Your image is ready to be compressed – but don’t forget to umount it first!

Источник

What is the fastest way to overwrite an entire file with zeros in C?

The problem is how to define the best buffer size «programmatically».

What makes you say that stat st_blksize isn’t returning the number you seek? Odds are you should post the code because there is likely a bug in your usage of stat(2).

Oh sorry Banthar, now I understood your truncate(fd,0) and truncate(fd, size), saw it now in R.. answer and figured out, but this isn’t going to lose too much performance ?

3 Answers 3

int fd = open("file", O_WRONLY); off_t size = lseek(fd, 0, SEEK_END); ftruncate(fd, 0); ftruncate(fd, size); 

Obviously it would be nice to add some error checking.

This solution is not what you want for secure obliteration of the file though. It will simply mark the old blocks used by the file as unused and leave a sparse file that doesn’t occupy any physical space. If you want to clear the old contents of the file from the physical storage medium, you might try something like:

static const char zeros[4096]; int fd = open("file", O_WRONLY); off_t size = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); while (size>sizeof zeros) size -= write(fd, zeros, sizeof zeros); while (size) size -= write(fd, zeros, size); 

You could increase the size of zeros up to 32768 or so if testing shows that it improves performance, but beyond a certain point it should not help and will just be a waste.

Источник

Оцените статью
Adblock
detector